From d5a0a4bdef4af35bbc6e959ba1968449a48a9463 Mon Sep 17 00:00:00 2001 From: Bruce Chase Date: Mon, 14 Jan 2019 15:06:04 -0800 Subject: [PATCH 1/5] ArraysTest for array items with enum validation Tests number, integer and string array items types that have enums of acceptable values --- tests/Constraints/ArraysTest.php | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index dac14358..63b97bf1 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -71,6 +71,51 @@ public function getInvalidTests() } } }' + ), + array( // Test array items.enum where type string fail validation if value(s) is/are not in items.enum + '{"data": ["a", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' + ), + array( // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum + '{"data": [1, 2]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer", + "enum": [2, 3] + } + } + } + }' + ), + array( // Test array items.enum where type number fail validation if value(s) is/are not in items.enum + '{"data": [1.25, 2.25]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "number", + "enum": [1.25, 2] + } + } + } + }' ) ); } @@ -168,6 +213,51 @@ public function getValidTests() } } }' + ), + array( // Test array items.enum where type string passes validation if value(s) is/are in items.enum + '{"data": ["c", "c", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' + ), + array( // Test array items.enum where type integer passes validation if value(s) is/are in items.enum + '{"data": [1, 1, 2]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer", + "enum": [1, 2] + } + } + } + }' + ), + array( // Test array items.enum where type number passes validation if value(s) is/are in items.enum + '{"data": [1.25, 1.25, 2.25]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "number", + "enum": [1.25, 2.25] + } + } + } + }' ) ); } From a98b6987ab7a3f8dea7fd9a7c0203fef563abc50 Mon Sep 17 00:00:00 2001 From: Erayd Date: Wed, 27 Feb 2019 10:27:13 +1300 Subject: [PATCH 2/5] Don't run checks which assume a defined instance against undefined Validation tests for an undefined instance should be limited to those tests which are actually applicable (e.g. required, default). Tests which assume an instance previously attempted to validate an internal default when the instance is undefined, rather than ignoring it, which is incorrect behavior. Closes #566. --- .../Constraints/UndefinedConstraint.php | 6 +++++ tests/Constraints/NotTest.php | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index 257db155..e194cb0e 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -150,6 +150,12 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer 'required' ); } + } else { + // If the value is both undefined and not required, skip remaining checks + // in this method which assume an actual, defined instance when validating. + if ($value instanceof self) { + return; + } } } diff --git a/tests/Constraints/NotTest.php b/tests/Constraints/NotTest.php index 3a950f57..6183f684 100644 --- a/tests/Constraints/NotTest.php +++ b/tests/Constraints/NotTest.php @@ -31,6 +31,20 @@ public function getInvalidTests() } } }' + ), + array( // check that a missing, required property is correctly validated + '{"y": "foo"}', + '{ + "type": "object", + "required": ["x"], + "properties": { + "x": { + "not": { + "type": "null" + } + } + } + }' ) ); } @@ -69,6 +83,19 @@ public function getValidTests() } } }' + ), + array( // check that a missing, non-required property isn't validated + '{"y": "foo"}', + '{ + "type": "object", + "properties": { + "x": { + "not": { + "type": "null" + } + } + } + }' ) ); } From 27cc889c2e00709fe46b8ca8a5bb59c60bdeb5f3 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Mon, 3 Jun 2019 12:06:49 +0100 Subject: [PATCH 3/5] Tests on php 7.3 (#575) * Tests on php 7.3 * bumping php-cs-fixer version as per comment from @erayd on justinrainbow/json-schema#563 * turning yoda style off to preserve previous behaviour * some EOL versions of php require an older version of php-cs-fixer * attempting to normalise behaviour with php-cs-fixer 2.2 * attempt separate run of php 7.0 to avoid having xdebug loaded when running php-cs-fixer --- .php_cs.dist | 3 +++ .travis.yml | 5 ++++- composer.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 0b5e2b2c..5a7a578e 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -21,8 +21,11 @@ $config 'phpdoc_order' => true, 'phpdoc_summary' => false, 'pre_increment' => false, + 'increment_style' => false, 'simplified_null_return' => false, 'trailing_comma_in_multiline_array' => false, + 'yoda_style' => false, + 'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'), )) ->setFinder($finder) ; diff --git a/.travis.yml b/.travis.yml index 3b4f5fc1..0d869178 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,12 @@ matrix: - php: 5.5 - php: 5.6 - php: 7.0 - env: WITH_COVERAGE=true WITH_PHPCSFIXER=true + env: WITH_COVERAGE=true + - php: 7.0 + env: WITH_PHPCSFIXER=true - php: 7.1 - php: 7.2 + - php: 7.3 - php: 'nightly' - php: hhvm dist: trusty diff --git a/composer.json b/composer.json index 20e85fc3..884a6971 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "php": ">=5.3.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20", + "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", "json-schema/JSON-Schema-Test-Suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, From 6bbd3d1640080b9a152ea543089de26c1b202db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 6 Sep 2019 12:16:03 +0200 Subject: [PATCH 4/5] Fixed PHPDoc of Validator::validate() method (#587) --- src/JsonSchema/Validator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index 448091cd..431b3781 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -34,9 +34,7 @@ class Validator extends BaseConstraint * Both the php object and the schema are supposed to be a result of a json_decode call. * The validation works as defined by the schema proposal in http://json-schema.org. * - * Note that the first argument is passwd by reference, so you must pass in a variable. - * - * {@inheritdoc} + * Note that the first argument is passed by reference, so you must pass in a variable. */ public function validate(&$value, $schema = null, $checkMode = null) { From 5bc9862d6056d7f0cea2d2a01d4e76c434394780 Mon Sep 17 00:00:00 2001 From: Nicolas Giraud Date: Fri, 6 Sep 2019 12:16:37 +0200 Subject: [PATCH 5/5] Fix travis PHP 5.4 and 5.5 config. (#583) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0d869178..be79e9fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,9 @@ matrix: - 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