Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise to PHP 7.2 minimum and add support for PHP 8.0 and 8.1 #689

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 23 additions & 22 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -17,34 +17,35 @@ jobs:
strategy:
matrix:
php-version:
- "5.3"
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
# - "5.3"
# - "5.4"
# - "5.5"
# - "5.6"
# - "7.0"
# - "7.1"
- "7.2"
- "7.3"
- "7.4"
# - "8.0"
- "8.0"
- "8.1"
dependencies: [highest]
experimental: [false]
include:
- php-version: "5.3"
dependencies: highest
experimental: false
- php-version: "5.3"
dependencies: lowest
experimental: false
# - php-version: "8.0"
# dependencies: highest
# experimental: false
# - php-version: "8.1"
# dependencies: lowest-ignore
# experimental: true
# - php-version: "8.1"
# dependencies: highest-ignore
# experimental: true
# - php-version: "5.3"
# dependencies: highest
# experimental: false
# - php-version: "5.3"
# dependencies: lowest
# experimental: false
- php-version: "8.0"
dependencies: highest
experimental: false
- php-version: "8.1"
dependencies: lowest-ignore
experimental: true
- php-version: "8.1"
dependencies: highest-ignore
experimental: true

steps:
- name: "Checkout"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
php-version:
- "5.3"
- "7.2"
- "latest"

steps:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -27,14 +27,14 @@
}
],
"require": {
"php": ">=5.3.3",
"php": ">=7.2",
"marc-mabe/php-enum":"^2.0 || ^3.0 || ^4.0",
"icecave/parity": "1.0.0"
"icecave/parity": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0",
"json-schema/json-schema-test-suite": "1.2.0",
"phpunit/phpunit": "^4.8.35"
"phpunit/phpunit": "^8.5.26"
},
"extra": {
"branch-alias": {
Expand Down
10 changes: 6 additions & 4 deletions src/JsonSchema/Iterator/ObjectIterator.php
Expand Up @@ -39,6 +39,7 @@ public function __construct($object)
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function current()
{
$this->initialize();
Expand All @@ -49,7 +50,7 @@ public function current()
/**
* {@inheritdoc}
*/
public function next()
public function next(): void
{
$this->initialize();
$this->position++;
Expand All @@ -58,6 +59,7 @@ public function next()
/**
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function key()
{
$this->initialize();
Expand All @@ -68,7 +70,7 @@ public function key()
/**
* {@inheritdoc}
*/
public function valid()
public function valid(): bool
{
$this->initialize();

Expand All @@ -78,7 +80,7 @@ public function valid()
/**
* {@inheritdoc}
*/
public function rewind()
public function rewind(): void
{
$this->initialize();
$this->position = 0;
Expand All @@ -87,7 +89,7 @@ public function rewind()
/**
* {@inheritdoc}
*/
public function count()
public function count(): int
{
$this->initialize();

Expand Down
6 changes: 5 additions & 1 deletion src/JsonSchema/Uri/UriResolver.php
Expand Up @@ -28,6 +28,10 @@ class UriResolver implements UriResolverInterface
*/
public function parse($uri)
{
if (null === $uri || '' === $uri) {
return array();
}

preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);

$components = array();
Expand Down Expand Up @@ -102,7 +106,7 @@ public function resolve($uri, $baseUri = null)
return $uri;
}
$baseComponents = $this->parse($baseUri);
$basePath = $baseComponents['path'];
$basePath = $baseComponents['path'] ?? '';

$baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath);
if (isset($components['fragment'])) {
Expand Down
8 changes: 5 additions & 3 deletions src/JsonSchema/Uri/UriRetriever.php
Expand Up @@ -83,9 +83,11 @@ public function confirmMediaType($uriRetriever, $uri)
return;
}

foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) {
if (strpos($uri, $endpoint) === 0) {
return true;
if (null !== $uri) {
foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) {
if (strpos($uri, $endpoint) === 0) {
return true;
}
}
}

Expand Down
7 changes: 3 additions & 4 deletions tests/ConstraintErrorTest.php
Expand Up @@ -24,10 +24,9 @@ public function testGetInvalidMessage()
{
$e = ConstraintError::MISSING_ERROR();

$this->setExpectedException(
'\JsonSchema\Exception\InvalidArgumentException',
'Missing error message for missingError'
);
$this->expectException(\JsonSchema\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Missing error message for missingError');

$e->getMessage();
}
}
2 changes: 1 addition & 1 deletion tests/Constraints/CoerciveTest.php
Expand Up @@ -18,7 +18,7 @@ class CoerciveTest extends VeryBaseTestCase
{
protected $factory = null;

public function setUp()
public function setUp(): void
{
$this->factory = new Factory();
$this->factory->setConfig(Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE_TYPES);
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/FactoryTest.php
Expand Up @@ -42,7 +42,7 @@ class FactoryTest extends TestCase
*/
protected $factory;

protected function setUp()
protected function setUp(): void
{
$this->factory = new Factory();
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function constraintNameProvider()
*/
public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName)
{
$this->setExpectedException('JsonSchema\Exception\InvalidArgumentException');
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
$this->factory->createInstanceFor($constraintName);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Constraints/FormatTest.php
Expand Up @@ -17,7 +17,7 @@ class FormatTest extends BaseTestCase
{
protected $validateSchema = true;

public function setUp()
public function setUp(): void
{
date_default_timezone_set('UTC');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Constraints/MinLengthMaxLengthMultiByteTest.php
Expand Up @@ -13,7 +13,7 @@ class MinLengthMaxLengthMultiByteTest extends BaseTestCase
{
protected $validateSchema = true;

protected function setUp()
protected function setUp(): void
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('mbstring extension is not available');
Expand Down
12 changes: 4 additions & 8 deletions tests/Constraints/SchemaValidationTest.php
Expand Up @@ -102,19 +102,15 @@ public function testValidCases($schema)

public function testNonObjectSchema()
{
$this->setExpectedException(
'\JsonSchema\Exception\RuntimeException',
'Cannot validate the schema of a non-object'
);
$this->expectException('\JsonSchema\Exception\RuntimeException');
$this->expectExceptionMessage('Cannot validate the schema of a non-object');
$this->testValidCases('"notAnObject"');
}

public function testInvalidSchemaException()
{
$this->setExpectedException(
'\JsonSchema\Exception\InvalidSchemaException',
'Schema did not pass validation'
);
$this->expectException('\JsonSchema\Exception\InvalidSchemaException');
$this->expectExceptionMessage('Schema did not pass validation');

$input = json_decode('{}');
$schema = json_decode('{"properties":{"propertyOne":{"type":"string","required":true}}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/Constraints/SelfDefinedSchemaTest.php
Expand Up @@ -74,7 +74,7 @@ public function testInvalidArgumentException()

$v = new Validator();

$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');

$v->validate($value, $schema);
}
Expand Down
12 changes: 4 additions & 8 deletions tests/Constraints/TypeTest.php
Expand Up @@ -125,10 +125,8 @@ public function testInvalidateTypeNameWording()
$m = $r->getMethod('validateTypeNameWording');
$m->setAccessible(true);

$this->setExpectedException(
'\UnexpectedValueException',
"No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]"
);
$this->expectException('\UnexpectedValueException');
$this->expectExceptionMessage("No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]");
$m->invoke($t, 'notAValidTypeName');
}

Expand All @@ -138,10 +136,8 @@ public function testValidateTypeException()
$data = new \stdClass();
$schema = json_decode('{"type": "notAValidTypeName"}');

$this->setExpectedException(
'JsonSchema\Exception\InvalidArgumentException',
'object is an invalid type for notAValidTypeName'
);
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
$this->expectExceptionMessage('object is an invalid type for notAValidTypeName');
$t->check($data, $schema);
}
}
2 changes: 1 addition & 1 deletion tests/Constraints/ValidationExceptionTest.php
Expand Up @@ -45,7 +45,7 @@ public function testValidationException()
$exception->getMessage()
);

$this->setExpectedException('JsonSchema\Exception\ValidationException');
$this->expectException('JsonSchema\Exception\ValidationException');
throw $exception;
}
}
6 changes: 2 additions & 4 deletions tests/Entity/JsonPointerTest.php
Expand Up @@ -113,10 +113,8 @@ public function testJsonPointerWithPropertyPaths()

public function testCreateWithInvalidValue()
{
$this->setExpectedException(
'\JsonSchema\Exception\InvalidArgumentException',
'Ref value must be a string'
);
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Ref value must be a string');
new JsonPointer(null);
}
}
2 changes: 1 addition & 1 deletion tests/Iterators/ObjectIteratorTest.php
Expand Up @@ -16,7 +16,7 @@ class ObjectIteratorTest extends TestCase
{
protected $testObject;

public function setUp()
public function setUp(): void
{
$this->testObject = (object) array(
'subOne' => (object) array(
Expand Down
2 changes: 1 addition & 1 deletion tests/RefTest.php
Expand Up @@ -69,7 +69,7 @@ public function testRefIgnoresSiblings($schema, $document, $isValid, $exception

$v = new Validator();
if ($exception) {
$this->setExpectedException($exception);
$this->expectException($exception);
}

$v->validate($document, $schema);
Expand Down
12 changes: 4 additions & 8 deletions tests/SchemaStorageTest.php
Expand Up @@ -102,10 +102,8 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()

public function testUnresolvableJsonPointExceptionShouldBeThrown()
{
$this->setExpectedException(
'JsonSchema\Exception\UnresolvableJsonPointerException',
'File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car'
);
$this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException');
$this->expectExceptionMessage('File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car');

$mainSchema = $this->getInvalidSchema();
$mainSchemaPath = 'http://www.example.com/schema.json';
Expand All @@ -121,10 +119,8 @@ public function testUnresolvableJsonPointExceptionShouldBeThrown()

public function testResolveRefWithNoAssociatedFileName()
{
$this->setExpectedException(
'JsonSchema\Exception\UnresolvableJsonPointerException',
"Could not resolve fragment '#': no file is defined"
);
$this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException');
$this->expectExceptionMessage("Could not resolve fragment '#': no file is defined");

$schemaStorage = new SchemaStorage();
$schemaStorage->resolveRef('#');
Expand Down
6 changes: 2 additions & 4 deletions tests/Uri/Retrievers/CurlTest.php
Expand Up @@ -17,10 +17,8 @@ public function testRetrieveNonexistantFile()
{
$c = new Curl();

$this->setExpectedException(
'\JsonSchema\Exception\ResourceNotFoundException',
'JSON schema not found'
);
$this->expectException('\JsonSchema\Exception\ResourceNotFoundException');
$this->expectExceptionMessage('JSON schema not found');
$c->retrieve(__DIR__ . '/notARealFile');
}

Expand Down
12 changes: 4 additions & 8 deletions tests/Uri/Retrievers/FileGetContentsTest.php
Expand Up @@ -30,21 +30,17 @@ public function testFalseReturn()
{
$res = new FileGetContents();

$this->setExpectedException(
'\JsonSchema\Exception\ResourceNotFoundException',
'JSON schema not found at http://example.com/false'
);
$this->expectException('\JsonSchema\Exception\ResourceNotFoundException');
$this->expectExceptionMessage('JSON schema not found at http://example.com/false');
$res->retrieve('http://example.com/false');
}

public function testFetchDirectory()
{
$res = new FileGetContents();

$this->setExpectedException(
'\JsonSchema\Exception\ResourceNotFoundException',
'JSON schema not found at file:///this/is/a/directory/'
);
$this->expectException('\JsonSchema\Exception\ResourceNotFoundException');
$this->expectExceptionMessage('JSON schema not found at file:///this/is/a/directory/');
$res->retrieve('file:///this/is/a/directory/');
}

Expand Down