From 5034fb7f98d61b039b2b570cc9af1786cf224019 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 29 Aug 2025 12:55:14 +0200 Subject: [PATCH 1/3] Backport of PHP 8.5 patch: ci: Add PHP 8.5 to pipeline, ignoring dependencies and as experimental (#842) This PR will - resolve deprecations for: - Reflection*::setAccessible - curl_close Fixes #798 Fixes #863 --- src/JsonSchema/Uri/Retrievers/Curl.php | 4 +++- .../Uri/Retrievers/FileGetContents.php | 20 ++++++++++--------- tests/Constraints/TypeTest.php | 8 ++++++-- tests/SchemaStorageTest.php | 6 ++++-- tests/Uri/Retrievers/FileGetContentsTest.php | 4 +++- tests/Uri/UriRetrieverTest.php | 16 +++++++++++---- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/JsonSchema/Uri/Retrievers/Curl.php b/src/JsonSchema/Uri/Retrievers/Curl.php index 81c86037d..c14df3fdb 100644 --- a/src/JsonSchema/Uri/Retrievers/Curl.php +++ b/src/JsonSchema/Uri/Retrievers/Curl.php @@ -51,7 +51,9 @@ public function retrieve($uri) $this->fetchMessageBody($response); $this->fetchContentType($response); - curl_close($ch); + if (PHP_VERSION_ID < 80000) { + curl_close($ch); + } return $this->messageBody; } diff --git a/src/JsonSchema/Uri/Retrievers/FileGetContents.php b/src/JsonSchema/Uri/Retrievers/FileGetContents.php index c03348bc8..c5bbcf412 100644 --- a/src/JsonSchema/Uri/Retrievers/FileGetContents.php +++ b/src/JsonSchema/Uri/Retrievers/FileGetContents.php @@ -49,17 +49,19 @@ public function retrieve($uri) } $this->messageBody = $response; + if (function_exists('http_get_last_response_headers')) { - // Use http_get_last_response_headers() for BC compatibility with PHP 8.5+ + // Use http_get_last_response_headers() for compatibility with PHP 8.5+ // where $http_response_header is deprecated. - $http_response_header = http_get_last_response_headers(); + $httpResponseHeaders = http_get_last_response_headers(); + } else { + /** @phpstan-ignore nullCoalesce.variable ($http_response_header can non-existing when no http request was done) */ + $httpResponseHeaders = $http_response_header ?? []; } - if (!empty($http_response_header)) { - // $http_response_header cannot be tested, because it's defined in the method's local scope - // See http://php.net/manual/en/reserved.variables.httpresponseheader.php for more info. - $this->fetchContentType($http_response_header); // @codeCoverageIgnore - } else { // @codeCoverageIgnore - // Could be a "file://" url or something else - fake up the response + + if (!empty($httpResponseHeaders)) { + $this->fetchContentType($httpResponseHeaders); + } else { $this->contentType = null; } @@ -71,7 +73,7 @@ public function retrieve($uri) * * @return bool Whether the Content-Type header was found or not */ - private function fetchContentType(array $headers) + private function fetchContentType(array $headers): bool { foreach ($headers as $header) { if ($this->contentType = self::getContentTypeMatchInHeader($header)) { diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index a10996dac..864ca3877 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -113,7 +113,9 @@ public function testValidateTypeNameWording($nameWording) $t = new TypeConstraint(); $r = new \ReflectionObject($t); $m = $r->getMethod('validateTypeNameWording'); - $m->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $m->setAccessible(true); + } $m->invoke($t, $nameWording); } @@ -123,7 +125,9 @@ public function testInvalidateTypeNameWording() $t = new TypeConstraint(); $r = new \ReflectionObject($t); $m = $r->getMethod('validateTypeNameWording'); - $m->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $m->setAccessible(true); + } $this->setExpectedException( '\UnexpectedValueException', diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index 0c31e86a7..e17157e8e 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -311,11 +311,13 @@ public function testNoDoubleResolve() $uriRetriever->retrieve('test/schema')->willReturn($schemaOne)->shouldBeCalled(); $s = new SchemaStorage($uriRetriever->reveal()); - $schema = $s->addSchema('test/schema'); + $s->addSchema('test/schema'); $r = new \ReflectionObject($s); $p = $r->getProperty('schemas'); - $p->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $schemas = $p->getValue($s); $this->assertEquals( diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 0514a7d5a..48dff0597 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -54,7 +54,9 @@ public function testContentType() $reflector = new \ReflectionObject($res); $fetchContentType = $reflector->getMethod('fetchContentType'); - $fetchContentType->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $fetchContentType->setAccessible(true); + } $this->assertTrue($fetchContentType->invoke($res, array('Content-Type: application/json'))); $this->assertFalse($fetchContentType->invoke($res, array('X-Some-Header: whateverValue'))); diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index fb05cc18a..95d407dee 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -274,11 +274,15 @@ private function mockRetriever($schema) $retrieverMock = $this->getRetrieverMock($schema); $factory = new \ReflectionProperty('JsonSchema\Constraints\BaseConstraint', 'factory'); - $factory->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $factory->setAccessible(true); + } $factory = $factory->getValue($this->validator); $retriever = new \ReflectionProperty('JsonSchema\Constraints\Factory', 'uriRetriever'); - $retriever->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $retriever->setAccessible(true); + } $retriever->setValue($factory, $retrieverMock); } @@ -369,12 +373,16 @@ public function testSchemaCache() // inject a schema cache value $schemaCache = $reflector->getProperty('schemaCache'); - $schemaCache->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $schemaCache->setAccessible(true); + } $schemaCache->setValue($retriever, array('local://test/uri' => 'testSchemaValue')); // retrieve from schema cache $loadSchema = $reflector->getMethod('loadSchema'); - $loadSchema->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $loadSchema->setAccessible(true); + } $this->assertEquals( 'testSchemaValue', $loadSchema->invoke($retriever, 'local://test/uri') From 7e81a49f992b93e97c5ed0eb51f82eb0444d2864 Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 27 Dec 2025 16:38:39 +0000 Subject: [PATCH 2/3] Backport some CI to 5.x.x Remove old .travis.yml Update .gitattributes cf https://github.com/jsonrainbow/json-schema/tree/2911a17/.github/workflows --- .gitattributes | 2 +- .../continuous-integration-32-bits.yml | 52 +++++++++++++++ .github/workflows/continuous-integration.yml | 66 +++++++++++++++++++ .github/workflows/lint.yml | 43 ++++++++++++ .travis.yml | 43 ------------ tests/Uri/UriRetrieverTest.php | 2 +- 6 files changed, 163 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/continuous-integration-32-bits.yml create mode 100644 .github/workflows/continuous-integration.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 5918aea88..a04e5bf30 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,7 @@ /docs export-ignore /tests export-ignore /.gitattributes export-ignore +/.github export-ignore /.gitignore export-ignore /.php_cs.dist export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore diff --git a/.github/workflows/continuous-integration-32-bits.yml b/.github/workflows/continuous-integration-32-bits.yml new file mode 100644 index 000000000..1064d40ca --- /dev/null +++ b/.github/workflows/continuous-integration-32-bits.yml @@ -0,0 +1,52 @@ +name: "Continuous Integration - 32-bits" + +on: + push: + branches: + - main + - 5.x.x + pull_request: + branches: + - main + - 5.x.x + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + +jobs: + tests: + name: "PHP 8.4 - 32-bits" + + runs-on: ubuntu-latest + container: shivammathur/node:latest-i386 + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1, phar.readonly=0, error_reporting=E_ALL, display_errors=On" + php-version: "8.4" + tools: composer + + - name: Check PHP_INT_MAX + run: | + MAX=$(php -r "echo PHP_INT_MAX;") + if [ "$MAX" -ne 2147483647 ]; then + echo "Error: PHP is not 32-bits (PHP_INT_MAX is $MAX)" + exit 1 + fi + env: + MAX: "" + + - name: Install dependencies + run: | + git config --global --add safe.directory $(pwd) + composer install + + - name: Run tests + run: "composer test" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 000000000..fa0cd6cc9 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,66 @@ +name: "Continuous Integration" + +on: + push: + branches: + - main + - 5.x.x + pull_request: + branches: + - main + - 5.x.x + +env: + COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist" + +jobs: + tests: + name: "PHP ${{ matrix.php-version }}, ${{ matrix.dependencies }} dependecies, experimental: ${{ matrix.experimental || false}}" + + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental || false }} + + strategy: + fail-fast: false + matrix: + php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + dependencies: [highest] + include: + - php-version: "7.2" + dependencies: lowest + - php-version: "8.6" + dependencies: ignore + experimental: true + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + extensions: "intl, zip" + ini-values: "memory_limit=-1, phar.readonly=0, error_reporting=E_ALL, display_errors=On" + php-version: "${{ matrix.php-version }}" + tools: composer + + - name: "Handle lowest dependencies update" + if: "contains(matrix.dependencies, 'lowest')" + run: "echo \"COMPOSER_UPDATE_FLAGS=$COMPOSER_UPDATE_FLAGS --prefer-lowest\" >> $GITHUB_ENV" + + - name: "Handle ignore-platform-reqs dependencies update" + if: "contains(matrix.dependencies, 'ignore')" + run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --ignore-platform-req=php\" >> $GITHUB_ENV" + + - name: "Update dependencies" + run: "composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}" + + - name: "Validate composer.json" + run: "composer validate" + + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: "Run tests" + run: "composer test" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..90784e048 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,43 @@ +name: "PHP Lint" + +on: + push: + branches: + - main + pull_request: + branches: + - main + - 5.x.x + +jobs: + lint: + name: "Lint" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "7.2" + - "latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + extensions: "intl" + ini-values: "memory_limit=-1, error_reporting=E_ALL, display_errors=On" + coverage: "none" + tools: parallel-lint, cs2pr + + - name: "Lint PHP files" + run: | + parallel-lint . --checkstyle --exclude vendor --show-deprecated | cs2pr + + - name: "Validate conforming class autoloading" + run: | + composer dump-autoload --no-dev --optimize --strict-psr --strict-ambiguous diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ca5eced37..000000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - - $HOME/.phpcsfixer - -matrix: - fast_finish: true - include: - - php: 5.3 - dist: precise - - php: 5.4 - dist: trusty - - php: 5.5 - dist: trusty - - php: 5.6 - - php: 7.0 - env: WITH_COVERAGE=true - - php: 7.0 - env: WITH_PHPCSFIXER=true - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: nightly - - php: hhvm-3.18 - dist: trusty - allow_failures: - - php: nightly - - php: hhvm-3.18 - -before_install: - - if [[ "$WITH_COVERAGE" != "true" && "$TRAVIS_PHP_VERSION" != "hhvm-3.18" && "$TRAVIS_PHP_VERSION" != "nightly" && "$TRAVIS_PHP_VERSION" != "7.1" ]]; then phpenv config-rm xdebug.ini; fi - - if [[ "$TRAVIS_PHP_VERSION" = "hhvm-3.18" || "$TRAVIS_PHP_VERSION" = "nightly" ]]; then sed -i '/^.*friendsofphp\/php-cs-fixer.*$/d' composer.json; fi - -install: - - if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]]; then travis_retry composer install; fi - - if [[ "$TRAVIS_PHP_VERSION" = "nightly" ]]; then travis_retry composer install --ignore-platform-reqs; fi - -script: - - if [[ "$WITH_COVERAGE" == "true" ]]; then ./vendor/bin/phpunit --coverage-text; else composer test; fi - - if [[ "$WITH_PHPCSFIXER" == "true" ]]; then mkdir -p $HOME/.phpcsfixer && vendor/bin/php-cs-fixer fix --cache-file "$HOME/.phpcsfixer/.php_cs.cache" --dry-run --diff --verbose; fi diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 95d407dee..781345218 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -303,7 +303,7 @@ public function testPackageURITranslation() $root = sprintf('file://%s/', realpath(__DIR__ . '/../..')); $uri = $retriever->translate('package://foo/bar.json'); - $this->assertEquals("${root}foo/bar.json", $uri); + $this->assertEquals("{$root}foo/bar.json", $uri); } public function testDefaultDistTranslations() From acb4d94c38640ca931395c5616b04f5138ee9ec7 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 21 Feb 2025 10:50:06 +0100 Subject: [PATCH 3/3] fix: Upgrade php cs fixer to latest (#783) Fixes #598 --- .gitignore | 2 +- .php_cs.dist | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e5ad919d5..e9391243c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ coverage .project .settings .php_cs -.php_cs.cache +.php-cs-fixer.cache composer.lock docs-api phpunit.xml diff --git a/.php_cs.dist b/.php_cs.dist index a9e7e4ed1..c3fa2d6ff 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -2,7 +2,7 @@ $finder = new PhpCsFixer\Finder(); $config = new PhpCsFixer\Config('json-schema'); -$finder->in(__DIR__); +$finder->in([__DIR__ . '/src', __DIR__ . '/tests']); /* Based on ^2.1 of php-cs-fixer */ $config diff --git a/composer.json b/composer.json index 8c322670e..0ec802b03 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "php": ">=7.1" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "friendsofphp/php-cs-fixer": "3.3.0", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" },