Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions .github/workflows/continuous-integration-32-bits.yml
Original file line number Diff line number Diff line change
@@ -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"
66 changes: 66 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -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"
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coverage
.project
.settings
.php_cs
.php_cs.cache
.php-cs-fixer.cache
composer.lock
docs-api
phpunit.xml
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 3 additions & 1 deletion src/JsonSchema/Uri/Retrievers/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 11 additions & 9 deletions src/JsonSchema/Uri/Retrievers/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions tests/Constraints/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions tests/SchemaStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion tests/Uri/Retrievers/FileGetContentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down
18 changes: 13 additions & 5 deletions tests/Uri/UriRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -299,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()
Expand Down Expand Up @@ -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')
Expand Down
Loading