From ddb7a393617de83e3a9ba59e79e7f463202e5446 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 19:59:11 +0200 Subject: [PATCH 001/114] refactor: upgrade base test case to force return of generator --- tests/Constraints/BaseTestCase.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index 84daaf13..68143f94 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -9,6 +9,7 @@ namespace JsonSchema\Tests\Constraints; +use Generator; use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\Factory; use JsonSchema\SchemaStorage; @@ -135,17 +136,17 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); } - abstract public function getValidTests(): array; + abstract public function getValidTests(): Generator; - public function getValidForAssocTests(): array + public function getValidForAssocTests(): Generator { - return $this->getValidTests(); + yield from $this->getValidTests(); } - abstract public function getInvalidTests(): array; + abstract public function getInvalidTests(): Generator; - public function getInvalidForAssocTests(): array + public function getInvalidForAssocTests(): Generator { - return $this->getInvalidTests(); + yield from $this->getInvalidTests(); } } From 377c2a7fe35289b4d3f4e4446a64e351eb8db071 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:00:44 +0200 Subject: [PATCH 002/114] docs: remove class package annotation --- tests/Constraints/BaseTestCase.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index 68143f94..b4eb1f66 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -16,9 +16,6 @@ use JsonSchema\Uri\UriResolver; use JsonSchema\Validator; -/** - * @package JsonSchema\Tests\Constraints - */ abstract class BaseTestCase extends VeryBaseTestCase { protected $schemaSpec = 'http://json-schema.org/draft-04/schema#'; From ec8393099fafa426321cab2ac79868335be35cf4 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:03:05 +0200 Subject: [PATCH 003/114] refactor: apply generator return in additional properties test --- .../Constraints/AdditionalPropertiesTest.php | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index 46b29a82..52ea09bf 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -15,10 +15,9 @@ class AdditionalPropertiesTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ + yield [ '{ "prop":"1", "patternProp":"3", @@ -49,8 +48,8 @@ public function getInvalidTests(): array 'context' => Validator::ERROR_DOCUMENT_VALIDATION ] ] - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":"2" @@ -62,8 +61,8 @@ public function getInvalidTests(): array }, "additionalProperties": false }' - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":2 @@ -75,8 +74,8 @@ public function getInvalidTests(): array }, "additionalProperties": {"type":"string"} }' - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":2 @@ -88,8 +87,8 @@ public function getInvalidTests(): array }, "additionalProperties": {"type":"string"} }' - ], - [ + ]; + yield [ '{ "prop1": "a", "prop2": "b" @@ -100,8 +99,8 @@ public function getInvalidTests(): array "type": "boolean" } }' - ], - [ + ]; + yield [ '{ "prop1": "a", "prop2": "b" @@ -110,14 +109,12 @@ public function getInvalidTests(): array "type": "object", "additionalProperties": false }' - ], - ]; + ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ + yield [ '{ "prop":"1", "additionalProp":"2" @@ -128,8 +125,8 @@ public function getValidTests(): array "prop":{"type":"string"} } }' - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":"2" @@ -140,8 +137,8 @@ public function getValidTests(): array "prop":{"type":"string"} } }' - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":"2" @@ -153,8 +150,8 @@ public function getValidTests(): array }, "additionalProperties": {"type":"string"} }' - ], - [ + ]; + yield [ '{ "prop":"1", "additionalProp":[] @@ -166,8 +163,8 @@ public function getValidTests(): array }, "additionalProperties": true }' - ], - [ + ]; + yield [ '{ "prop1": "a", "prop2": "b" @@ -178,8 +175,8 @@ public function getValidTests(): array "type": "string" } }' - ], - [ + ]; + yield [ '{ "prop1": "a", "prop2": "b" @@ -188,8 +185,8 @@ public function getValidTests(): array "type": "object", "additionalProperties": true }' - ], - 'additional property casted into int when actually is numeric string (#784)' => [ + ]; + yield 'additional property casted into int when actually is numeric string (#784)' => [ '{ "prop1": { "123": "a" @@ -206,7 +203,6 @@ public function getValidTests(): array } } }' - ], - ]; + ]; } } From 0a103c837c361535a06eff15f66df9c92c73f41c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:03:27 +0200 Subject: [PATCH 004/114] docs: remove file license annotation --- tests/Constraints/AdditionalPropertiesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index 52ea09bf..89815718 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:08:14 +0200 Subject: [PATCH 005/114] refactor: apply generator to arrays test --- tests/Constraints/ArraysTest.php | 78 +++++++++++++++----------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index aac3fc7f..8b227b84 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -13,10 +13,9 @@ class ArraysTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ + yield [ '{ "array":[1,2,"a"] }', @@ -29,8 +28,8 @@ public function getInvalidTests(): array } } }' - ], - [ + ]; + yield [ '{ "array":[1,2,"a"] }', @@ -44,8 +43,8 @@ public function getInvalidTests(): array } } }' - ], - [ + ]; + yield [ '{ "array":[1,2,null] }', @@ -58,8 +57,8 @@ public function getInvalidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [1, 2, 3, "foo"]}', '{ "type": "object", @@ -71,8 +70,8 @@ public function getInvalidTests(): array } } }' - ], - [ // Test array items.enum where type string fail validation if value(s) is/are not in items.enum + ]; + yield 'Test array items.enum where type string fail validation if value(s) is/are not in items.enum' => [ '{"data": ["a", "b"]}', '{ "type": "object", @@ -86,8 +85,8 @@ public function getInvalidTests(): array } } }' - ], - [ // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum + ]; + yield 'Test array items.enum where type integer fail validation if value(s) is/are not in items.enum' => [ '{"data": [1, 2]}', '{ "type": "object", @@ -101,8 +100,8 @@ public function getInvalidTests(): array } } }' - ], - [ // Test array items.enum where type number fail validation if value(s) is/are not in items.enum + ]; + yield '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", @@ -116,8 +115,8 @@ public function getInvalidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [{"not_a_string_but_object":"string_but_in_object"}]}', '{ "type": "object", @@ -129,14 +128,12 @@ public function getInvalidTests(): array } } }' - ] - ]; + ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ + yield [ '{ "array":[1,2,"a"] }', @@ -146,8 +143,8 @@ public function getValidTests(): array "array":{"type":"array"} } }' - ], - [ + ]; + yield [ '{ "array":[1,2,"a"] }', @@ -161,8 +158,8 @@ public function getValidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [1, 2, 3, 4]}', '{ "type": "object", @@ -174,8 +171,8 @@ public function getValidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [1, "foo", false]}', '{ "type": "object", @@ -186,8 +183,8 @@ public function getValidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [1, "foo", false]}', '{ "type": "object", @@ -198,8 +195,8 @@ public function getValidTests(): array } } }' - ], - [ + ]; + yield [ '{"data": [1, 2, 3, 4, 5]}', '{ "type": "object", @@ -210,8 +207,8 @@ public function getValidTests(): array } } }' - ], - [ // test more schema items than array items + ]; + yield 'test more schema items than array items' => [ '{"data": [1, 2]}', '{ "type": "object", @@ -226,8 +223,8 @@ public function getValidTests(): array } } }' - ], - [ // Test array items.enum where type string passes validation if value(s) is/are in items.enum + ]; + yield 'Test array items.enum where type string passes validation if value(s) is/are in items.enum' => [ '{"data": ["c", "c", "b"]}', '{ "type": "object", @@ -241,8 +238,8 @@ public function getValidTests(): array } } }' - ], - [ // Test array items.enum where type integer passes validation if value(s) is/are in items.enum + ]; + yield 'Test array items.enum where type integer passes validation if value(s) is/are in items.enum' => [ '{"data": [1, 1, 2]}', '{ "type": "object", @@ -256,8 +253,8 @@ public function getValidTests(): array } } }' - ], - [ // Test array items.enum where type number passes validation if value(s) is/are in items.enum + ]; + yield '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", @@ -271,7 +268,6 @@ public function getValidTests(): array } } }' - ], ]; } } From b8d32d51cfa22db66ad811ea4ecbbcd012458c69 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:08:31 +0200 Subject: [PATCH 006/114] docs: remove file bases license reference --- tests/Constraints/ArraysTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index 8b227b84..1da5008f 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:08:47 +0200 Subject: [PATCH 007/114] refactor: add missing type hint --- tests/Constraints/ArraysTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index 1da5008f..88b10db7 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -4,6 +4,7 @@ class ArraysTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 8276d51ca3fc9fea4a2adbbae17e572e304cf726 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:11:16 +0200 Subject: [PATCH 008/114] refactor: apply generator to basic types test --- tests/Constraints/BasicTypesTest.php | 249 +++++++++++++-------------- 1 file changed, 123 insertions(+), 126 deletions(-) diff --git a/tests/Constraints/BasicTypesTest.php b/tests/Constraints/BasicTypesTest.php index 01e1f7ba..53e6e6a0 100644 --- a/tests/Constraints/BasicTypesTest.php +++ b/tests/Constraints/BasicTypesTest.php @@ -14,137 +14,134 @@ class BasicTypesTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "string":null - }', - '{ - "type":"object", - "properties": { - "string":{"type":"string"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "number":null - }', - '{ - "type":"object", - "properties": { - "number":{"type":"number"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "integer":null - }', - '{ - "type":"object", - "properties": { - "integer":{"type":"integer"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "boolean":null - }', - '{ - "type":"object", - "properties": { - "boolean":{"type":"boolean"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "object":null - }', - '{ - "type":"object", - "properties": { - "object":{"type":"object"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "array":null - }', - '{ - "type":"object", - "properties": { - "array":{"type":"array"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "null":1 - }', - '{ - "type":"object", - "properties": { - "null":{"type":"null"} - }, - "additionalProperties":false - }' - ] + + yield [ + '{ + "string":null + }', + '{ + "type":"object", + "properties": { + "string":{"type":"string"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "number":null + }', + '{ + "type":"object", + "properties": { + "number":{"type":"number"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "integer":null + }', + '{ + "type":"object", + "properties": { + "integer":{"type":"integer"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "boolean":null + }', + '{ + "type":"object", + "properties": { + "boolean":{"type":"boolean"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "object":null + }', + '{ + "type":"object", + "properties": { + "object":{"type":"object"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "array":null + }', + '{ + "type":"object", + "properties": { + "array":{"type":"array"} + }, + "additionalProperties":false + }' ]; + yield [ + '{ + "null":1 + }', + '{ + "type":"object", + "properties": { + "null":{"type":"null"} + }, + "additionalProperties":false + }' + ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "string":"string test", - "number":1, - "integer":1, - "boolean":true, - "object":{}, - "array":[], - "null":null, - "any": "string", - "any1": 2.6, - "any2": 4, - "any3": false, - "any4": {}, - "any5": [], - "any6": null - }', - '{ - "type":"object", - "properties":{ - "string":{"type":"string"}, - "number":{"type":"number"}, - "integer":{"type":"integer"}, - "boolean":{"type":"boolean"}, - "object":{"type":"object"}, - "array":{"type":"array"}, - "null":{"type":"null"}, - "any": {"type":"any"}, - "any1": {"type":"any"}, - "any2": {"type":"any"}, - "any3": {"type":"any"}, - "any4": {"type":"any"}, - "any5": {"type":"any"}, - "any6": {"type":"any"} - }, - "additionalProperties":false - }' - ] + yield [ + '{ + "string":"string test", + "number":1, + "integer":1, + "boolean":true, + "object":{}, + "array":[], + "null":null, + "any": "string", + "any1": 2.6, + "any2": 4, + "any3": false, + "any4": {}, + "any5": [], + "any6": null + }', + '{ + "type":"object", + "properties":{ + "string":{"type":"string"}, + "number":{"type":"number"}, + "integer":{"type":"integer"}, + "boolean":{"type":"boolean"}, + "object":{"type":"object"}, + "array":{"type":"array"}, + "null":{"type":"null"}, + "any": {"type":"any"}, + "any1": {"type":"any"}, + "any2": {"type":"any"}, + "any3": {"type":"any"}, + "any4": {"type":"any"}, + "any5": {"type":"any"}, + "any6": {"type":"any"} + }, + "additionalProperties":false + }' ]; } } From d1e148d2d39009379fe8a264dc107a0bd87ec6af Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:11:40 +0200 Subject: [PATCH 009/114] docs: remove file based license reference --- tests/Constraints/BasicTypesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/BasicTypesTest.php b/tests/Constraints/BasicTypesTest.php index 53e6e6a0..22084090 100644 --- a/tests/Constraints/BasicTypesTest.php +++ b/tests/Constraints/BasicTypesTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:11:51 +0200 Subject: [PATCH 010/114] refactor: add missing type hints --- tests/Constraints/BasicTypesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Constraints/BasicTypesTest.php b/tests/Constraints/BasicTypesTest.php index 22084090..83db96bf 100644 --- a/tests/Constraints/BasicTypesTest.php +++ b/tests/Constraints/BasicTypesTest.php @@ -4,7 +4,9 @@ class BasicTypesTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 9ef10bb9cfe50739c4887a40c0d031d966cdad47 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:14:02 +0200 Subject: [PATCH 011/114] refactor: apply generator to const test --- tests/Constraints/ConstTest.php | 156 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 80 deletions(-) diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index ec4f688d..653aa687 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -14,40 +14,39 @@ class ConstTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-06/schema#'; protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - 'Object with inner string value' => [ - '{"value":"foo"}', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","const":"bar"} - }, - "additionalProperties":false - }' - ], - 'Object with inner integer value' => [ - '{"value":5}', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","const":6} - }, - "additionalProperties":false - }' - ], - 'Object with inner boolean value' => [ - '{"value":false}', - '{ - "type":"object", - "properties":{ - "value":{"type":"boolean","const":true} - }, - "additionalProperties":false - }' - ], - 'Object with inner numerical string value' => [ + yield 'Object with inner string value' => [ + '{"value":"foo"}', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","const":"bar"} + }, + "additionalProperties":false + }' + ]; + yield 'Object with inner integer value' => [ + '{"value":5}', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","const":6} + }, + "additionalProperties":false + }' + ]; + yield 'Object with inner boolean value' => [ + '{"value":false}', + '{ + "type":"object", + "properties":{ + "value":{"type":"boolean","const":true} + }, + "additionalProperties":false + }' + ]; + yield 'Object with inner numerical string value' => [ '{ "value": { "foo": "12" @@ -64,54 +63,52 @@ public function getInvalidTests(): array } } }' - ] - ]; + ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - 'String value' => [ - '{"value":"bar"}', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","const":"bar"} - }, - "additionalProperties":false - }' - ], - 'Boolean(false) value' => [ - '{"value":false}', - '{ - "type":"object", - "properties":{ - "value":{"type":"boolean","const":false} - }, - "additionalProperties":false - }' - ], - 'Boolean(true) value' => [ - '{"value":true}', - '{ - "type":"object", - "properties":{ - "value":{"type":"boolean","const":true} - }, - "additionalProperties":false - }' - ], - 'Integer value' => [ - '{"value":5}', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","const":5} - }, - "additionalProperties":false - }' - ], - 'Object with inner integer value' => [ + yield 'String value' => [ + '{"value":"bar"}', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","const":"bar"} + }, + "additionalProperties":false + }' + ]; + yield 'Boolean(false) value' => [ + '{"value":false}', + '{ + "type":"object", + "properties":{ + "value":{"type":"boolean","const":false} + }, + "additionalProperties":false + }' + ]; + yield 'Boolean(true) value' => [ + '{"value":true}', + '{ + "type":"object", + "properties":{ + "value":{"type":"boolean","const":true} + }, + "additionalProperties":false + }' + ]; + yield 'Integer value' => [ + '{"value":5}', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","const":5} + }, + "additionalProperties":false + }' + ]; + yield 'Object with inner integer value' => [ '{ "value": { "foo": 12 @@ -128,7 +125,6 @@ public function getValidTests(): array } } }' - ] - ]; + ]; } } From b8618432b83056754fff363d3bd080eda3343140 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:14:25 +0200 Subject: [PATCH 012/114] docs: remove file based reference to license --- tests/Constraints/ConstTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index 653aa687..4e0de0fb 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -1,11 +1,5 @@ Date: Wed, 11 Jun 2025 20:14:35 +0200 Subject: [PATCH 013/114] refactor: add missing type hints --- tests/Constraints/ConstTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index 4e0de0fb..2efc3f82 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -5,7 +5,9 @@ class ConstTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-06/schema#'; + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From bfcd4d859c844f6d0ff87d90ea8507403ad87ffe Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:14:57 +0200 Subject: [PATCH 014/114] style: remove redundant newline --- tests/Constraints/ConstTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index 2efc3f82..2801a96e 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -1,6 +1,5 @@ Date: Wed, 11 Jun 2025 20:17:16 +0200 Subject: [PATCH 015/114] refactor: apply generator to dependencies test --- tests/Constraints/DependenciesTest.php | 250 ++++++++++++------------- 1 file changed, 123 insertions(+), 127 deletions(-) diff --git a/tests/Constraints/DependenciesTest.php b/tests/Constraints/DependenciesTest.php index ff3ffb8e..6639189d 100644 --- a/tests/Constraints/DependenciesTest.php +++ b/tests/Constraints/DependenciesTest.php @@ -14,138 +14,134 @@ class DependenciesTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{"bar": 1}', - '{ - "dependencies": {"bar": "foo"} - }' - ], - [ - '{"bar": 1}', - '{ - "dependencies": {"bar": ["foo"]} - }' - ], - [ - '{"bar": 1, "foo": 1}', - '{ - "dependencies": {"bar": ["foo", "baz"]} - }' - ], - [ - '{"bar": 1, "foo": 1}', - '{ - "dependencies": {"bar": { - "properties": { - "foo": {"type": "string"} - } - }} - }' - ], - [ - '{"bar": 1}', - '{ - "dependencies": {"bar": { - "properties": { - "foo": {"type": "integer", "required": true} - } - }} - }' - ], - [ - '{"bar": 1}', - '{ - "dependencies": {"bar": { - "properties": { - "foo": {"type": "integer"} - }, - "required": ["foo"] - }} - }' - ], - [ - '{"bar": true, "foo": "ick"}', - '{ - "dependencies": {"bar": { - "properties": { - "bar": {"type": "integer"}, - "foo": {"type": "integer"} - } - }} - }' - ] + yield [ + '{"bar": 1}', + '{ + "dependencies": {"bar": "foo"} + }' + ]; + yield [ + '{"bar": 1}', + '{ + "dependencies": {"bar": ["foo"]} + }' + ]; + yield [ + '{"bar": 1, "foo": 1}', + '{ + "dependencies": {"bar": ["foo", "baz"]} + }' + ]; + yield [ + '{"bar": 1, "foo": 1}', + '{ + "dependencies": {"bar": { + "properties": { + "foo": {"type": "string"} + } + }} + }' + ]; + yield [ + '{"bar": 1}', + '{ + "dependencies": {"bar": { + "properties": { + "foo": {"type": "integer", "required": true} + } + }} + }' + ]; + yield [ + '{"bar": 1}', + '{ + "dependencies": {"bar": { + "properties": { + "foo": {"type": "integer"} + }, + "required": ["foo"] + }} + }' + ]; + yield [ + '{"bar": true, "foo": "ick"}', + '{ + "dependencies": {"bar": { + "properties": { + "bar": {"type": "integer"}, + "foo": {"type": "integer"} + } + }} + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{}', - '{ - "dependencies": {"bar": "foo"} - }' - ], - [ - '{"foo": 1}', - '{ - "dependencies": {"bar": "foo"} - }' - ], - [ - '"foo"', - '{ - "dependencies": {"bar": "foo"} - }' - ], - [ - '{"bar": 1, "foo": 1}', - '{ - "dependencies": {"bar": "foo"} - }' - ], - [ - '{"bar": 1, "foo": 1, "baz": 1}', - '{ - "dependencies": {"bar": ["foo", "baz"]} - }' - ], - [ - '{}', - '{ - "dependencies": {"bar": ["foo", "baz"]} - }' - ], - [ - '{"foo": 1, "baz": 1}', - '{ - "dependencies": {"bar": ["foo", "baz"]} - }' - ], - [ - '{"bar": 1}', - '{ - "dependencies": {"bar": { - "properties": { - "foo": {"type": "integer"} - } - }} - }' - ], - [ - '{"bar": 1, "foo": 1}', - '{ - "dependencies": {"bar": { - "properties": { - "bar": {"type": "integer"}, - "foo": {"type": "integer"} - } - }} - }' - ] + yield [ + '{}', + '{ + "dependencies": {"bar": "foo"} + }' + ]; + yield [ + '{"foo": 1}', + '{ + "dependencies": {"bar": "foo"} + }' + ]; + yield [ + '"foo"', + '{ + "dependencies": {"bar": "foo"} + }' + ]; + yield [ + '{"bar": 1, "foo": 1}', + '{ + "dependencies": {"bar": "foo"} + }' + ]; + yield [ + '{"bar": 1, "foo": 1, "baz": 1}', + '{ + "dependencies": {"bar": ["foo", "baz"]} + }' + ]; + yield [ + '{}', + '{ + "dependencies": {"bar": ["foo", "baz"]} + }' + ]; + yield [ + '{"foo": 1, "baz": 1}', + '{ + "dependencies": {"bar": ["foo", "baz"]} + }' + ]; + yield [ + '{"bar": 1}', + '{ + "dependencies": {"bar": { + "properties": { + "foo": {"type": "integer"} + } + }} + }' + ]; + yield [ + '{"bar": 1, "foo": 1}', + '{ + "dependencies": {"bar": { + "properties": { + "bar": {"type": "integer"}, + "foo": {"type": "integer"} + } + }} + }' ]; } } From 1dc17a4b614eb0185278073d78dd6e915895f8b8 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:17:36 +0200 Subject: [PATCH 016/114] docs: remove file level reference to license --- tests/Constraints/DependenciesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/DependenciesTest.php b/tests/Constraints/DependenciesTest.php index 6639189d..7fe5f2db 100644 --- a/tests/Constraints/DependenciesTest.php +++ b/tests/Constraints/DependenciesTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:17:48 +0200 Subject: [PATCH 017/114] refactor: add missing type hints --- tests/Constraints/DependenciesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Constraints/DependenciesTest.php b/tests/Constraints/DependenciesTest.php index 7fe5f2db..7a89ebe2 100644 --- a/tests/Constraints/DependenciesTest.php +++ b/tests/Constraints/DependenciesTest.php @@ -4,7 +4,9 @@ class DependenciesTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From ff42063a189fec487531f4eaed2cbfb1d6e3119d Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:21:04 +0200 Subject: [PATCH 018/114] refactor: apply generator to disallow test --- tests/Constraints/DisallowTest.php | 272 ++++++++++++++--------------- 1 file changed, 134 insertions(+), 138 deletions(-) diff --git a/tests/Constraints/DisallowTest.php b/tests/Constraints/DisallowTest.php index 1fe93f6c..4d88072d 100644 --- a/tests/Constraints/DisallowTest.php +++ b/tests/Constraints/DisallowTest.php @@ -19,152 +19,148 @@ class DisallowTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; protected $validateSchema = false; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":"The xpto is weird" - }', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"any", - "disallow":{"type":"string","pattern":"xpto"} - } - } - }' - ], - [ - '{ - "value":null - }', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"any", - "disallow":{"type":"null"} - } - } - }' - ], - [ - '{"value": 1}', - '{ - "type": "object", - "properties": { - "value": {"type": "any", "disallow": "integer"} - } - }' - ], - [ - '{"value": true}', - '{ - "type": "object", - "properties": { - "value": {"type": "any", "disallow": ["integer", "boolean"]} - } - }' - ], - [ - '{"value": "foo"}', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", - "disallow": - ["string", { - "type": "object", - "properties": { - "foo": {"type": "string"} - } - }] - } + yield [ + '{ + "value":"The xpto is weird" + }', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"any", + "disallow":{"type":"string","pattern":"xpto"} + } + } + }' + ]; + yield [ + '{ + "value":null + }', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"any", + "disallow":{"type":"null"} + } + } + }' + ]; + yield [ + '{"value": 1}', + '{ + "type": "object", + "properties": { + "value": {"type": "any", "disallow": "integer"} + } + }' + ]; + yield [ + '{"value": true}', + '{ + "type": "object", + "properties": { + "value": {"type": "any", "disallow": ["integer", "boolean"]} + } + }' + ]; + yield [ + '{"value": "foo"}', + '{ + "type": "object", + "properties": { + "value": { + "type": "any", + "disallow": + ["string", { + "type": "object", + "properties": { + "foo": {"type": "string"} + } + }] } - }' - ], - [ - '{"value": {"foo": "bar"}}', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", - "disallow": - ["string", { - "type": "object", - "properties": { - "foo": {"type": "string"} - } - }] - } + } + }' + ]; + yield [ + '{"value": {"foo": "bar"}}', + '{ + "type": "object", + "properties": { + "value": { + "type": "any", + "disallow": + ["string", { + "type": "object", + "properties": { + "foo": {"type": "string"} + } + }] } - }' - ] + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":"The xpto is weird" - }', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"any", - "disallow":{"type":"string","pattern":"^xpto"} - } - } - }' - ], - [ - '{ - "value":1 - }', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"any", - "disallow":{"type":"null"} - } - } - }' - ], - [ - '{"value": {"foo": 1}}', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", - "disallow": - ["string", { - "type": "object", - "properties": { - "foo": {"type": "string"} - } - }] - } - } - }' - ], - [ - '{"value": true}', - '{ - "type": "object", - "properties": { - "value": {"type": "any", "disallow": "string"} + yield [ + '{ + "value":"The xpto is weird" + }', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"any", + "disallow":{"type":"string","pattern":"^xpto"} + } + } + }' + ]; + yield [ + '{ + "value":1 + }', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"any", + "disallow":{"type":"null"} + } + } + }' + ]; + yield [ + '{"value": {"foo": 1}}', + '{ + "type": "object", + "properties": { + "value": { + "type": "any", + "disallow": + ["string", { + "type": "object", + "properties": { + "foo": {"type": "string"} + } + }] } - }' - ] + } + }' + ]; + yield [ + '{"value": true}', + '{ + "type": "object", + "properties": { + "value": {"type": "any", "disallow": "string"} + } + }' ]; } } From 3128028b68fab55793907806444e375c1575c57c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:21:46 +0200 Subject: [PATCH 019/114] docs: remove file level license reference; move class comment to correct level --- tests/Constraints/DisallowTest.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/Constraints/DisallowTest.php b/tests/Constraints/DisallowTest.php index 4d88072d..8b26ee69 100644 --- a/tests/Constraints/DisallowTest.php +++ b/tests/Constraints/DisallowTest.php @@ -1,21 +1,16 @@ Date: Wed, 11 Jun 2025 20:22:39 +0200 Subject: [PATCH 020/114] refactor: remove overriding property with same value --- tests/Constraints/DisallowTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Constraints/DisallowTest.php b/tests/Constraints/DisallowTest.php index 8b26ee69..9eb08fbb 100644 --- a/tests/Constraints/DisallowTest.php +++ b/tests/Constraints/DisallowTest.php @@ -12,7 +12,6 @@ class DisallowTest extends BaseTestCase { protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; - protected $validateSchema = false; public function getInvalidTests(): \Generator { From d55d3c3e25543d399fd4c1a56dec359ddc328903 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:22:57 +0200 Subject: [PATCH 021/114] refactor: add missing type hint --- tests/Constraints/DisallowTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/DisallowTest.php b/tests/Constraints/DisallowTest.php index 9eb08fbb..5717ae89 100644 --- a/tests/Constraints/DisallowTest.php +++ b/tests/Constraints/DisallowTest.php @@ -11,6 +11,7 @@ */ class DisallowTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; public function getInvalidTests(): \Generator From 993c5bf16b7bed730d47d7a2b298a0ff7d4845da Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:24:59 +0200 Subject: [PATCH 022/114] refactor: apply generator to divisible by test --- tests/Constraints/DivisibleByTest.php | 144 +++++++++++++------------- 1 file changed, 70 insertions(+), 74 deletions(-) diff --git a/tests/Constraints/DivisibleByTest.php b/tests/Constraints/DivisibleByTest.php index 354d6a29..204bb4cb 100644 --- a/tests/Constraints/DivisibleByTest.php +++ b/tests/Constraints/DivisibleByTest.php @@ -13,85 +13,81 @@ class DivisibleByTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{"value": 5.6333}', - '{ - "type":"object", - "properties":{ - "value":{"type":"number","divisibleBy":3} - } - }' - ], - [ - '{"value": 35}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "divisibleBy": 1.5} - } - }' - ], - [ - '{"value": 0.00751}', - '{ - "type": "object", - "properties": { - "value": {"type": "number", "divisibleBy": 0.0001} - } - }' - ], - [ - '{"value": 7}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "divisibleBy": 2} - } - }' - ] + yield [ + '{"value": 5.6333}', + '{ + "type":"object", + "properties":{ + "value":{"type":"number","divisibleBy":3} + } + }' + ]; + yield [ + '{"value": 35}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "divisibleBy": 1.5} + } + }' + ]; + yield [ + '{"value": 0.00751}', + '{ + "type": "object", + "properties": { + "value": {"type": "number", "divisibleBy": 0.0001} + } + }' + ]; + yield [ + '{"value": 7}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "divisibleBy": 2} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{"value": 6}', - '{ - "type":"object", - "properties":{ - "value":{"type":"number","divisibleBy":3} - } - }' - ], - [ - '{"value": 4.5}', - '{ - "type": "object", - "properties": { - "value": {"type": "number", "divisibleBy": 1.5} - } - }' - ], - [ - '{"value": 0.0075}', - '{ - "properties": { - "value": {"type": "number", "divisibleBy": 0.0001} - } - }' - ], - [ - '{"value": 1}', - '{ - "properties": { - "value": {"type": "number", "divisibleBy": 0.02} - } - }' - ] + yield [ + '{"value": 6}', + '{ + "type":"object", + "properties":{ + "value":{"type":"number","divisibleBy":3} + } + }' + ]; + yield [ + '{"value": 4.5}', + '{ + "type": "object", + "properties": { + "value": {"type": "number", "divisibleBy": 1.5} + } + }' + ]; + yield [ + '{"value": 0.0075}', + '{ + "properties": { + "value": {"type": "number", "divisibleBy": 0.0001} + } + }' + ]; + yield [ + '{"value": 1}', + '{ + "properties": { + "value": {"type": "number", "divisibleBy": 0.02} + } + }' ]; } } From e7027bed1af05c6be237dd58760b5f579125d95e Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:25:18 +0200 Subject: [PATCH 023/114] docs: remove file level reference to license --- tests/Constraints/DivisibleByTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/DivisibleByTest.php b/tests/Constraints/DivisibleByTest.php index 204bb4cb..46ad6e89 100644 --- a/tests/Constraints/DivisibleByTest.php +++ b/tests/Constraints/DivisibleByTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:25:32 +0200 Subject: [PATCH 024/114] refactor: add missing type hint --- tests/Constraints/DivisibleByTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/DivisibleByTest.php b/tests/Constraints/DivisibleByTest.php index 46ad6e89..63102db3 100644 --- a/tests/Constraints/DivisibleByTest.php +++ b/tests/Constraints/DivisibleByTest.php @@ -4,6 +4,7 @@ class DivisibleByTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 738b9ca5597370ca13ca5f9e893e412f3ecc4eaf Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:27:59 +0200 Subject: [PATCH 025/114] refactor: apply generator to enum test --- tests/Constraints/EnumTest.php | 332 ++++++++++++++++----------------- 1 file changed, 164 insertions(+), 168 deletions(-) diff --git a/tests/Constraints/EnumTest.php b/tests/Constraints/EnumTest.php index a70f871f..73eec357 100644 --- a/tests/Constraints/EnumTest.php +++ b/tests/Constraints/EnumTest.php @@ -14,185 +14,181 @@ class EnumTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":"Morango" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} - }, - "additionalProperties":false - }' - ], - [ - '{}', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"string", - "enum":["Abacate","Manga","Pitanga"], - "required":true + yield [ + '{ + "value":"Morango" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} + }, + "additionalProperties":false + }' + ]; + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"string", + "enum":["Abacate","Manga","Pitanga"], + "required":true + } + }, + "additionalProperties":false + }' + ]; + yield [ + '{"value": "4"}', + '{ + "type": "object", + "properties": { + "value": { + "type": "integer", "enum": [1, 2, 3] } - }, - "additionalProperties":false - }' - ], - [ - '{"value": "4"}', - '{ - "type": "object", - "properties": { - "value": { - "type": "integer", "enum": [1, 2, 3] - } - }, - "additionalProperties": false - }' - ], - [ - '{"value": {"foo": false}}', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", "enum": [6, "foo", [], true, {"foo": 12}] - } - }, - "additionalProperties": false - }' - ], - [ - '{ + }, + "additionalProperties": false + }' + ]; + yield [ + '{"value": {"foo": false}}', + '{ + "type": "object", + "properties": { "value": { - "foo": "12" + "type": "any", "enum": [6, "foo", [], true, {"foo": 12}] } - }', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", - "enum": [ - 6, - "foo", - [], - true, - { - "foo": 12 - } - ] - } + }, + "additionalProperties": false + }' + ]; + yield [ + '{ + "value": { + "foo": "12" + } + }', + '{ + "type": "object", + "properties": { + "value": { + "type": "any", + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] } - }' - ] + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":"Abacate" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} - }, - "additionalProperties":false - }' - ], - [ - '{}', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} - }, - "additionalProperties":false - }' - ], - [ - '{}', - '{ - "type":"object", - "properties":{ - "value":{ - "type":"string", - "enum":["Abacate","Manga","Pitanga"], - "required":false - } - }, - "additionalProperties":false - }' - ], - [ - '{"value": 1}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "enum": [1, 2, 3]} - } - }' - ], - [ - '{"value": []}', - '{ - "type": "object", - "properties": { - "value": {"type": "any", "enum": [6, "foo", [], true, {"foo": 12}]} - }, - "additionalProperties": false - }' - ], - [ - '{ + yield [ + '{ + "value":"Abacate" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} + }, + "additionalProperties":false + }' + ]; + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","enum":["Abacate","Manga","Pitanga"]} + }, + "additionalProperties":false + }' + ]; + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "value":{ + "type":"string", + "enum":["Abacate","Manga","Pitanga"], + "required":false + } + }, + "additionalProperties":false + }' + ]; + yield [ + '{"value": 1}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "enum": [1, 2, 3]} + } + }' + ]; + yield [ + '{"value": []}', + '{ + "type": "object", + "properties": { + "value": {"type": "any", "enum": [6, "foo", [], true, {"foo": 12}]} + }, + "additionalProperties": false + }' + ]; + yield [ + '{ + "value": { + "foo": 12 + } + }', + '{ + "type": "object", + "properties": { "value": { - "foo": 12 - } - }', - '{ - "type": "object", - "properties": { - "value": { - "type": "any", - "enum": [ - 6, - "foo", - [], - true, - { - "foo": 12 - } - ] - } + "type": "any", + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] } - }' - ], - 'Number values with mathematical equality are considered valid' => [ - 'data' => '12', - 'schema' => '{ - "type": "any", - "enum": [ - 12.0 - ] - }' - ], - 'Array with number values with mathematical equality are considered valid' => [ - 'input' => '[ 0.0 ]', - 'schema' => '{ - "enum": [ - [ 0 ] - ] - }', - ] + } + }' + ]; + yield 'Number values with mathematical equality are considered valid' => [ + 'data' => '12', + 'schema' => '{ + "type": "any", + "enum": [ + 12.0 + ] + }' + ]; + yield 'Array with number values with mathematical equality are considered valid' => [ + 'input' => '[ 0.0 ]', + 'schema' => '{ + "enum": [ + [ 0 ] + ] + }', ]; } } From 1abf94793186d4ee9840c724aafc7307a64cacb9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:28:14 +0200 Subject: [PATCH 026/114] docs: remove file level license reference --- tests/Constraints/EnumTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/EnumTest.php b/tests/Constraints/EnumTest.php index 73eec357..9705afbb 100644 --- a/tests/Constraints/EnumTest.php +++ b/tests/Constraints/EnumTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:28:26 +0200 Subject: [PATCH 027/114] refactor: add missing type hints --- tests/Constraints/EnumTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Constraints/EnumTest.php b/tests/Constraints/EnumTest.php index 9705afbb..a4752387 100644 --- a/tests/Constraints/EnumTest.php +++ b/tests/Constraints/EnumTest.php @@ -4,7 +4,9 @@ class EnumTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From fa4eacf01ec17d840ead629b203c122c3ce62420 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:30:18 +0200 Subject: [PATCH 028/114] refactor: apply generator to extends test --- tests/Constraints/ExtendsTest.php | 220 +++++++++++++++--------------- 1 file changed, 108 insertions(+), 112 deletions(-) diff --git a/tests/Constraints/ExtendsTest.php b/tests/Constraints/ExtendsTest.php index 286b24b8..e7cf16ce 100644 --- a/tests/Constraints/ExtendsTest.php +++ b/tests/Constraints/ExtendsTest.php @@ -14,141 +14,137 @@ class ExtendsTest extends BaseTestCase protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "name":"bruno", - "age":50 - }', - '{ + yield [ + '{ + "name":"bruno", + "age":50 + }', + '{ + "properties": { + "name": {"type": "string"}, + "age": { + "type": "integer", + "maximum": 120 + } + }, + "extends": { "properties": { - "name": {"type": "string"}, - "age": { - "type": "integer", - "maximum": 120 - } - }, - "extends": { - "properties": { - "age": {"minimum": 70} - } + "age": {"minimum": 70} + } + } + }' + ]; + yield [ + '{ + "name":"bruno", + "age":180 + }', + '{ + "properties": { + "name": {"type": "string"}, + "age": { + "type": "integer", + "maximum": 120 } - }' - ], - [ - '{ - "name":"bruno", - "age":180 - }', - '{ + }, + "extends": { "properties": { - "name": {"type": "string"}, - "age": { - "type": "integer", - "maximum": 120 - } - }, - "extends": { - "properties": { - "age": {"minimum":70} - } + "age": {"minimum":70} } - }' - ], - [ - '{"foo": 2, "bar": "baz"}', - '{ + } + }' + ]; + yield [ + '{"foo": 2, "bar": "baz"}', + '{ + "properties": { + "bar": {"type": "integer", "required": true} + }, + "extends": { "properties": { - "bar": {"type": "integer", "required": true} - }, - "extends": { + "foo": {"type": "string", "required": true} + } + } + }' + ]; + yield [ + '{"bar": 2}', + '{ + "properties": { + "bar": {"type": "integer", "required": true} + }, + "extends" : [ + { "properties": { "foo": {"type": "string", "required": true} } - } - }' - ], - [ - '{"bar": 2}', - '{ - "properties": { - "bar": {"type": "integer", "required": true} }, - "extends" : [ - { - "properties": { - "foo": {"type": "string", "required": true} - } - }, - { - "properties": { - "baz": {"type": "null", "required": true} - } + { + "properties": { + "baz": {"type": "null", "required": true} } - ] - }' - ] + } + ] + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "name":"bruno", - "age":80 - }', - '{ + yield [ + '{ + "name":"bruno", + "age":80 + }', + '{ + "properties": { + "name": {"type": "string"}, + "age": { + "type": "integer", + "maximum": 120 + } + }, + "extends": { "properties": { - "name": {"type": "string"}, - "age": { - "type": "integer", - "maximum": 120 - } - }, - "extends": { - "properties": { - "age": {"minimum": 70} - } + "age": {"minimum": 70} } - }' - ], - [ - '{"foo": "baz", "bar": 2}', - '{ + } + }' + ]; + yield [ + '{"foo": "baz", "bar": 2}', + '{ + "properties": { + "bar": {"type": "integer", "required": true} + }, + "extends": { "properties": { - "bar": {"type": "integer", "required": true} - }, - "extends": { + "foo": {"type": "string", "required": true} + } + } + }' + ]; + yield [ + '{"foo": "ick", "bar": 2, "baz": null}', + '{ + "properties": { + "bar": {"type": "integer", "required": true} + }, + "extends" : [ + { "properties": { "foo": {"type": "string", "required": true} } - } - }' - ], - [ - '{"foo": "ick", "bar": 2, "baz": null}', - '{ - "properties": { - "bar": {"type": "integer", "required": true} }, - "extends" : [ - { - "properties": { - "foo": {"type": "string", "required": true} - } - }, - { - "properties": { - "baz": {"type": "null", "required": true} - } + { + "properties": { + "baz": {"type": "null", "required": true} } - ] - }' - ] + } + ] + }' ]; } } From b2c3eb750db168f71403e355996565144c10fead Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:30:44 +0200 Subject: [PATCH 029/114] docs: remove file level reference to license --- tests/Constraints/ExtendsTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/ExtendsTest.php b/tests/Constraints/ExtendsTest.php index e7cf16ce..10368b66 100644 --- a/tests/Constraints/ExtendsTest.php +++ b/tests/Constraints/ExtendsTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:30:56 +0200 Subject: [PATCH 030/114] refactor: add missing type hints --- tests/Constraints/ExtendsTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Constraints/ExtendsTest.php b/tests/Constraints/ExtendsTest.php index 10368b66..b8013e2d 100644 --- a/tests/Constraints/ExtendsTest.php +++ b/tests/Constraints/ExtendsTest.php @@ -4,7 +4,9 @@ class ExtendsTest extends BaseTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 2d580652b58362878c9ae516b2ec98aba8132548 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:40:35 +0200 Subject: [PATCH 031/114] refactor: apply generator to format test --- tests/Constraints/FormatTest.php | 339 +++++++++++++++---------------- 1 file changed, 166 insertions(+), 173 deletions(-) diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 25eab1c0..4b836304 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -95,204 +95,197 @@ public function testDisabledFormat($string, $format): void $this->assertEmpty($validator->getErrors()); } - public function getValidFormats(): array + public function getValidFormats(): \Generator { - return [ - ['2001-01-23', 'date'], - ['2000-02-29', 'date'], - [42, 'date'], - [4.2, 'date'], - - ['12:22:01', 'time'], - ['00:00:00', 'time'], - ['23:59:59', 'time'], - [42, 'time'], - [4.2, 'time'], - - ['2000-05-01T12:12:12Z', 'date-time'], - ['2000-05-01T12:12:12+0100', 'date-time'], - ['2000-05-01T12:12:12+01:00', 'date-time'], - ['2000-05-01T12:12:12.123456Z', 'date-time'], - ['2000-05-01T12:12:12.123Z', 'date-time'], - ['2000-05-01T12:12:12.123000Z', 'date-time'], - ['2000-05-01T12:12:12.0Z', 'date-time'], - ['2000-05-01T12:12:12.000Z', 'date-time'], - ['2000-05-01T12:12:12.000000Z', 'date-time'], - [42, 'date-time'], - [4.2, 'date-time'], - - ['0', 'utc-millisec'], - - ['aqua', 'color'], - ['black', 'color'], - ['blue', 'color'], - ['fuchsia', 'color'], - ['gray', 'color'], - ['green', 'color'], - ['lime', 'color'], - ['maroon', 'color'], - ['navy', 'color'], - ['olive', 'color'], - ['orange', 'color'], - ['purple', 'color'], - ['red', 'color'], - ['silver', 'color'], - ['teal', 'color'], - ['white', 'color'], - ['yellow', 'color'], - ['#fff', 'color'], - ['#00cc00', 'color'], - [42, 'color'], - [4.2, 'color'], - - ['background: blue', 'style'], - ['color: #000;', 'style'], - - ['555 320 1212', 'phone'], - - ['http://bluebox.org', 'uri'], - ['//bluebox.org', 'uri-reference'], - ['/absolutePathReference/', 'uri-reference'], - ['./relativePathReference/', 'uri-reference'], - ['./relative:PathReference/', 'uri-reference'], - ['relativePathReference/', 'uri-reference'], - ['relative/Path:Reference/', 'uri-reference'], - [42, 'uri-reference'], - [4.2, 'uri-reference'], - - ['info@something.edu', 'email'], - [42, 'email'], - [4.2, 'email'], - - ['10.10.10.10', 'ip-address'], - ['127.0.0.1', 'ip-address'], - [42, 'ip-address'], - [4.2, 'ip-address'], - - ['127.0.0.1', 'ipv4'], - [42, 'ipv4'], - [4.2, 'ipv4'], - - ['::ff', 'ipv6'], - [42, 'ipv6'], - [4.2, 'ipv6'], - - ['www.example.com', 'host-name'], - ['3v4l.org', 'host-name'], - ['a-valid-host.com', 'host-name'], - ['localhost', 'host-name'], - [42, 'host-name'], - [4.2, 'host-name'], - - ['www.example.com', 'hostname'], - ['3v4l.org', 'hostname'], - ['a-valid-host.com', 'hostname'], - ['localhost', 'hostname'], - [42, 'hostname'], - [4.2, 'hostname'], - - ['anything', '*'], - ['unknown', '*'], - ]; + yield ['2001-01-23', 'date']; + yield ['2000-02-29', 'date']; + yield [42, 'date']; + yield [4.2, 'date']; + + yield ['12:22:01', 'time']; + yield ['00:00:00', 'time']; + yield ['23:59:59', 'time']; + yield [42, 'time']; + yield [4.2, 'time']; + + yield ['2000-05-01T12:12:12Z', 'date-time']; + yield ['2000-05-01T12:12:12+0100', 'date-time']; + yield ['2000-05-01T12:12:12+01:00', 'date-time']; + yield ['2000-05-01T12:12:12.123456Z', 'date-time']; + yield ['2000-05-01T12:12:12.123Z', 'date-time']; + yield ['2000-05-01T12:12:12.123000Z', 'date-time']; + yield ['2000-05-01T12:12:12.0Z', 'date-time']; + yield ['2000-05-01T12:12:12.000Z', 'date-time']; + yield ['2000-05-01T12:12:12.000000Z', 'date-time']; + yield [42, 'date-time']; + yield [4.2, 'date-time']; + + yield ['0', 'utc-millisec']; + + yield ['aqua', 'color']; + yield ['black', 'color']; + yield ['blue', 'color']; + yield ['fuchsia', 'color']; + yield ['gray', 'color']; + yield ['green', 'color']; + yield ['lime', 'color']; + yield ['maroon', 'color']; + yield ['navy', 'color']; + yield ['olive', 'color']; + yield ['orange', 'color']; + yield ['purple', 'color']; + yield ['red', 'color']; + yield ['silver', 'color']; + yield ['teal', 'color']; + yield ['white', 'color']; + yield ['yellow', 'color']; + yield ['#fff', 'color']; + yield ['#00cc00', 'color']; + yield [42, 'color']; + yield [4.2, 'color']; + + yield ['background: blue', 'style']; + yield ['color: #000;', 'style']; + + yield ['555 320 1212', 'phone']; + + yield ['http://bluebox.org', 'uri']; + yield ['//bluebox.org', 'uri-reference']; + yield ['/absolutePathReference/', 'uri-reference']; + yield ['./relativePathReference/', 'uri-reference']; + yield ['./relative:PathReference/', 'uri-reference']; + yield ['relativePathReference/', 'uri-reference']; + yield ['relative/Path:Reference/', 'uri-reference']; + yield [42, 'uri-reference']; + yield [4.2, 'uri-reference']; + + yield ['info@something.edu', 'email']; + yield [42, 'email']; + yield [4.2, 'email']; + + yield ['10.10.10.10', 'ip-address']; + yield ['127.0.0.1', 'ip-address']; + yield [42, 'ip-address']; + yield [4.2, 'ip-address']; + + yield ['127.0.0.1', 'ipv4']; + yield [42, 'ipv4']; + yield [4.2, 'ipv4']; + + yield ['::ff', 'ipv6']; + yield [42, 'ipv6']; + yield [4.2, 'ipv6']; + + yield ['www.example.com', 'host-name']; + yield ['3v4l.org', 'host-name']; + yield ['a-valid-host.com', 'host-name']; + yield ['localhost', 'host-name']; + yield [42, 'host-name']; + yield [4.2, 'host-name']; + + yield ['www.example.com', 'hostname']; + yield ['3v4l.org', 'hostname']; + yield ['a-valid-host.com', 'hostname']; + yield ['localhost', 'hostname']; + yield [42, 'hostname']; + yield [4.2, 'hostname']; + + yield ['anything', '*']; + yield ['unknown', '*']; } - public function getInvalidFormats(): array + public function getInvalidFormats(): \Generator { - return [ - ['January 1st, 1910', 'date'], - ['199-01-1', 'date'], - ['2012-0-11', 'date'], - ['2012-10-1', 'date'], + yield ['January 1st, 1910', 'date']; + yield ['199-01-1', 'date']; + yield ['2012-0-11', 'date']; + yield ['2012-10-1', 'date']; - ['24:01:00', 'time'], - ['00:00:60', 'time'], - ['25:00:00', 'time'], + yield ['24:01:00', 'time']; + yield ['00:00:60', 'time']; + yield ['25:00:00', 'time']; - ['invalid_value_2000-05-01T12:12:12Z', 'date-time'], - ['2000-05-01T12:12:12Z_invalid_value', 'date-time'], - ['1999-1-11T00:00:00Z', 'date-time'], - ['1999-01-11T00:00:00+100', 'date-time'], - ['1999-01-11T00:00:00+1:00', 'date-time'], - ['1999.000Z-01-11T00:00:00+1:00', 'date-time'], + yield ['invalid_value_2000-05-01T12:12:12Z', 'date-time']; + yield ['2000-05-01T12:12:12Z_invalid_value', 'date-time']; + yield ['1999-1-11T00:00:00Z', 'date-time']; + yield ['1999-01-11T00:00:00+100', 'date-time']; + yield ['1999-01-11T00:00:00+1:00', 'date-time']; + yield ['1999.000Z-01-11T00:00:00+1:00', 'date-time']; - [PHP_INT_MAX, 'utc-millisec'], + yield [PHP_INT_MAX, 'utc-millisec']; - ['grey', 'color'], - ['#HHH', 'color'], - ['#000a', 'color'], - ['#aa', 'color'], + yield ['grey', 'color']; + yield ['#HHH', 'color']; + yield ['#000a', 'color']; + yield ['#aa', 'color']; - ['background; blue', 'style'], + yield ['background; blue', 'style']; - ['1 123 4424', 'phone'], + yield ['1 123 4424', 'phone']; - ['htt:/bluebox.org', 'uri'], - ['.relative:path/reference/', 'uri'], - ['', 'uri'], - ['//bluebox.org', 'uri'], - ['/absolutePathReference/', 'uri'], - ['./relativePathReference/', 'uri'], - ['./relative:PathReference/', 'uri'], - ['relativePathReference/', 'uri'], - ['relative/Path:Reference/', 'uri'], + yield ['htt:/bluebox.org', 'uri']; + yield ['.relative:path/reference/', 'uri']; + yield ['', 'uri']; + yield ['//bluebox.org', 'uri']; + yield ['/absolutePathReference/', 'uri']; + yield ['./relativePathReference/', 'uri']; + yield ['./relative:PathReference/', 'uri']; + yield ['relativePathReference/', 'uri']; + yield ['relative/Path:Reference/', 'uri']; - ['info@somewhere', 'email'], + yield ['info@somewhere', 'email']; - ['256.2.2.2', 'ip-address'], + yield ['256.2.2.2', 'ip-address']; - [':::ff', 'ipv6'], + yield [':::ff', 'ipv6']; - ['@localhost', 'host-name'], - ['..nohost', 'host-name'], - ]; + yield ['@localhost', 'host-name']; + yield ['..nohost', 'host-name']; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ "counter": "10" }', - '{ - "type": "object", - "properties": { - "counter": { - "type": "string", - "format": "regex", - "pattern": "[0-9]+" - } + yield [ + '{ "counter": "10" }', + '{ + "type": "object", + "properties": { + "counter": { + "type": "string", + "format": "regex", + "pattern": "[0-9]+" } - }'], + } + }' ]; } - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ "counter": "blue" }', - '{ - "type": "object", - "properties": { - "counter": { - "type": "string", - "format": "regex", - "pattern": "[0-9]+" - } + yield [ + '{ "counter": "blue" }', + '{ + "type": "object", + "properties": { + "counter": { + "type": "string", + "format": "regex", + "pattern": "[0-9]+" } - }' - ], - [ - '{ "color": "blueberry" }', - '{ - "type": "object", - "properties": { - "color": { - "type": "string", - "format": "color" - } + } + }' + ]; + yield [ + '{ "color": "blueberry" }', + '{ + "type": "object", + "properties": { + "color": { + "type": "string", + "format": "color" } - }' - ] + } + }' ]; } } From bc4e582afa720cb656c0bb1d17cf8e7e9f665334 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:40:52 +0200 Subject: [PATCH 032/114] docs: remove file level reference to license --- tests/Constraints/FormatTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 4b836304..b8a5b8ae 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -1,11 +1,5 @@ Date: Wed, 11 Jun 2025 20:41:03 +0200 Subject: [PATCH 033/114] refactor: add missing type hints --- tests/Constraints/FormatTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index b8a5b8ae..9d2288a0 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -9,6 +9,7 @@ class FormatTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function setUp(): void From da6d83b2460c9aa0225242d17b446888f99eb399 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:42:42 +0200 Subject: [PATCH 034/114] refactor: apply generator to min items max items test --- tests/Constraints/MinItemsMaxItemsTest.php | 148 ++++++++++----------- 1 file changed, 72 insertions(+), 76 deletions(-) diff --git a/tests/Constraints/MinItemsMaxItemsTest.php b/tests/Constraints/MinItemsMaxItemsTest.php index df6f0c75..185ba113 100644 --- a/tests/Constraints/MinItemsMaxItemsTest.php +++ b/tests/Constraints/MinItemsMaxItemsTest.php @@ -15,87 +15,83 @@ class MinItemsMaxItemsTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - 'Input violating minItems constraint' => [ - 'input' => '{ - "value":[2] - }', - 'schema' => '{ - "type":"object", - "properties":{ - "value":{"type":"array","minItems":2,"maxItems":4} - } - }', - 'checkMode' => Constraint::CHECK_MODE_NORMAL, - [[ - 'property' => 'value', - 'pointer' => '/value', - 'message' => 'There must be a minimum of 2 items in the array, 1 found', - 'constraint' => [ - 'name' => 'minItems', - 'params' => [ - 'minItems' => 2, - 'found' => 1 - ] - ], - 'context' => 1 - ]] - ], - 'Input violating maxItems constraint' => [ - 'input' => '{ - "value":[2,2,5,8,5] - }', - 'schema' => '{ - "type":"object", - "properties":{ - "value":{"type":"array","minItems":2,"maxItems":4} - } - }', - 'checkMode' => Constraint::CHECK_MODE_NORMAL, - [[ - 'property' => 'value', - 'pointer' => '/value', - 'message' => 'There must be a maximum of 4 items in the array, 5 found', - 'constraint' => [ - 'name' => 'maxItems', - 'params' => [ - 'maxItems' => 4, - 'found' => 5 - ] - ], - 'context' => 1 - ]] - ] + yield 'Input violating minItems constraint' => [ + 'input' => '{ + "value":[2] + }', + 'schema' => '{ + "type":"object", + "properties":{ + "value":{"type":"array","minItems":2,"maxItems":4} + } + }', + 'checkMode' => Constraint::CHECK_MODE_NORMAL, + [[ + 'property' => 'value', + 'pointer' => '/value', + 'message' => 'There must be a minimum of 2 items in the array, 1 found', + 'constraint' => [ + 'name' => 'minItems', + 'params' => [ + 'minItems' => 2, + 'found' => 1 + ] + ], + 'context' => 1 + ]] + ]; + yield 'Input violating maxItems constraint' => [ + 'input' => '{ + "value":[2,2,5,8,5] + }', + 'schema' => '{ + "type":"object", + "properties":{ + "value":{"type":"array","minItems":2,"maxItems":4} + } + }', + 'checkMode' => Constraint::CHECK_MODE_NORMAL, + [[ + 'property' => 'value', + 'pointer' => '/value', + 'message' => 'There must be a maximum of 4 items in the array, 5 found', + 'constraint' => [ + 'name' => 'maxItems', + 'params' => [ + 'maxItems' => 4, + 'found' => 5 + ] + ], + 'context' => 1 + ]] ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":[2,2] - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"array","minItems":2,"maxItems":4} - } - }' - ], - [ - '{ - "value":[2,2,5,8] - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"array","minItems":2,"maxItems":4} - } - }' - ] + yield [ + '{ + "value":[2,2] + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"array","minItems":2,"maxItems":4} + } + }' + ]; + yield [ + '{ + "value":[2,2,5,8] + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"array","minItems":2,"maxItems":4} + } + }' ]; } } From 757b0ee92f869341369a2a386e7eafffb8fccdc2 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 11 Jun 2025 20:43:20 +0200 Subject: [PATCH 035/114] docs: remove file level reference to license --- tests/Constraints/MinItemsMaxItemsTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/MinItemsMaxItemsTest.php b/tests/Constraints/MinItemsMaxItemsTest.php index 185ba113..86eaa99c 100644 --- a/tests/Constraints/MinItemsMaxItemsTest.php +++ b/tests/Constraints/MinItemsMaxItemsTest.php @@ -1,12 +1,5 @@ Date: Wed, 11 Jun 2025 20:43:35 +0200 Subject: [PATCH 036/114] refactor: add missing type hints --- tests/Constraints/MinItemsMaxItemsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/MinItemsMaxItemsTest.php b/tests/Constraints/MinItemsMaxItemsTest.php index 86eaa99c..4bb4d68f 100644 --- a/tests/Constraints/MinItemsMaxItemsTest.php +++ b/tests/Constraints/MinItemsMaxItemsTest.php @@ -6,6 +6,7 @@ class MinItemsMaxItemsTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 6467bae54c39ade61dbdb3261956ed2b31425883 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:24:12 +0200 Subject: [PATCH 037/114] refactor: apply generator to min length max length multibyte test --- .../MinLengthMaxLengthMultiByteTest.php | 92 +++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index ab6db1a3..636d3c2d 100644 --- a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php +++ b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php @@ -20,59 +20,55 @@ protected function setUp(): void } } - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":"☀" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ], - [ - '{ - "value":"☀☁☂☃☺" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ] + yield [ + '{ + "value":"☀" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' + ]; + yield [ + '{ + "value":"☀☁☂☃☺" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":"☀☁" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ], - [ - '{ - "value":"☀☁☂☃" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ] + yield [ + '{ + "value":"☀☁" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' + ]; + yield [ + '{ + "value":"☀☁☂☃" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' ]; } } From c5993f6917263fb246d777ebe9f03691c537eba9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:24:39 +0200 Subject: [PATCH 038/114] docs: remove file level reference to license --- tests/Constraints/MinLengthMaxLengthMultiByteTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index 636d3c2d..4fbaafac 100644 --- a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php +++ b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php @@ -1,12 +1,5 @@ Date: Fri, 13 Jun 2025 14:24:54 +0200 Subject: [PATCH 039/114] refactor: add missing type hints --- tests/Constraints/MinLengthMaxLengthMultiByteTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php index 4fbaafac..fc49bfde 100644 --- a/tests/Constraints/MinLengthMaxLengthMultiByteTest.php +++ b/tests/Constraints/MinLengthMaxLengthMultiByteTest.php @@ -4,6 +4,7 @@ class MinLengthMaxLengthMultiByteTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; protected function setUp(): void From fcddb1a511331a0af5e18db3525b5e2d61d48fd1 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:26:56 +0200 Subject: [PATCH 040/114] refactor: apply generator to min length max length test --- tests/Constraints/MinLengthMaxLengthTest.php | 92 ++++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/tests/Constraints/MinLengthMaxLengthTest.php b/tests/Constraints/MinLengthMaxLengthTest.php index 4832dfd5..3ac931b8 100644 --- a/tests/Constraints/MinLengthMaxLengthTest.php +++ b/tests/Constraints/MinLengthMaxLengthTest.php @@ -13,59 +13,55 @@ class MinLengthMaxLengthTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":"w" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ], - [ - '{ - "value":"wo7us" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ] + yield [ + '{ + "value":"w" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' + ]; + yield [ + '{ + "value":"wo7us" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":"wo" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ], - [ - '{ - "value":"wo7u" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","minLength":2,"maxLength":4} - } - }' - ], + yield [ + '{ + "value":"wo" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' + ]; + yield [ + '{ + "value":"wo7u" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","minLength":2,"maxLength":4} + } + }' ]; } } From c70a4c06d9713ddf728b34a9f429b2d3e57f3803 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:27:16 +0200 Subject: [PATCH 041/114] docs: remove file header reference to license --- tests/Constraints/MinLengthMaxLengthTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/MinLengthMaxLengthTest.php b/tests/Constraints/MinLengthMaxLengthTest.php index 3ac931b8..d622526a 100644 --- a/tests/Constraints/MinLengthMaxLengthTest.php +++ b/tests/Constraints/MinLengthMaxLengthTest.php @@ -1,12 +1,5 @@ Date: Fri, 13 Jun 2025 14:27:31 +0200 Subject: [PATCH 042/114] refactor: add missing type hints --- tests/Constraints/MinLengthMaxLengthTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/MinLengthMaxLengthTest.php b/tests/Constraints/MinLengthMaxLengthTest.php index d622526a..29600ac0 100644 --- a/tests/Constraints/MinLengthMaxLengthTest.php +++ b/tests/Constraints/MinLengthMaxLengthTest.php @@ -4,6 +4,7 @@ class MinLengthMaxLengthTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 732709817f6f6599e9a22664c92711ca4555aec5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:32:03 +0200 Subject: [PATCH 043/114] refactor: apply generator in min max properties test --- tests/Constraints/MinMaxPropertiesTest.php | 242 ++++++++++----------- 1 file changed, 116 insertions(+), 126 deletions(-) diff --git a/tests/Constraints/MinMaxPropertiesTest.php b/tests/Constraints/MinMaxPropertiesTest.php index 2de94329..55bf1371 100644 --- a/tests/Constraints/MinMaxPropertiesTest.php +++ b/tests/Constraints/MinMaxPropertiesTest.php @@ -15,137 +15,127 @@ class MinMaxPropertiesTest extends BaseTestCase { protected $validateSchema = true; - /** - * {@inheritdoc} - */ - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - 'Empty object with minProperties: 0' => [ - 'input' => '{ - "value": {} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "minProperties": 0} - } - }' - ], - 'Empty object with maxProperties: 1' => [ - 'input' => '{ - "value": {} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "maxProperties": 1} - } - }' - ], - 'Empty object with minProperties: 0 and maxProperties: 1' => [ - 'input' => '{ - "value": {} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "minProperties": 0,"maxProperties": 1} - } - }' - ], - 'Object with two properties with minProperties: 1 and maxProperties: 2' => [ - 'input' => '{ - "value": {"foo": 1, "bar": 2} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "minProperties": 1,"maxProperties": 2} - } - }' - ], - 'Empty array with minProperties: 1 and maxProperties: 2' => [ - 'input' => '{ - "value": [] - }', - 'schema' => '{ - "properties": { - "value": {"minProperties": 1,"maxProperties": 2} - } - }', - 'checkMode' => Constraint::CHECK_MODE_NORMAL, - ], - 'Array with two items with maxProperties: 1' => [ - 'input' => '{ - "value": [1, 2] - }', - 'schema' => '{ - "properties": { - "value": {"maxProperties": 1} - } - }' - ], + yield 'Empty object with minProperties: 0' => [ + 'input' => '{ + "value": {} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "minProperties": 0} + } + }' + ]; + yield 'Empty object with maxProperties: 1' => [ + 'input' => '{ + "value": {} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "maxProperties": 1} + } + }' + ]; + yield 'Empty object with minProperties: 0 and maxProperties: 1' => [ + 'input' => '{ + "value": {} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "minProperties": 0,"maxProperties": 1} + } + }' + ]; + yield 'Object with two properties with minProperties: 1 and maxProperties: 2' => [ + 'input' => '{ + "value": {"foo": 1, "bar": 2} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "minProperties": 1,"maxProperties": 2} + } + }' + ]; + yield 'Empty array with minProperties: 1 and maxProperties: 2' => [ + 'input' => '{ + "value": [] + }', + 'schema' => '{ + "properties": { + "value": {"minProperties": 1,"maxProperties": 2} + } + }', + 'checkMode' => Constraint::CHECK_MODE_NORMAL, + ]; + yield 'Array with two items with maxProperties: 1' => [ + 'input' => '{ + "value": [1, 2] + }', + 'schema' => '{ + "properties": { + "value": {"maxProperties": 1} + } + }' ]; } - /** - * {@inheritdoc} - */ - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - 'Empty object with minProperties: 1' => [ - 'input' => '{ - "value": {} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "minProperties": 1} - } - }' - ], - 'Empty object with minProperties' => [ - 'input' => '{}', - 'schema' => '{ - "type": "object", - "properties": { - "propertyOne": { - "type": "string" - }, - "propertyTwo": { - "type": "string" - } - }, - "minProperties": 1 - }' - ], - 'Object with two properties with maxProperties: 1' => [ - 'input' => '{ - "value": { - "propertyOne": "valueOne", - "propertyTwo": "valueTwo" - } - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "maxProperties": 1} - } - }' - ], - 'Object with two properties with minProperties: 1 and maxProperties: 2' => [ - 'input' => '{ - "value": {"foo": 1, "bar": 2, "baz": 3} - }', - 'schema' => '{ - "type": "object", - "properties": { - "value": {"type": "object", "minProperties": 1,"maxProperties": 2} - } - }' - ], + yield 'Empty object with minProperties: 1' => [ + 'input' => '{ + "value": {} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "minProperties": 1} + } + }' + ]; + yield 'Empty object with minProperties' => [ + 'input' => '{}', + 'schema' => '{ + "type": "object", + "properties": { + "propertyOne": { + "type": "string" + }, + "propertyTwo": { + "type": "string" + } + }, + "minProperties": 1 + }' + ]; + yield 'Object with two properties with maxProperties: 1' => [ + 'input' => '{ + "value": { + "propertyOne": "valueOne", + "propertyTwo": "valueTwo" + } + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "maxProperties": 1} + } + }' + ]; + yield 'Object with two properties with minProperties: 1 and maxProperties: 2' => [ + 'input' => '{ + "value": {"foo": 1, "bar": 2, "baz": 3} + }', + 'schema' => '{ + "type": "object", + "properties": { + "value": {"type": "object", "minProperties": 1,"maxProperties": 2} + } + }' ]; } } From 24687adf3ae645438bd9b5dd4e7747432fdcb64f Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:32:18 +0200 Subject: [PATCH 044/114] docs: remove file header refernec to license --- tests/Constraints/MinMaxPropertiesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/MinMaxPropertiesTest.php b/tests/Constraints/MinMaxPropertiesTest.php index 55bf1371..fad21951 100644 --- a/tests/Constraints/MinMaxPropertiesTest.php +++ b/tests/Constraints/MinMaxPropertiesTest.php @@ -1,12 +1,5 @@ Date: Fri, 13 Jun 2025 14:32:29 +0200 Subject: [PATCH 045/114] refactor: add missing type hints --- tests/Constraints/MinMaxPropertiesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/MinMaxPropertiesTest.php b/tests/Constraints/MinMaxPropertiesTest.php index fad21951..39598571 100644 --- a/tests/Constraints/MinMaxPropertiesTest.php +++ b/tests/Constraints/MinMaxPropertiesTest.php @@ -6,6 +6,7 @@ class MinMaxPropertiesTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getValidTests(): \Generator From 1ed5d555cb037ce9b3e6fbffe7ae3dd5094aaa8e Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:35:19 +0200 Subject: [PATCH 046/114] refactor: apply generator to minimum maximum tests --- tests/Constraints/MinimumMaximumTest.php | 302 +++++++++++------------ 1 file changed, 149 insertions(+), 153 deletions(-) diff --git a/tests/Constraints/MinimumMaximumTest.php b/tests/Constraints/MinimumMaximumTest.php index 6f66565b..a946ba5d 100644 --- a/tests/Constraints/MinimumMaximumTest.php +++ b/tests/Constraints/MinimumMaximumTest.php @@ -13,164 +13,160 @@ class MinimumMaximumTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":2 - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","minimum":4} - } - }' - ], - [ - '{"value": 3}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "minimum": 3, "exclusiveMinimum": true} - } - }' - ], - [ - '{ - "value":16 - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","maximum":8} - } - }' - ], - [ - '{"value": 8}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "maximum": 8, "exclusiveMaximum": true} - } - }' - ], - [ - '{"value": 4}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "exclusiveMinimum": true} - } - }' - ], - [ - '{"value": 4}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "exclusiveMaximum": true} - } - }' - ], - [ - '{"value": 4}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "minimum": 5, "exclusiveMinimum": false} - } - }' - ], - [ - '{"value": 4}', - '{ - "properties": { - "value": {"type": "integer", "maximum": 3, "exclusiveMaximum": false} - } - }' - ], - [ - '{"value": 0.00}', - '{ - "properties": { - "value": {"type": "number", "minimum": 0, "exclusiveMinimum": true} - } - }' - ], - [ - '{"value": 0.00}', - '{ - "properties": { - "value": {"type": "number", "maximum": 0, "exclusiveMaximum": true} - } - }' - ] + yield [ + '{ + "value":2 + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","minimum":4} + } + }' + ]; + yield [ + '{"value": 3}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "minimum": 3, "exclusiveMinimum": true} + } + }' + ]; + yield [ + '{ + "value":16 + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","maximum":8} + } + }' + ]; + yield [ + '{"value": 8}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "maximum": 8, "exclusiveMaximum": true} + } + }' + ]; + yield [ + '{"value": 4}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "exclusiveMinimum": true} + } + }' + ]; + yield [ + '{"value": 4}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "exclusiveMaximum": true} + } + }' + ]; + yield [ + '{"value": 4}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "minimum": 5, "exclusiveMinimum": false} + } + }' + ]; + yield [ + '{"value": 4}', + '{ + "properties": { + "value": {"type": "integer", "maximum": 3, "exclusiveMaximum": false} + } + }' + ]; + yield [ + '{"value": 0.00}', + '{ + "properties": { + "value": {"type": "number", "minimum": 0, "exclusiveMinimum": true} + } + }' + ]; + yield [ + '{"value": 0.00}', + '{ + "properties": { + "value": {"type": "number", "maximum": 0, "exclusiveMaximum": true} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":6 - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","minimum":4} - } - }' - ], - [ - '{ - "value":6 - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"integer","maximum":8} - } - }' - ], - [ - '{"value": 6}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "minimum": 6, "exclusiveMinimum": false} - } - }' - ], - [ - '{"value": 6}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "maximum": 6, "exclusiveMaximum": false} - } - }' - ], - [ - '{"value": 6}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "minimum": 6} - } - }' - ], - [ - '{"value": 6}', - '{ - "type": "object", - "properties": { - "value": {"type": "integer", "maximum": 6} - } - }' - ] + yield [ + '{ + "value":6 + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","minimum":4} + } + }' + ]; + yield [ + '{ + "value":6 + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"integer","maximum":8} + } + }' + ]; + yield [ + '{"value": 6}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "minimum": 6, "exclusiveMinimum": false} + } + }' + ]; + yield [ + '{"value": 6}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "maximum": 6, "exclusiveMaximum": false} + } + }' + ]; + yield [ + '{"value": 6}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "minimum": 6} + } + }' + ]; + yield [ + '{"value": 6}', + '{ + "type": "object", + "properties": { + "value": {"type": "integer", "maximum": 6} + } + }' ]; } } From 078f632e853c14b33c59775da58a8d5735a2123f Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 14:35:35 +0200 Subject: [PATCH 047/114] docs: remove file header license reference --- tests/Constraints/MinimumMaximumTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/MinimumMaximumTest.php b/tests/Constraints/MinimumMaximumTest.php index a946ba5d..416ae19a 100644 --- a/tests/Constraints/MinimumMaximumTest.php +++ b/tests/Constraints/MinimumMaximumTest.php @@ -1,12 +1,5 @@ Date: Fri, 13 Jun 2025 14:35:48 +0200 Subject: [PATCH 048/114] refactor: add missing type hints --- tests/Constraints/MinimumMaximumTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/MinimumMaximumTest.php b/tests/Constraints/MinimumMaximumTest.php index 416ae19a..c9a22d87 100644 --- a/tests/Constraints/MinimumMaximumTest.php +++ b/tests/Constraints/MinimumMaximumTest.php @@ -4,6 +4,7 @@ class MinimumMaximumTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 96f5d5284d1a64014e90f3ae5b4e65779dfcb305 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 15:53:55 +0200 Subject: [PATCH 049/114] refactor: apply generator to not test --- tests/Constraints/NotTest.php | 134 +++++++++++++++++----------------- 1 file changed, 65 insertions(+), 69 deletions(-) diff --git a/tests/Constraints/NotTest.php b/tests/Constraints/NotTest.php index 2b6b48e3..3965bbcf 100644 --- a/tests/Constraints/NotTest.php +++ b/tests/Constraints/NotTest.php @@ -13,90 +13,86 @@ class NotTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "x": [1, 2] - }', - '{ - "properties": { - "x": { - "not": { - "type": "array", - "items": {"type": "integer"}, - "minItems": 2 - } + yield [ + '{ + "x": [1, 2] + }', + '{ + "properties": { + "x": { + "not": { + "type": "array", + "items": {"type": "integer"}, + "minItems": 2 } } - }' - ], - [ // check that a missing, required property is correctly validated - '{"y": "foo"}', - '{ - "type": "object", - "required": ["x"], - "properties": { - "x": { - "not": { - "type": "null" - } + } + }' + ]; + yield 'check that a missing, required property is correctly validated' => [ + '{"y": "foo"}', + '{ + "type": "object", + "required": ["x"], + "properties": { + "x": { + "not": { + "type": "null" } } - }' - ] + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "x": [1] - }', - '{ - "properties": { - "x": { - "not": { - "type": "array", - "items": {"type": "integer"}, - "minItems": 2 - } + yield [ + '{ + "x": [1] + }', + '{ + "properties": { + "x": { + "not": { + "type": "array", + "items": {"type": "integer"}, + "minItems": 2 } } - }' - ], - [ - '{ - "x": ["foo", 2] - }', - '{ - "properties": { - "x": { - "not": { - "type": "array", - "items": {"type": "integer"}, - "minItems": 2 - } + } + }' + ]; + yield [ + '{ + "x": ["foo", 2] + }', + '{ + "properties": { + "x": { + "not": { + "type": "array", + "items": {"type": "integer"}, + "minItems": 2 } } - }' - ], - [ // check that a missing, non-required property isn't validated - '{"y": "foo"}', - '{ - "type": "object", - "properties": { - "x": { - "not": { - "type": "null" - } + } + }' + ]; + yield "check that a missing, non-required property isn't validated" => [ + '{"y": "foo"}', + '{ + "type": "object", + "properties": { + "x": { + "not": { + "type": "null" } } - }' - ] + } + }' ]; } } From b3396146e7d2099705a45165b4213f7648286c7c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 15:54:14 +0200 Subject: [PATCH 050/114] docs: remove file header license reference --- tests/Constraints/NotTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/NotTest.php b/tests/Constraints/NotTest.php index 3965bbcf..0defa0f9 100644 --- a/tests/Constraints/NotTest.php +++ b/tests/Constraints/NotTest.php @@ -1,12 +1,5 @@ Date: Fri, 13 Jun 2025 15:54:26 +0200 Subject: [PATCH 051/114] refactor: add missing type hints --- tests/Constraints/NotTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/NotTest.php b/tests/Constraints/NotTest.php index 0defa0f9..30525101 100644 --- a/tests/Constraints/NotTest.php +++ b/tests/Constraints/NotTest.php @@ -4,6 +4,7 @@ class NotTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From cb34328827666caf77eda21aaabbd66c2751d939 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 15:56:34 +0200 Subject: [PATCH 052/114] refactor: apply generator to number and integer types test --- .../Constraints/NumberAndIntegerTypesTest.php | 182 +++++++++--------- 1 file changed, 89 insertions(+), 93 deletions(-) diff --git a/tests/Constraints/NumberAndIntegerTypesTest.php b/tests/Constraints/NumberAndIntegerTypesTest.php index 78b02110..7f3fc366 100644 --- a/tests/Constraints/NumberAndIntegerTypesTest.php +++ b/tests/Constraints/NumberAndIntegerTypesTest.php @@ -13,106 +13,102 @@ class NumberAndIntegerTypesTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "integer": 1.4 - }', - '{ - "type":"object", - "properties":{ - "integer":{"type":"integer"} - } - }' - ], - [ - '{"integer": 1.001}', - '{ - "type": "object", - "properties": { - "integer": {"type": "integer"} - } - }' - ], - [ - '{"integer": true}', - '{ - "type": "object", - "properties": { - "integer": {"type": "integer"} - } - }' - ], - [ - '{"number": "x"}', - '{ - "type": "object", - "properties": { - "number": {"type": "number"} - } - }' - ] + yield [ + '{ + "integer": 1.4 + }', + '{ + "type":"object", + "properties":{ + "integer":{"type":"integer"} + } + }' + ]; + yield [ + '{"integer": 1.001}', + '{ + "type": "object", + "properties": { + "integer": {"type": "integer"} + } + }' + ]; + yield [ + '{"integer": true}', + '{ + "type": "object", + "properties": { + "integer": {"type": "integer"} + } + }' + ]; + yield [ + '{"number": "x"}', + '{ + "type": "object", + "properties": { + "number": {"type": "number"} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "integer": 1 - }', - '{ - "type":"object", - "properties":{ - "integer":{"type":"integer"} - } - }' - ], - [ - '{ - "number": 1.4 - }', - '{ - "type":"object", - "properties":{ - "number":{"type":"number"} - } - }' - ], - [ - '{"number": 1e5}', - '{ - "type": "object", - "properties": { - "number": {"type": "number"} - } - }' - ], - [ - '{"number": 1}', - '{ - "type": "object", - "properties": { - "number": {"type": "number"} + yield [ + '{ + "integer": 1 + }', + '{ + "type":"object", + "properties":{ + "integer":{"type":"integer"} + } + }' + ]; + yield [ + '{ + "number": 1.4 + }', + '{ + "type":"object", + "properties":{ + "number":{"type":"number"} + } + }' + ]; + yield [ + '{"number": 1e5}', + '{ + "type": "object", + "properties": { + "number": {"type": "number"} + } + }' + ]; + yield [ + '{"number": 1}', + '{ + "type": "object", + "properties": { + "number": {"type": "number"} + } + }' + ]; + yield [ + '{"number": -49.89}', + '{ + "type": "object", + "properties": { + "number": { + "type": "number", + "multipleOf": 0.01 } - }' - ], - [ - '{"number": -49.89}', - '{ - "type": "object", - "properties": { - "number": { - "type": "number", - "multipleOf": 0.01 - } - } - }' - ] + } + }' ]; } } From 707a02a953bdab4d1e909417a97ed9849e95dae0 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 15:56:53 +0200 Subject: [PATCH 053/114] docs: remove file header license reference --- tests/Constraints/NumberAndIntegerTypesTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Constraints/NumberAndIntegerTypesTest.php b/tests/Constraints/NumberAndIntegerTypesTest.php index 7f3fc366..096beba5 100644 --- a/tests/Constraints/NumberAndIntegerTypesTest.php +++ b/tests/Constraints/NumberAndIntegerTypesTest.php @@ -1,11 +1,5 @@ Date: Fri, 13 Jun 2025 15:57:09 +0200 Subject: [PATCH 054/114] refactor: add missing type hints --- tests/Constraints/NumberAndIntegerTypesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/NumberAndIntegerTypesTest.php b/tests/Constraints/NumberAndIntegerTypesTest.php index 096beba5..ac09fec7 100644 --- a/tests/Constraints/NumberAndIntegerTypesTest.php +++ b/tests/Constraints/NumberAndIntegerTypesTest.php @@ -5,6 +5,7 @@ class NumberAndIntegerTypesTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From ed86bca87f784f41563525b684a4aab88034976e Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 16:04:07 +0200 Subject: [PATCH 055/114] refactor: apply generator to of properties test --- tests/Constraints/OfPropertiesTest.php | 382 ++++++++++++------------- 1 file changed, 189 insertions(+), 193 deletions(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index b602c0b4..37fd5f66 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -18,217 +18,213 @@ class OfPropertiesTest extends BaseTestCase { protected $validateSchema = true; - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{"prop1": "abc"}', - '{ - "type": "object", - "properties": { - "prop1": {"type": "string"}, - "prop2": { - "oneOf": [ - {"type": "number"}, - {"type": "string"} - ] - } - }, - "required": ["prop1"] - }' - ], - [ - '{"prop1": "abc", "prop2": 23}', - '{ - "type": "object", - "properties": { - "prop1": {"type": "string"}, - "prop2": { - "oneOf": [ - {"type": "number"}, - {"type": "string"} - ] - } - }, - "required": ["prop1"] - }' - ], + yield [ + '{"prop1": "abc"}', + '{ + "type": "object", + "properties": { + "prop1": {"type": "string"}, + "prop2": { + "oneOf": [ + {"type": "number"}, + {"type": "string"} + ] + } + }, + "required": ["prop1"] + }' + ]; + yield [ + '{"prop1": "abc", "prop2": 23}', + '{ + "type": "object", + "properties": { + "prop1": {"type": "string"}, + "prop2": { + "oneOf": [ + {"type": "number"}, + {"type": "string"} + ] + } + }, + "required": ["prop1"] + }' ]; } - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ + yield [ + '{"prop1": "abc", "prop2": []}', + '{ + "type": "object", + "properties": { + "prop1": {"type": "string"}, + "prop2": { + "oneOf": [ + {"type": "number"}, + {"type": "string"} + ] + } + }, + "required": ["prop1"] + }', + null, [ - '{"prop1": "abc", "prop2": []}', - '{ - "type": "object", - "properties": { - "prop1": {"type": "string"}, - "prop2": { - "oneOf": [ - {"type": "number"}, - {"type": "string"} - ] - } - }, - "required": ["prop1"] - }', - null, [ - [ - 'property' => 'prop2', - 'pointer' => '/prop2', - 'message' => 'Array value found, but a string is required', - 'constraint' => [ - 'name' => 'type', - 'params' => [ - 'expected' => 'a string', - 'found' => 'array' - ] - ], - 'context' => Validator::ERROR_DOCUMENT_VALIDATION + 'property' => 'prop2', + 'pointer' => '/prop2', + 'message' => 'Array value found, but a string is required', + 'constraint' => [ + 'name' => 'type', + 'params' => [ + 'expected' => 'a string', + 'found' => 'array' + ] ], - [ - 'property' => 'prop2', - 'pointer' => '/prop2', - 'message' => 'Array value found, but a number is required', - 'constraint' => [ - 'name' => 'type', - 'params' => [ - 'expected' => 'a number', - 'found' => 'array' - ] - ], - 'context' => Validator::ERROR_DOCUMENT_VALIDATION + 'context' => Validator::ERROR_DOCUMENT_VALIDATION + ], + [ + 'property' => 'prop2', + 'pointer' => '/prop2', + 'message' => 'Array value found, but a number is required', + 'constraint' => [ + 'name' => 'type', + 'params' => [ + 'expected' => 'a number', + 'found' => 'array' + ] ], - [ - 'property' => 'prop2', - 'pointer' => '/prop2', - 'message' => 'Failed to match exactly one schema', - 'constraint' => [ - 'name' => 'oneOf', - 'params' => [] - ], - 'context' => Validator::ERROR_DOCUMENT_VALIDATION + 'context' => Validator::ERROR_DOCUMENT_VALIDATION + ], + [ + 'property' => 'prop2', + 'pointer' => '/prop2', + 'message' => 'Failed to match exactly one schema', + 'constraint' => [ + 'name' => 'oneOf', + 'params' => [] ], + 'context' => Validator::ERROR_DOCUMENT_VALIDATION ], ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "oneOf": [ - { - "type": "string", - "pattern": "^[a-z]*$" - }, - { - "type": "string", - "pattern": "^[A-Z]*$" - } - ] + ]; + yield [ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "oneOf": [ + { + "type": "string", + "pattern": "^[a-z]*$" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" } - } - }' - ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "string", - "pattern": "^[A-Z]*$" - } - ] + ] + } + } + }' + ]; + yield [ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string", + "pattern": "^[A-Z]*$" } - } - }' - ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string", - "pattern": "^[A-Z]*$" - } - ] + ] + } + } + }' + ]; + yield[ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" } - } - }' - ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "string", - "pattern": "^[A-Z]*$" - } - ] + ] + } + } + }' + ]; + yield[ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" } - } - }' - ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "string", - "pattern": "^[a-z]*$" - }, - { - "type": "string", - "pattern": "^[A-Z]*$" - } - ] + ] + } + } + }' + ]; + yield[ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string", + "pattern": "^[a-z]*$" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" } - } - }' - ], - [ - '{"prop1": [1,2]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "type": "string" - } - ] + ] + } + } + }' + ]; + yield [ + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "string" } - } - }' - ] + ] + } + } + }' ]; } From d7cee657b5c6db3f0ff07a63c10c2c14d47e3528 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 16:04:51 +0200 Subject: [PATCH 056/114] docs: remove file header license reference --- tests/Constraints/OfPropertiesTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 37fd5f66..70c4f5fb 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -1,10 +1,4 @@ Date: Fri, 13 Jun 2025 16:05:07 +0200 Subject: [PATCH 057/114] docs: remvoe class phpdoc --- tests/Constraints/OfPropertiesTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 70c4f5fb..025bb5c4 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -5,9 +5,6 @@ use JsonSchema\Constraints\Constraint; use JsonSchema\Validator; -/** - * Class OfPropertiesTest - */ class OfPropertiesTest extends BaseTestCase { protected $validateSchema = true; From e36febcee096fd77364fc08119b46e9506d3aba8 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 16:05:20 +0200 Subject: [PATCH 058/114] refactor: add missing type hints --- tests/Constraints/OfPropertiesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 025bb5c4..12ba6a2c 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -7,6 +7,7 @@ class OfPropertiesTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getValidTests(): \Generator From 2e447a3eb21ce6a1c7d90ecc58d34e5ef9b68859 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 13 Jun 2025 16:05:38 +0200 Subject: [PATCH 059/114] refactor: enforce cast to object --- tests/Constraints/OfPropertiesTest.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 12ba6a2c..65700930 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -222,7 +222,8 @@ public function getInvalidTests(): \Generator public function testNoPrematureAnyOfException(): void { - $schema = json_decode('{ + $schema = json_decode( + '{ "type": "object", "properties": { "propertyOne": { @@ -232,8 +233,10 @@ public function testNoPrematureAnyOfException(): void ] } } - }'); - $data = json_decode('{"propertyOne":"ABC"}'); + }', + false + ); + $data = json_decode('{"propertyOne":"ABC"}', false); $v = new Validator(); $v->validate($data, $schema, Constraint::CHECK_MODE_EXCEPTIONS); @@ -242,7 +245,8 @@ public function testNoPrematureAnyOfException(): void public function testNoPrematureOneOfException(): void { - $schema = json_decode('{ + $schema = json_decode( + '{ "type": "object", "properties": { "propertyOne": { @@ -252,8 +256,10 @@ public function testNoPrematureOneOfException(): void ] } } - }'); - $data = json_decode('{"propertyOne":"ABC"}'); + }', + false + ); + $data = json_decode('{"propertyOne":"ABC"}', false); $v = new Validator(); $v->validate($data, $schema, Constraint::CHECK_MODE_EXCEPTIONS); From 0999413fb1e3260a36254cc85abf588f02696f22 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:25:04 +0200 Subject: [PATCH 060/114] refactor: add missing type hint --- tests/Constraints/PatternPropertiesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/PatternPropertiesTest.php b/tests/Constraints/PatternPropertiesTest.php index 526777ef..17d62168 100644 --- a/tests/Constraints/PatternPropertiesTest.php +++ b/tests/Constraints/PatternPropertiesTest.php @@ -11,6 +11,7 @@ class PatternPropertiesTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): array From 960003616392ca280b98fea8db9841219a97e878 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:25:26 +0200 Subject: [PATCH 061/114] refactor: apply generator to pattern properties test --- tests/Constraints/PatternPropertiesTest.php | 340 ++++++++++---------- 1 file changed, 165 insertions(+), 175 deletions(-) diff --git a/tests/Constraints/PatternPropertiesTest.php b/tests/Constraints/PatternPropertiesTest.php index 17d62168..363a3856 100644 --- a/tests/Constraints/PatternPropertiesTest.php +++ b/tests/Constraints/PatternPropertiesTest.php @@ -14,202 +14,192 @@ class PatternPropertiesTest extends BaseTestCase /** @var bool */ protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - // matches pattern but invalid schema for object - [ - json_encode([ - 'someobject' => [ - 'foobar' => 'foo', - 'barfoo' => 'bar', - ] - ]), - json_encode([ - 'type' => 'object', - 'patternProperties' => [ - '^someobject$' => [ - 'type' => 'object', - 'additionalProperties' => false, - 'properties' => [ - 'barfoo' => [ - 'type' => 'string', - ], - ] + yield 'matches pattern but invalid schema for object' => [ + json_encode([ + 'someobject' => [ + 'foobar' => 'foo', + 'barfoo' => 'bar', + ] + ]), + json_encode([ + 'type' => 'object', + 'patternProperties' => [ + '^someobject$' => [ + 'type' => 'object', + 'additionalProperties' => false, + 'properties' => [ + 'barfoo' => [ + 'type' => 'string', + ], ] ] - ]) - ], - // Does not match pattern - [ - json_encode([ - 'regex_us' => false, - ]), - json_encode([ - 'type' => 'object', - 'patternProperties' => [ - '^[a-z]+_(jp|de)$' => [ - 'type' => ['boolean'] - ] - ], - 'additionalProperties' => false - ]) - ], - // Does not match pattern with unicode - [ - json_encode([ - '猡猡獛' => false, - ]), - json_encode([ - 'type' => 'object', - 'patternProperties' => [ - '^[\\x{0080}-\\x{006FFF}]+$' => [ - 'type' => ['boolean'] - ] - ], - 'additionalProperties' => false - ]) - ], - // An invalid regular expression pattern - [ - json_encode([ - 'regex_us' => false, - ]), - json_encode([ - 'type' => 'object', - 'patternProperties' => [ - '^[a-z+_jp|de)$' => [ - 'type' => ['boolean'] - ] - ], - 'additionalProperties' => false - ]) - ], + ] + ]) + ]; + yield 'Does not match pattern' => [ + json_encode([ + 'regex_us' => false, + ]), + json_encode([ + 'type' => 'object', + 'patternProperties' => [ + '^[a-z]+_(jp|de)$' => [ + 'type' => ['boolean'] + ] + ], + 'additionalProperties' => false + ]) + ]; + yield 'Does not match pattern with unicode' => [ + json_encode([ + '猡猡獛' => false, + ]), + json_encode([ + 'type' => 'object', + 'patternProperties' => [ + '^[\\x{0080}-\\x{006FFF}]+$' => [ + 'type' => ['boolean'] + ] + ], + 'additionalProperties' => false + ]) + ]; + yield 'An invalid regular expression pattern' => [ + json_encode([ + 'regex_us' => false, + ]), + json_encode([ + 'type' => 'object', + 'patternProperties' => [ + '^[a-z+_jp|de)$' => [ + 'type' => ['boolean'] + ] + ], + 'additionalProperties' => false + ]) ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - // validates pattern schema - json_encode([ - 'someobject' => [ - 'foobar' => 'foo', - 'barfoo' => 'bar', - ], - 'someotherobject' => [ - 'foobar' => 1234, + [ + yield 'validates pattern schema' => json_encode([ + 'someobject' => [ + 'foobar' => 'foo', + 'barfoo' => 'bar', + ], + 'someotherobject' => [ + 'foobar' => 1234, + ], + '/products' => [ + 'get' => [] + ], + '#products' => [ + 'get' => [] + ], + '+products' => [ + 'get' => [] + ], + '~products' => [ + 'get' => [] + ], + '*products' => [ + 'get' => [] + ], + '%products' => [ + 'get' => [] + ] + ]), + json_encode([ + 'type' => 'object', + 'additionalProperties' => false, + 'patternProperties' => [ + '^someobject$' => [ + 'type' => 'object', + 'properties' => [ + 'foobar' => ['type' => 'string'], + 'barfoo' => ['type' => 'string'], + ], ], - '/products' => [ - 'get' => [] + '^someotherobject$' => [ + 'type' => 'object', + 'properties' => [ + 'foobar' => ['type' => 'number'], + ], ], - '#products' => [ - 'get' => [] + '^/' => [ + 'type' => 'object', + 'properties' => [ + 'get' => ['type' => 'array'] + ] ], - '+products' => [ - 'get' => [] + '^#' => [ + 'type' => 'object', + 'properties' => [ + 'get' => ['type' => 'array'] + ] ], - '~products' => [ - 'get' => [] + '^\+' => [ + 'type' => 'object', + 'properties' => [ + 'get' => ['type' => 'array'] + ] ], - '*products' => [ - 'get' => [] + '^~' => [ + 'type' => 'object', + 'properties' => [ + 'get' => ['type' => 'array'] + ] ], - '%products' => [ - 'get' => [] - ] - ]), - json_encode([ - 'type' => 'object', - 'additionalProperties' => false, - 'patternProperties' => [ - '^someobject$' => [ - 'type' => 'object', - 'properties' => [ - 'foobar' => ['type' => 'string'], - 'barfoo' => ['type' => 'string'], - ], - ], - '^someotherobject$' => [ - 'type' => 'object', - 'properties' => [ - 'foobar' => ['type' => 'number'], - ], - ], - '^/' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] - ], - '^#' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] - ], - '^\+' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] - ], - '^~' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] - ], - '^\*' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] - ], - '^%' => [ - 'type' => 'object', - 'properties' => [ - 'get' => ['type' => 'array'] - ] + '^\*' => [ + 'type' => 'object', + 'properties' => [ + 'get' => ['type' => 'array'] ] - ] - ]) - ], - [ - json_encode([ - 'foobar' => true, - 'regex_us' => 'foo', - 'regex_de' => 1234 - ]), - json_encode([ + ], + '^%' => [ 'type' => 'object', 'properties' => [ - 'foobar' => ['type' => 'boolean'] - ], - 'patternProperties' => [ - '^[a-z]+_(us|de)$' => [ - 'type' => ['string', 'integer'] - ] - ], - 'additionalProperties' => false - ]) - ], - // Does match pattern with unicode - [ - json_encode([ - 'ðæſ' => 'unicode', - ]), - json_encode([ + 'get' => ['type' => 'array'] + ] + ] + ] + ]) + ]; + yield [ + json_encode([ + 'foobar' => true, + 'regex_us' => 'foo', + 'regex_de' => 1234 + ]), + json_encode([ 'type' => 'object', + 'properties' => [ + 'foobar' => ['type' => 'boolean'] + ], 'patternProperties' => [ - '^[\\x{0080}-\\x{10FFFF}]+$' => [ - 'type' => ['string'] + '^[a-z]+_(us|de)$' => [ + 'type' => ['string', 'integer'] ] ], 'additionalProperties' => false - ]) - ], + ]) + ]; + yield 'Does match pattern with unicode' => [ + json_encode([ + 'ðæſ' => 'unicode', + ]), + json_encode([ + 'type' => 'object', + 'patternProperties' => [ + '^[\\x{0080}-\\x{10FFFF}]+$' => [ + 'type' => ['string'] + ] + ], + 'additionalProperties' => false + ]) ]; } } From aaf40ecf1b37eb913f5a4ad6979be4091207c220 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:25:43 +0200 Subject: [PATCH 062/114] docs: remove file header with reference to license --- tests/Constraints/PatternPropertiesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/PatternPropertiesTest.php b/tests/Constraints/PatternPropertiesTest.php index 363a3856..4bcb987d 100644 --- a/tests/Constraints/PatternPropertiesTest.php +++ b/tests/Constraints/PatternPropertiesTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 14:28:07 +0200 Subject: [PATCH 063/114] refactor: apply generator to pattern test --- tests/Constraints/PatternTest.php | 156 +++++++++++++++--------------- 1 file changed, 76 insertions(+), 80 deletions(-) diff --git a/tests/Constraints/PatternTest.php b/tests/Constraints/PatternTest.php index 8207c91b..b00e290e 100644 --- a/tests/Constraints/PatternTest.php +++ b/tests/Constraints/PatternTest.php @@ -13,91 +13,87 @@ class PatternTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "value":"Abacates" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","pattern":"^cat"} - }, - "additionalProperties":false - }' - ], - [ - '{"value": "abc"}', - '{ - "type": "object", - "properties": { - "value": {"type": "string", "pattern": "^a*$"} - }, - "additionalProperties": false - }' - ], - [ - '{"value": "ü"}', - '{ - "type": "object", - "properties": { - "value": {"type": "string", "pattern": "^ü$"} - }, - "additionalProperties": false - }' - ], + yield [ + '{ + "value":"Abacates" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","pattern":"^cat"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{"value": "abc"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^a*$"} + }, + "additionalProperties": false + }' + ]; + yield [ + '{"value": "ü"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^ü$"} + }, + "additionalProperties": false + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "value":"Abacates" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","pattern":"tes$"} - }, - "additionalProperties":false - }' - ], - [ - '{ - "value":"Abacates" - }', - '{ - "type":"object", - "properties":{ - "value":{"type":"string","pattern":"cat"} - }, - "additionalProperties":false - }' - ], - [ - '{"value": "aaa"}', - '{ - "type": "object", - "properties": { - "value": {"type": "string", "pattern": "^a*$"} - }, - "additionalProperties": false - }' - ], - [ - '{"value": "↓æ→"}', - '{ - "type": "object", - "properties": { - "value": {"type": "string", "pattern": "^↓æ.$"} - }, - "additionalProperties": false - }' - ] + yield [ + '{ + "value":"Abacates" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","pattern":"tes$"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{ + "value":"Abacates" + }', + '{ + "type":"object", + "properties":{ + "value":{"type":"string","pattern":"cat"} + }, + "additionalProperties":false + }' + ]; + yield [ + '{"value": "aaa"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^a*$"} + }, + "additionalProperties": false + }' + ]; + yield [ + '{"value": "↓æ→"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^↓æ.$"} + }, + "additionalProperties": false + }' ]; } } From 91a7a8d287b24b11447e2ff0d139ae3888491ae5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:28:24 +0200 Subject: [PATCH 064/114] docs: remove file header with license reference --- tests/Constraints/PatternTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/PatternTest.php b/tests/Constraints/PatternTest.php index b00e290e..f038b4ba 100644 --- a/tests/Constraints/PatternTest.php +++ b/tests/Constraints/PatternTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 14:28:36 +0200 Subject: [PATCH 065/114] refactor: add missing type hint --- tests/Constraints/PatternTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/PatternTest.php b/tests/Constraints/PatternTest.php index f038b4ba..de527215 100644 --- a/tests/Constraints/PatternTest.php +++ b/tests/Constraints/PatternTest.php @@ -4,6 +4,7 @@ class PatternTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 9fede1fc125d832a91b0b29d2aaaf220ef87a712 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:32:56 +0200 Subject: [PATCH 066/114] refactor: apply generator to read only test --- tests/Constraints/ReadOnlyTest.php | 45 +++++++++++++----------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/tests/Constraints/ReadOnlyTest.php b/tests/Constraints/ReadOnlyTest.php index 3a54fa51..e29aeee8 100644 --- a/tests/Constraints/ReadOnlyTest.php +++ b/tests/Constraints/ReadOnlyTest.php @@ -13,36 +13,31 @@ class ReadOnlyTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - //is readonly really required? - return [ - [ - '{ "number": [] }', - '{ - "type":"object", - "properties":{ - "number":{"type":"string","readonly":true} - } - }' - ] + yield 'is readonly really required?' => [ + '{ "number": [] }', + '{ + "type":"object", + "properties":{ + "number":{"type":"string","readonly":true} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "number": "1.4" - }', - '{ - "type":"object", - "properties":{ - "number":{"type":"string","readonly":true} - } - }' - ] + yield [ + '{ + "number": "1.4" + }', + '{ + "type":"object", + "properties":{ + "number":{"type":"string","readonly":true} + } + }' ]; } } From f3e06886ee789467d7ee46aec918dc380aaffd90 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:33:40 +0200 Subject: [PATCH 067/114] docs: remove file header with license reference --- tests/Constraints/ReadOnlyTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/ReadOnlyTest.php b/tests/Constraints/ReadOnlyTest.php index e29aeee8..9570fc9f 100644 --- a/tests/Constraints/ReadOnlyTest.php +++ b/tests/Constraints/ReadOnlyTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 14:33:59 +0200 Subject: [PATCH 068/114] refactor: add missing type hint --- tests/Constraints/ReadOnlyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/ReadOnlyTest.php b/tests/Constraints/ReadOnlyTest.php index 9570fc9f..af46730e 100644 --- a/tests/Constraints/ReadOnlyTest.php +++ b/tests/Constraints/ReadOnlyTest.php @@ -4,6 +4,7 @@ class ReadOnlyTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 51e52c61bfd2c7f6728e76a741482175a870a5d9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:36:34 +0200 Subject: [PATCH 069/114] refactor: apply generator to require test --- tests/Constraints/RequireTest.php | 54 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/tests/Constraints/RequireTest.php b/tests/Constraints/RequireTest.php index 34ca88ca..e56ac09a 100644 --- a/tests/Constraints/RequireTest.php +++ b/tests/Constraints/RequireTest.php @@ -13,40 +13,36 @@ class RequireTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "state":"DF" - }', - '{ - "type":"object", - "properties":{ - "state":{"type":"string","requires":"city"}, - "city":{"type":"string"} - } - }' - ] + yield [ + '{ + "state":"DF" + }', + '{ + "type":"object", + "properties":{ + "state":{"type":"string","requires":"city"}, + "city":{"type":"string"} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "state":"DF", - "city":"Brasília" - }', - '{ - "type":"object", - "properties":{ - "state":{"type":"string","requires":"city"}, - "city":{"type":"string"} - } - }' - ] + yield [ + '{ + "state":"DF", + "city":"Brasília" + }', + '{ + "type":"object", + "properties":{ + "state":{"type":"string","requires":"city"}, + "city":{"type":"string"} + } + }' ]; } } From 0416fffcfb51772f376ababd5e1f87a0f6deb6e4 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:36:51 +0200 Subject: [PATCH 070/114] docs: remove file header with license reference --- tests/Constraints/RequireTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/RequireTest.php b/tests/Constraints/RequireTest.php index e56ac09a..c0652485 100644 --- a/tests/Constraints/RequireTest.php +++ b/tests/Constraints/RequireTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 14:37:15 +0200 Subject: [PATCH 071/114] refactor: add missing type hint --- tests/Constraints/RequireTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/RequireTest.php b/tests/Constraints/RequireTest.php index c0652485..0ced6e32 100644 --- a/tests/Constraints/RequireTest.php +++ b/tests/Constraints/RequireTest.php @@ -4,6 +4,7 @@ class RequireTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 11e9afa096a8795457734de19d365816b90f3ddd Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:46:30 +0200 Subject: [PATCH 072/114] refactor: add generator to require property test --- tests/Constraints/RequiredPropertyTest.php | 608 ++++++++++----------- 1 file changed, 302 insertions(+), 306 deletions(-) diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index 2f38c3e5..b77b6e03 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -113,329 +113,325 @@ protected function assertErrorHasExpectedPropertyValue($error, $propertyValue): $this->assertEquals($propertyValue, $error[0]['property']); } - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{}', - '{ - "type":"object", - "properties":{ - "number":{"type":"number","required":true} - } - }' - ], - [ - '{}', - '{ - "type": "object", - "properties": { - "number": {"type": "number"} - }, - "required": ["number"] - }' - ], - [ - '{ - "foo": {} - }', - '{ - "type": "object", - "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number"} - }, - "required": ["bar"] - } - } - }' - ], - [ - '{ - "bar": 1.4 - }', - '{ - "type": "object", - "properties": { - "foo": {"type": "string", "required": true}, - "bar": {"type": "number"} - }, - "required": ["bar"] - }' - ], - [ - '{}', - '{ - "required": ["foo"] - }' - ], - [ - '{ - }', - '{ - "type": "object", - "properties": { - "foo": { "required": true } + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "number":{"type":"number","required":true} + } + }' + ]; + yield [ + '{}', + '{ + "type": "object", + "properties": { + "number": {"type": "number"} + }, + "required": ["number"] + }' + ]; + yield [ + '{ + "foo": {} + }', + '{ + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": {"type": "number"} + }, + "required": ["bar"] } - }' - ], - [ - '{ - "string":{} - }', - '{ - "type":"object", - "properties": { - "string":{"type":"string", "required": true} - } - }' - ], - [ - '{ - "number":{} - }', - '{ - "type":"object", - "properties": { - "number":{"type":"number", "required": true} - } - }' - ], - [ - '{ - "integer":{} - }', - '{ - "type":"object", - "properties": { - "integer":{"type":"integer", "required": true} - } - }' - ], - [ - '{ - "boolean":{} - }', - '{ - "type":"object", - "properties": { - "boolean":{"type":"boolean", "required": true} - } - }' - ], - [ - '{ - "array":{} - }', - '{ - "type":"object", - "properties": { - "array":{"type":"array", "required": true} - } - }', - Constraint::CHECK_MODE_NORMAL - ], - [ - '{ - "null":{} - }', - '{ - "type":"object", - "properties": { - "null":{"type":"null", "required": true} - } - }' - ], - [ - '{ - "foo": {"baz": 1.5} - }', - '{ + } + }' + ]; + yield [ + '{ + "bar": 1.4 + }', + '{ + "type": "object", + "properties": { + "foo": {"type": "string", "required": true}, + "bar": {"type": "number"} + }, + "required": ["bar"] + }' + ]; + yield [ + '{}', + '{ + "required": ["foo"] + }' + ]; + yield [ + '{ + }', + '{ + "type": "object", + "properties": { + "foo": { "required": true } + } + }' + ]; + yield [ + '{ + "string":{} + }', + '{ + "type":"object", + "properties": { + "string":{"type":"string", "required": true} + } + }' + ]; + yield [ + '{ + "number":{} + }', + '{ + "type":"object", + "properties": { + "number":{"type":"number", "required": true} + } + }' + ]; + yield [ + '{ + "integer":{} + }', + '{ + "type":"object", + "properties": { + "integer":{"type":"integer", "required": true} + } + }' + ]; + yield [ + '{ + "boolean":{} + }', + '{ + "type":"object", + "properties": { + "boolean":{"type":"boolean", "required": true} + } + }' + ]; + yield [ + '{ + "array":{} + }', + '{ + "type":"object", + "properties": { + "array":{"type":"array", "required": true} + } + }', + Constraint::CHECK_MODE_NORMAL + ]; + yield [ + '{ + "null":{} + }', + '{ + "type":"object", + "properties": { + "null":{"type":"null", "required": true} + } + }' + ]; + yield [ + '{ + "foo": {"baz": 1.5} + }', + '{ + "type": "object", + "properties": { + "foo": { "type": "object", "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number"} - }, - "required": ["bar"] - } - } - }' - ], - [ - '{ - "foo": {"baz": 1.5} - }', - '{ + "bar": {"type": "number"} + }, + "required": ["bar"] + } + } + }' + ]; + yield [ + '{ + "foo": {"baz": 1.5} + }', + '{ + "type": "object", + "properties": { + "foo": { "type": "object", "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number", "required": true} - } - } + "bar": {"type": "number", "required": true} } - }' - ], + } + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "number": 1.4 - }', - '{ - "type":"object", - "properties":{ - "number":{"type":"number","required":true} - } - }' - ], - [ - '{}', - '{ - "type":"object", - "properties":{ - "number":{"type":"number"} - } - }' - ], - [ - '{}', - '{ - "type":"object", - "properties":{ - "number":{"type":"number","required":false} - } - }' - ], - [ - '{ - "number": 0 - }', - '{ - "type":"object", - "properties":{ - "number":{"type":"integer","required":true} - } - }' - ], - [ - '{ - "is_active": false - }', - '{ - "type":"object", - "properties":{ - "is_active":{"type":"boolean","required":true} - } - }' - ], - [ - '{ - "status": null - }', - '{ - "type":"object", - "properties":{ - "status":{"type":"null","required":true} - } - }' - ], - [ - '{ - "users": [] - }', - '{ - "type":"object", - "properties":{ - "users":{"type":"array","required":true} - } - }' - ], - [ - '{ - "foo": "foo", - "bar": 1.4 - }', - '{ - "type": "object", - "properties": { - "foo": {"type": "string", "required": true}, - "bar": {"type": "number"} - }, - "required": ["bar"] - }' - ], - [ - '{ - "foo": {"bar": 1.5} - }', - '{ - "type": "object", - "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number"} - }, - "required": ["bar"] - } - }, - "required": ["foo"] - }' - ], - [ - '{ - "foo": {} - }', - '{ - "type": "object", - "properties": { - "foo": { "required": true } + yield [ + '{ + "number": 1.4 + }', + '{ + "type":"object", + "properties":{ + "number":{"type":"number","required":true} + } + }' + ]; + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "number":{"type":"number"} + } + }' + ]; + yield [ + '{}', + '{ + "type":"object", + "properties":{ + "number":{"type":"number","required":false} + } + }' + ]; + yield [ + '{ + "number": 0 + }', + '{ + "type":"object", + "properties":{ + "number":{"type":"integer","required":true} + } + }' + ]; + yield [ + '{ + "is_active": false + }', + '{ + "type":"object", + "properties":{ + "is_active":{"type":"boolean","required":true} + } + }' + ]; + yield [ + '{ + "status": null + }', + '{ + "type":"object", + "properties":{ + "status":{"type":"null","required":true} + } + }' + ]; + yield [ + '{ + "users": [] + }', + '{ + "type":"object", + "properties":{ + "users":{"type":"array","required":true} + } + }' + ]; + yield [ + '{ + "foo": "foo", + "bar": 1.4 + }', + '{ + "type": "object", + "properties": { + "foo": {"type": "string", "required": true}, + "bar": {"type": "number"} + }, + "required": ["bar"] + }' + ]; + yield [ + '{ + "foo": {"bar": 1.5} + }', + '{ + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": {"type": "number"} + }, + "required": ["bar"] } - }' - ], - [ - '{ - "boo": {"bar": 1.5} - }', - '{ + }, + "required": ["foo"] + }' + ]; + yield [ + '{ + "foo": {} + }', + '{ + "type": "object", + "properties": { + "foo": { "required": true } + } + }' + ]; + yield [ + '{ + "boo": {"bar": 1.5} + }', + '{ + "type": "object", + "properties": { + "foo": { "type": "object", "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number"} - }, - "required": ["bar"] - } - } - }' - ], - [ - '{ - "boo": {"bar": 1.5} - }', - '{ + "bar": {"type": "number"} + }, + "required": ["bar"] + } + } + }' + ]; + yield [ + '{ + "boo": {"bar": 1.5} + }', + '{ + "type": "object", + "properties": { + "foo": { "type": "object", "properties": { - "foo": { - "type": "object", - "properties": { - "bar": {"type": "number", "required": true} - } - } + "bar": {"type": "number", "required": true} } - }' - ], + } + } + }' ]; } } From a83c5751b4fb2443e374e684e274b5f075cfedec Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:46:50 +0200 Subject: [PATCH 073/114] docs: remove file header with license reference --- tests/Constraints/RequiredPropertyTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index b77b6e03..72402bd7 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 14:47:32 +0200 Subject: [PATCH 074/114] refactor: add missing type hints --- tests/Constraints/RequiredPropertyTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index 72402bd7..cda131f8 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -7,10 +7,15 @@ class RequiredPropertyTest extends BaseTestCase { - // Most tests are draft-03 compliant, but some tests are draft-04, or mix draft-03 and - // draft-04 syntax within the same schema. Unfortunately, draft-03 and draft-04 required - // definitions are incompatible, so disabling schema validation for these tests. + /** + * Most tests are draft-03 compliant, but some tests are draft-04, or mix draft-03 and + * draft-04 syntax within the same schema. Unfortunately, draft-03 and draft-04 required + * definitions are incompatible, so disabling schema validation for these tests. + * + * @var string + * */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = false; public function testErrorPropertyIsPopulatedForRequiredIfMissingInInput(): void From eb0169ca086941a47720029643af1ce54e1d503a Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 14:47:47 +0200 Subject: [PATCH 075/114] refactor: cleanup remaining test cases --- tests/Constraints/RequiredPropertyTest.php | 52 +++++++++------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index cda131f8..6f2ef260 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -21,20 +21,17 @@ class RequiredPropertyTest extends BaseTestCase public function testErrorPropertyIsPopulatedForRequiredIfMissingInInput(): void { $validator = new UndefinedConstraint(); - $document = json_decode( - '{ - "bar": 42 - }' - ); + $document = json_decode('{ "bar": 42 }', false); $schema = json_decode( '{ - "type": "object", - "properties": { - "foo": {"type": "number"}, - "bar": {"type": "number"} - }, - "required": ["foo"] - }' + "type": "object", + "properties": { + "foo": {"type": "number"}, + "bar": {"type": "number"} + }, + "required": ["foo"] + }', + false ); $validator->check($document, $schema); @@ -45,11 +42,7 @@ public function testErrorPropertyIsPopulatedForRequiredIfMissingInInput(): void public function testPathErrorPropertyIsPopulatedForRequiredIfMissingInInput(): void { $validator = new UndefinedConstraint(); - $document = json_decode( - '{ - "foo": [{"baz": 1.5}] - }' - ); + $document = json_decode('{ "foo": [{"baz": 1.5}] }', false); $schema = json_decode( '{ "type": "object", @@ -67,7 +60,8 @@ public function testPathErrorPropertyIsPopulatedForRequiredIfMissingInInput(): v } }, "required": ["foo"] - }' + }', + false ); $validator->check($document, $schema); @@ -78,21 +72,17 @@ public function testPathErrorPropertyIsPopulatedForRequiredIfMissingInInput(): v public function testErrorPropertyIsPopulatedForRequiredIfEmptyValueInInput(): void { $validator = new UndefinedConstraint(); - $document = json_decode( - '{ - "bar": 42, - "foo": null - }' - ); + $document = json_decode('{ "bar": 42, "foo": null }', false); $schema = json_decode( '{ - "type": "object", - "properties": { - "foo": {"type": "number"}, - "bar": {"type": "number"} - }, - "required": ["foo"] - }' + "type": "object", + "properties": { + "foo": {"type": "number"}, + "bar": {"type": "number"} + }, + "required": ["foo"] + }', + false ); $validator->check($document, $schema); From aa242ffd4723fa37601365f3eda8233db9ed7984 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:39:32 +0200 Subject: [PATCH 076/114] refactor: remove redundant property --- tests/Constraints/RequiredPropertyTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index 6f2ef260..54abc3e8 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -15,8 +15,6 @@ class RequiredPropertyTest extends BaseTestCase * @var string * */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; - /** @var bool */ - protected $validateSchema = false; public function testErrorPropertyIsPopulatedForRequiredIfMissingInInput(): void { From 4b94c84e11b572a1aa41737c223951b8357beaa9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:43:12 +0200 Subject: [PATCH 077/114] refactor: apply generator to self defined schema test --- tests/Constraints/SelfDefinedSchemaTest.php | 80 ++++++++++----------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 4ac1b8a7..c05132e0 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -15,55 +15,51 @@ class SelfDefinedSchemaTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "$schema": { - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "name": { - "type": "string" - }, - "age" : { - "type": "integer", - "maximum": 25 - } + yield [ + '{ + "$schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "properties": { + "name": { + "type": "string" + }, + "age" : { + "type": "integer", + "maximum": 25 } - }, - "name" : "John Doe", - "age" : 30, - "type" : "object" - }', - '' - ] + } + }, + "name" : "John Doe", + "age" : 30, + "type" : "object" + }', + '' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "$schema": { - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "name": { - "type": "string" - }, - "age" : { - "type": "integer", - "maximum": 125 - } + yield [ + '{ + "$schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "properties": { + "name": { + "type": "string" + }, + "age" : { + "type": "integer", + "maximum": 125 } - }, - "name" : "John Doe", - "age" : 30, - "type" : "object" - }', - '' - ] + } + }, + "name" : "John Doe", + "age" : 30, + "type" : "object" + }', + '' ]; } From 4487c60303e4d54e6fbf06962930f15517538bf0 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:43:32 +0200 Subject: [PATCH 078/114] docs: remove file header with llicense reference --- tests/Constraints/SelfDefinedSchemaTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index c05132e0..6fcc9292 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 15:43:48 +0200 Subject: [PATCH 079/114] refactor: add missing type hint --- tests/Constraints/SelfDefinedSchemaTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 6fcc9292..2da256fd 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -6,6 +6,7 @@ class SelfDefinedSchemaTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 2a64607a239df76ebdfad01bc074e63ad7e9afa9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:44:02 +0200 Subject: [PATCH 080/114] refactor: update remaining tests case --- tests/Constraints/SelfDefinedSchemaTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index 2da256fd..2d4e8c42 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -3,6 +3,8 @@ namespace JsonSchema\Tests\Constraints; use JsonSchema\Validator; +use JsonSchema\Exception\InvalidArgumentException; +use stdClass; class SelfDefinedSchemaTest extends BaseTestCase { @@ -59,12 +61,12 @@ public function getValidTests(): \Generator public function testInvalidArgumentException(): void { - $value = json_decode('{}'); - $schema = json_decode(''); + $value = new stdClass(); + $schema = null; $v = new Validator(); - $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $v->validate($value, $schema); } From 67af72195a2fa6f1103cb6228f695e5174ea9c3c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:45:59 +0200 Subject: [PATCH 081/114] refactor: apply generator to tuple typing test --- tests/Constraints/TupleTypingTest.php | 226 +++++++++++++------------- 1 file changed, 111 insertions(+), 115 deletions(-) diff --git a/tests/Constraints/TupleTypingTest.php b/tests/Constraints/TupleTypingTest.php index f565ae00..bc182654 100644 --- a/tests/Constraints/TupleTypingTest.php +++ b/tests/Constraints/TupleTypingTest.php @@ -13,128 +13,124 @@ class TupleTypingTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "tupleTyping":[2,"a"] - }', - '{ - "type":"object", - "properties":{ - "tupleTyping":{ - "type":"array", - "items":[ - {"type":"string"}, - {"type":"number"} - ] - } - } - }' - ], - [ - '{ - "tupleTyping":["2",2,true] - }', - '{ - "type":"object", - "properties":{ - "tupleTyping":{ - "type":"array", - "items":[ - {"type":"string"}, - {"type":"number"} - ] , - "additionalItems":false - } - } - }' - ], - [ - '{ - "tupleTyping":["2",2,3] - }', - '{ - "type":"object", - "properties":{ - "tupleTyping":{ - "type":"array", - "items":[ - {"type":"string"}, - {"type":"number"} - ] , - "additionalItems":{"type":"string"} - } - } - }' - ], - [ - '{"data": [1, "foo", true, 1.5]}', - '{ - "type": "object", - "properties": { - "data": { - "type": "array", - "items": [{}, {}, {}], - "additionalItems": false - } + yield [ + '{ + "tupleTyping":[2,"a"] + }', + '{ + "type":"object", + "properties":{ + "tupleTyping":{ + "type":"array", + "items":[ + {"type":"string"}, + {"type":"number"} + ] + } + } + }' + ]; + yield [ + '{ + "tupleTyping":["2",2,true] + }', + '{ + "type":"object", + "properties":{ + "tupleTyping":{ + "type":"array", + "items":[ + {"type":"string"}, + {"type":"number"} + ] , + "additionalItems":false + } + } + }' + ]; + yield [ + '{ + "tupleTyping":["2",2,3] + }', + '{ + "type":"object", + "properties":{ + "tupleTyping":{ + "type":"array", + "items":[ + {"type":"string"}, + {"type":"number"} + ] , + "additionalItems":{"type":"string"} + } + } + }' + ]; + yield [ + '{"data": [1, "foo", true, 1.5]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": [{}, {}, {}], + "additionalItems": false } - }' - ] + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "tupleTyping":["2", 1] - }', - '{ - "type":"object", - "properties":{ - "tupleTyping":{ - "type":"array", - "items":[ - {"type":"string"}, - {"type":"number"} - ] - } - } - }' - ], - [ - '{ - "tupleTyping":["2",2,3] - }', - '{ - "type":"object", - "properties":{ - "tupleTyping":{ - "type":"array", - "items":[ - {"type":"string"}, - {"type":"number"} - ] - } - } - }' - ], - [ - '{"data": [1, "foo", true]}', - '{ - "type": "object", - "properties": { - "data": { - "type": "array", - "items": [{}, {}, {}], - "additionalItems": false - } + yield [ + '{ + "tupleTyping":["2", 1] + }', + '{ + "type":"object", + "properties":{ + "tupleTyping":{ + "type":"array", + "items":[ + {"type":"string"}, + {"type":"number"} + ] + } + } + }' + ]; + yield [ + '{ + "tupleTyping":["2",2,3] + }', + '{ + "type":"object", + "properties":{ + "tupleTyping":{ + "type":"array", + "items":[ + {"type":"string"}, + {"type":"number"} + ] + } + } + }' + ]; + yield [ + '{"data": [1, "foo", true]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": [{}, {}, {}], + "additionalItems": false } - }' - ] + } + }' ]; } } From fcf18b7f2158f467d9f3629cf90f1acc42e766d5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 15:46:14 +0200 Subject: [PATCH 082/114] docs: remove file header with license reference --- tests/Constraints/TupleTypingTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/TupleTypingTest.php b/tests/Constraints/TupleTypingTest.php index bc182654..44a5b911 100644 --- a/tests/Constraints/TupleTypingTest.php +++ b/tests/Constraints/TupleTypingTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 15:46:26 +0200 Subject: [PATCH 083/114] refactor: add missing type hint --- tests/Constraints/TupleTypingTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/TupleTypingTest.php b/tests/Constraints/TupleTypingTest.php index 44a5b911..721bbdaa 100644 --- a/tests/Constraints/TupleTypingTest.php +++ b/tests/Constraints/TupleTypingTest.php @@ -4,6 +4,7 @@ class TupleTypingTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 838c7e118b8ca8411fa18cf162f79bd54eb12678 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:04:11 +0200 Subject: [PATCH 084/114] refactor: apply generator to undefined constraint test --- tests/Constraints/UndefinedConstraintTest.php | 168 ++++++++---------- 1 file changed, 76 insertions(+), 92 deletions(-) diff --git a/tests/Constraints/UndefinedConstraintTest.php b/tests/Constraints/UndefinedConstraintTest.php index 7e66a60b..d07eed77 100644 --- a/tests/Constraints/UndefinedConstraintTest.php +++ b/tests/Constraints/UndefinedConstraintTest.php @@ -8,21 +8,12 @@ class UndefinedConstraintTest extends BaseTestCase { - /** - * @return array{} - */ - public function getInvalidTests(): array - { - return []; - } + public function getInvalidTests(): \Generator + {} - /** - * @return array - */ - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - 'oneOf with type coercion should not affect value passed to each sub schema (#790)' => [ + yield 'oneOf with type coercion should not affect value passed to each sub schema (#790)' => [ 'input' => << << Constraint::CHECK_MODE_COERCE_TYPES - ], - 'oneOf with apply defaults should not affect value passed to each sub schema (#510)' => [ - 'input' => << << Constraint::CHECK_MODE_COERCE_TYPES + ]; + yield 'oneOf with apply defaults should not affect value passed to each sub schema (#510)' => [ + 'input' => << << Constraint::CHECK_MODE_APPLY_DEFAULTS - ], - 'anyOf with apply defaults should not affect value passed to each sub schema (#711)' => [ - 'input' => << << Constraint::CHECK_MODE_APPLY_DEFAULTS + ]; + yield 'anyOf with apply defaults should not affect value passed to each sub schema (#711)' => [ + 'input' => << << Constraint::CHECK_MODE_APPLY_DEFAULTS - ] +JSON, + 'checkMode' => Constraint::CHECK_MODE_APPLY_DEFAULTS ]; } } From 98d6103904a4fb89c5ae94f20da163a59a4f5027 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:06:12 +0200 Subject: [PATCH 085/114] refactor: apply generator to union types test --- tests/Constraints/UnionTypesTest.php | 56 +++++++++++++--------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/tests/Constraints/UnionTypesTest.php b/tests/Constraints/UnionTypesTest.php index 387848df..c107826d 100644 --- a/tests/Constraints/UnionTypesTest.php +++ b/tests/Constraints/UnionTypesTest.php @@ -13,41 +13,37 @@ class UnionTypesTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":4.8, - "booleanOrNull":5 - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":4.8, + "booleanOrNull":5 + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":4.8, - "booleanOrNull":false - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":4.8, + "booleanOrNull":false + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } } From 704c3b68d03492032b8dd2562ff8c09167a64c82 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:06:32 +0200 Subject: [PATCH 086/114] docs: remove file header with license reference --- tests/Constraints/UnionTypesTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/UnionTypesTest.php b/tests/Constraints/UnionTypesTest.php index c107826d..8aaeca3b 100644 --- a/tests/Constraints/UnionTypesTest.php +++ b/tests/Constraints/UnionTypesTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 16:06:50 +0200 Subject: [PATCH 087/114] refactor: add missing type hints --- tests/Constraints/UnionTypesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/UnionTypesTest.php b/tests/Constraints/UnionTypesTest.php index 8aaeca3b..f39aa667 100644 --- a/tests/Constraints/UnionTypesTest.php +++ b/tests/Constraints/UnionTypesTest.php @@ -4,6 +4,7 @@ class UnionTypesTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 30c40b7b651fcbd8b94b6f6c33d6e46644a83e5d Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:08:25 +0200 Subject: [PATCH 088/114] refactor: apply generator to union with null value test --- tests/Constraints/UnionWithNullValueTest.php | 56 +++++++++----------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/tests/Constraints/UnionWithNullValueTest.php b/tests/Constraints/UnionWithNullValueTest.php index 16d2d8b2..d8c60c9c 100644 --- a/tests/Constraints/UnionWithNullValueTest.php +++ b/tests/Constraints/UnionWithNullValueTest.php @@ -13,41 +13,37 @@ class UnionWithNullValueTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":null, - "booleanOrNull":null - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":null, + "booleanOrNull":null + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":12, - "booleanOrNull":null - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":12, + "booleanOrNull":null + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } } From 8ba7f73d27d4ab2c9230e912504a6aa05d45d4e6 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:08:42 +0200 Subject: [PATCH 089/114] docs: remove file header with license reference --- tests/Constraints/UnionWithNullValueTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/UnionWithNullValueTest.php b/tests/Constraints/UnionWithNullValueTest.php index d8c60c9c..83f1295d 100644 --- a/tests/Constraints/UnionWithNullValueTest.php +++ b/tests/Constraints/UnionWithNullValueTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 16:08:54 +0200 Subject: [PATCH 090/114] refactor: add missing type hint --- tests/Constraints/UnionWithNullValueTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/UnionWithNullValueTest.php b/tests/Constraints/UnionWithNullValueTest.php index 83f1295d..cd0cbb91 100644 --- a/tests/Constraints/UnionWithNullValueTest.php +++ b/tests/Constraints/UnionWithNullValueTest.php @@ -4,6 +4,7 @@ class UnionWithNullValueTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From e5cd0e70c7c2ff524f829ce27a728d62f84e2f2b Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:12:34 +0200 Subject: [PATCH 091/114] refactor: apply generator to unique items test --- tests/Constraints/UniqueItemsTest.php | 282 +++++++++++++------------- 1 file changed, 139 insertions(+), 143 deletions(-) diff --git a/tests/Constraints/UniqueItemsTest.php b/tests/Constraints/UniqueItemsTest.php index 0badfe1d..4adc5c8c 100644 --- a/tests/Constraints/UniqueItemsTest.php +++ b/tests/Constraints/UniqueItemsTest.php @@ -13,153 +13,149 @@ class UniqueItemsTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array - { - return [ - 'Non unique integers' => [ - 'input' => '[1,2,2]', - 'schema' => '{ - "type":"array", - "uniqueItems": true - }' - ], - 'Non unique objects' => [ - 'input' => '[{"a":"b"},{"a":"c"},{"a":"b"}]', - 'schema' => '{ - "type":"array", - "uniqueItems": true - }' - ], - 'Non unique objects - three levels deep' => [ - 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Non unique mathematical values for the number one' => [ - 'input' => '[1.0, 1.00, 1]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Non unique arrays' => [ - 'input' => '[["foo"], ["foo"]]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Non unique mix of different types' => [ - 'input' => '[{}, [1], true, null, {}, 1]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'objects are non-unique despite key order' => [ - 'input' => '[{"a": 1, "b": 2}, {"b": 2, "a": 1}]', - 'schema' => '{"uniqueItems": true}', - ] + public function getInvalidTests(): \Generator +{ + yield 'Non unique integers' => [ + 'input' => '[1,2,2]', + 'schema' => '{ + "type":"array", + "uniqueItems": true + }' + ]; + yield 'Non unique objects' => [ + 'input' => '[{"a":"b"},{"a":"c"},{"a":"b"}]', + 'schema' => '{ + "type":"array", + "uniqueItems": true + }' + ]; + yield 'Non unique objects - three levels deep' => [ + 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Non unique mathematical values for the number one' => [ + 'input' => '[1.0, 1.00, 1]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Non unique arrays' => [ + 'input' => '[["foo"], ["foo"]]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Non unique mix of different types' => [ + 'input' => '[{}, [1], true, null, {}, 1]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'objects are non-unique despite key order' => [ + 'input' => '[{"a": 1, "b": 2}, {"b": 2, "a": 1}]', + 'schema' => '{"uniqueItems": true}', ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - 'unique integers' => [ - 'input' => '[1,2,3]', - 'schema' => '{ - "type":"array", - "uniqueItems": true - }' - ], - 'unique objects' =>[ - 'input' => '[{"foo": 12}, {"bar": false}]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Integer one and boolean true' => [ - 'input' => '[1, true]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Integer zero and boolean false' => [ - 'input' => '[0, false]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Objects with different value three levels deep' => [ - 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Array of strings' => [ - 'input' => '[["foo"], ["bar"]]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - 'Object, Array, boolean, null and integer' => [ - 'input' => '[{}, [1], true, null, 1]', - 'schema' => '{ - "type": "array", - "uniqueItems": true - }' - ], - // below equals the invalid tests, but with uniqueItems set to false - 'Non unique integers' => [ - 'input' => '[1,2,2]', - 'schema' => '{ - "type":"array", - "uniqueItems": false - }' - ], - 'Non unique objects' => [ - 'input' => '[{"a":"b"},{"a":"c"},{"a":"b"}]', - 'schema' => '{ - "type":"array", - "uniqueItems": false - }' - ], - 'Non unique objects - three levels deep' => [ - 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', - 'schema' => '{ - "type": "array", - "uniqueItems": false - }' - ], - 'Non unique mathematical values for the number one' => [ - 'input' => '[1.0, 1.00, 1]', - 'schema' => '{ - "type": "array", - "uniqueItems": false - }' - ], - 'Non unique arrays' => [ - 'input' => '[["foo"], ["foo"]]', - 'schema' => '{ - "type": "array", - "uniqueItems": false - }' - ], - 'Non unique mix of different types' => [ - 'input' => '[{}, [1], true, null, {}, 1]', - 'schema' => '{ - "type": "array", - "uniqueItems": false - }' - ] + yield 'unique integers' => [ + 'input' => '[1,2,3]', + 'schema' => '{ + "type":"array", + "uniqueItems": true + }' + ]; + yield 'unique objects' =>[ + 'input' => '[{"foo": 12}, {"bar": false}]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Integer one and boolean true' => [ + 'input' => '[1, true]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Integer zero and boolean false' => [ + 'input' => '[0, false]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Objects with different value three levels deep' => [ + 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Array of strings' => [ + 'input' => '[["foo"], ["bar"]]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + yield 'Object, Array, boolean, null and integer' => [ + 'input' => '[{}, [1], true, null, 1]', + 'schema' => '{ + "type": "array", + "uniqueItems": true + }' + ]; + // below equals the invalid tests, but with uniqueItems set to false + yield 'Non unique integers' => [ + 'input' => '[1,2,2]', + 'schema' => '{ + "type":"array", + "uniqueItems": false + }' + ]; + yield 'Non unique objects' => [ + 'input' => '[{"a":"b"},{"a":"c"},{"a":"b"}]', + 'schema' => '{ + "type":"array", + "uniqueItems": false + }' + ]; + yield 'Non unique objects - three levels deep' => [ + 'input' => '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', + 'schema' => '{ + "type": "array", + "uniqueItems": false + }' + ]; + yield 'Non unique mathematical values for the number one' => [ + 'input' => '[1.0, 1.00, 1]', + 'schema' => '{ + "type": "array", + "uniqueItems": false + }' + ]; + yield 'Non unique arrays' => [ + 'input' => '[["foo"], ["foo"]]', + 'schema' => '{ + "type": "array", + "uniqueItems": false + }' + ]; + yield 'Non unique mix of different types' => [ + 'input' => '[{}, [1], true, null, {}, 1]', + 'schema' => '{ + "type": "array", + "uniqueItems": false + }' ]; } } From da92537dbe4e030b1395e25eae60d74d31388046 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:12:55 +0200 Subject: [PATCH 092/114] docs: remove file header with license reference --- tests/Constraints/UniqueItemsTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/UniqueItemsTest.php b/tests/Constraints/UniqueItemsTest.php index 4adc5c8c..3ff94f8d 100644 --- a/tests/Constraints/UniqueItemsTest.php +++ b/tests/Constraints/UniqueItemsTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 16:13:06 +0200 Subject: [PATCH 093/114] refactor: add missing type hints --- tests/Constraints/UniqueItemsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/UniqueItemsTest.php b/tests/Constraints/UniqueItemsTest.php index 3ff94f8d..c559bbde 100644 --- a/tests/Constraints/UniqueItemsTest.php +++ b/tests/Constraints/UniqueItemsTest.php @@ -4,6 +4,7 @@ class UniqueItemsTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From 8d628d519fdbf3ab5ebcdd5fc6e54f640e5dbc4a Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:15:25 +0200 Subject: [PATCH 094/114] refactor: apply generator to wrong message failling test case test --- .../WrongMessagesFailingTestCaseTest.php | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/tests/Constraints/WrongMessagesFailingTestCaseTest.php b/tests/Constraints/WrongMessagesFailingTestCaseTest.php index e36f57ce..961ef3fa 100644 --- a/tests/Constraints/WrongMessagesFailingTestCaseTest.php +++ b/tests/Constraints/WrongMessagesFailingTestCaseTest.php @@ -13,41 +13,37 @@ class WrongMessagesFailingTestCaseTest extends BaseTestCase { protected $validateSchema = true; - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":4.8, - "booleanOrNull":["A","B"] - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":4.8, + "booleanOrNull":["A","B"] + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } - public function getValidTests(): array + public function getValidTests(): \Generator { - return [ - [ - '{ - "stringOrNumber":4.8, - "booleanOrNull":true - }', - '{ - "type":"object", - "properties":{ - "stringOrNumber":{"type":["string","number"]}, - "booleanOrNull":{"type":["boolean","null"]} - } - }' - ] + yield [ + '{ + "stringOrNumber":4.8, + "booleanOrNull":true + }', + '{ + "type":"object", + "properties":{ + "stringOrNumber":{"type":["string","number"]}, + "booleanOrNull":{"type":["boolean","null"]} + } + }' ]; } } From 17bf1552658689fd32b8b8a9d52355e0423ab1d8 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:15:44 +0200 Subject: [PATCH 095/114] docs: remove file header with license reference --- tests/Constraints/WrongMessagesFailingTestCaseTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Constraints/WrongMessagesFailingTestCaseTest.php b/tests/Constraints/WrongMessagesFailingTestCaseTest.php index 961ef3fa..f6ec1b8f 100644 --- a/tests/Constraints/WrongMessagesFailingTestCaseTest.php +++ b/tests/Constraints/WrongMessagesFailingTestCaseTest.php @@ -1,12 +1,5 @@ Date: Fri, 20 Jun 2025 16:15:56 +0200 Subject: [PATCH 096/114] refactor: add missing type hints --- tests/Constraints/WrongMessagesFailingTestCaseTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Constraints/WrongMessagesFailingTestCaseTest.php b/tests/Constraints/WrongMessagesFailingTestCaseTest.php index f6ec1b8f..5d62fe11 100644 --- a/tests/Constraints/WrongMessagesFailingTestCaseTest.php +++ b/tests/Constraints/WrongMessagesFailingTestCaseTest.php @@ -4,6 +4,7 @@ class WrongMessagesFailingTestCaseTest extends BaseTestCase { + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator From fce02678039006d6a228fd0c29b0b6a3f88d24fe Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:17:47 +0200 Subject: [PATCH 097/114] refactor: apply generator to base draft test case --- tests/Drafts/BaseDraftTestCase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Drafts/BaseDraftTestCase.php b/tests/Drafts/BaseDraftTestCase.php index 9a4d564f..f74bc85e 100644 --- a/tests/Drafts/BaseDraftTestCase.php +++ b/tests/Drafts/BaseDraftTestCase.php @@ -45,14 +45,14 @@ private function setUpTests(bool $isValid): array return $tests; } - public function getInvalidTests(): array + public function getInvalidTests(): \Generator { - return $this->setUpTests(false); + yield from $this->setUpTests(false); } - public function getValidTests(): array + public function getValidTests(): \Generator { - return $this->setUpTests(true); + yield from $this->setUpTests(true); } /** From d2acee897301d7511f3adb6858107fc42153d6c8 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Fri, 20 Jun 2025 16:27:44 +0200 Subject: [PATCH 098/114] refactor: apply generator to draft 3 test case --- tests/Drafts/Draft3Test.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index bebc6eaf..169829bd 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -81,26 +81,34 @@ protected function getFilePaths(): array ]; } - public function getInvalidForAssocTests(): array + public function getInvalidForAssocTests(): \Generator { - $tests = parent::getInvalidForAssocTests(); - unset( - $tests['type.json / object type matches objects / an array is not an object'], - $tests['type.json / array type matches arrays / an object is not an array'] - ); + $skip = [ + 'type.json / object type matches objects / an array is not an object', + 'type.json / array type matches arrays / an object is not an array', + ]; - return $tests; + foreach (parent::getInvalidForAssocTests() as $name => $testcase) { + if (in_array($name, $skip, true)) { + continue; + } + yield $name => $testcase; + } } - public function getValidForAssocTests(): array + public function getValidForAssocTests(): \Generator { - $tests = parent::getValidForAssocTests(); - unset( - $tests['type.json / object type matches objects / an array is not an object'], - $tests['type.json / array type matches arrays / an object is not an array'] - ); + $skip = [ + 'type.json / object type matches objects / an array is not an object', + 'type.json / array type matches arrays / an object is not an array', + ]; - return $tests; + foreach (parent::getValidForAssocTests() as $name => $testcase) { + if (in_array($name, $skip, true)) { + continue; + } + yield $name => $testcase; + } } /** From a8531fd95d8f9305f413bf5d5dc973b76ce525bd Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 22 Jun 2025 20:52:19 +0200 Subject: [PATCH 099/114] docs: remove file header with license reference --- tests/Drafts/Draft3Test.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index 169829bd..12346429 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -1,12 +1,5 @@ Date: Sun, 22 Jun 2025 20:52:36 +0200 Subject: [PATCH 100/114] docs: remove class docblock --- tests/Drafts/Draft3Test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index 12346429..6c845d26 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -6,9 +6,6 @@ use JsonSchema\SchemaStorage; use JsonSchema\Validator; -/** - * @package JsonSchema\Tests\Drafts - */ class Draft3Test extends BaseDraftTestCase { protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; From 7b4a61e816356c883b57eddd3b3eedf94318b209 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 22 Jun 2025 20:53:02 +0200 Subject: [PATCH 101/114] refactor: add missing type hints --- tests/Drafts/Draft3Test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index 6c845d26..7ac372c7 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -8,7 +8,9 @@ class Draft3Test extends BaseDraftTestCase { + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; + /** @var bool */ protected $validateSchema = true; /** From 2e2042e63e494c387428a418e98b24d4299d6f62 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 22 Jun 2025 20:55:31 +0200 Subject: [PATCH 102/114] refactor: apply generator to draft 4 test --- tests/Drafts/Draft4Test.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/Drafts/Draft4Test.php b/tests/Drafts/Draft4Test.php index 16c73b45..9abdf7bc 100644 --- a/tests/Drafts/Draft4Test.php +++ b/tests/Drafts/Draft4Test.php @@ -28,26 +28,34 @@ protected function getFilePaths(): array ]; } - public function getInvalidForAssocTests(): array + public function getInvalidForAssocTests(): \Generator { - $tests = parent::getInvalidForAssocTests(); - unset( - $tests['type.json / object type matches objects / an array is not an object'], - $tests['type.json / array type matches arrays / an object is not an array'] - ); + $skip = [ + 'type.json / object type matches objects / an array is not an object', + 'type.json / array type matches arrays / an object is not an array', + ]; - return $tests; + foreach (parent::getInvalidForAssocTests() as $name => $testcase) { + if (in_array($name, $skip, true)) { + continue; + } + yield $name => $testcase; + } } - public function getValidForAssocTests(): array + public function getValidForAssocTests(): \Generator { - $tests = parent::getValidForAssocTests(); - unset( - $tests['type.json / object type matches objects / an array is not an object'], - $tests['type.json / array type matches arrays / an object is not an array'] - ); + $skip = [ + 'type.json / object type matches objects / an array is not an object', + 'type.json / array type matches arrays / an object is not an array', + ]; - return $tests; + foreach (parent::getValidForAssocTests() as $name => $testcase) { + if (in_array($name, $skip, true)) { + continue; + } + yield $name => $testcase; + } } /** From 6dd9dba99bc88972727a6a5c20c30ba9d09791d0 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Sun, 22 Jun 2025 20:55:54 +0200 Subject: [PATCH 103/114] docs: remove file header with license reference --- tests/Drafts/Draft4Test.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Drafts/Draft4Test.php b/tests/Drafts/Draft4Test.php index 9abdf7bc..f9acbde3 100644 --- a/tests/Drafts/Draft4Test.php +++ b/tests/Drafts/Draft4Test.php @@ -1,12 +1,5 @@ Date: Sun, 22 Jun 2025 20:56:09 +0200 Subject: [PATCH 104/114] docs: remove class php doccblock --- tests/Drafts/Draft4Test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Drafts/Draft4Test.php b/tests/Drafts/Draft4Test.php index f9acbde3..acfb00e2 100644 --- a/tests/Drafts/Draft4Test.php +++ b/tests/Drafts/Draft4Test.php @@ -2,9 +2,6 @@ namespace JsonSchema\Tests\Drafts; -/** - * @package JsonSchema\Tests\Drafts - */ class Draft4Test extends BaseDraftTestCase { /** @var bool */ From 357c2f92b57c5b85c4dcb61c4646e204a62c8c5e Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:44:11 +0200 Subject: [PATCH 105/114] style: correct code style violations --- tests/Constraints/ArraysTest.php | 2 +- tests/Constraints/BasicTypesTest.php | 5 ++--- tests/Constraints/ConstTest.php | 4 ++-- tests/Constraints/DependenciesTest.php | 4 ++-- tests/Constraints/EnumTest.php | 4 ++-- tests/Constraints/FormatTest.php | 3 +-- tests/Constraints/NumberAndIntegerTypesTest.php | 1 - tests/Constraints/OfPropertiesTest.php | 6 +++--- tests/Constraints/SelfDefinedSchemaTest.php | 2 +- tests/Constraints/UndefinedConstraintTest.php | 5 +++-- tests/Constraints/UniqueItemsTest.php | 2 +- 11 files changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index 88b10db7..0835bc07 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -9,7 +9,7 @@ class ArraysTest extends BaseTestCase public function getInvalidTests(): \Generator { - yield [ + yield [ '{ "array":[1,2,"a"] }', diff --git a/tests/Constraints/BasicTypesTest.php b/tests/Constraints/BasicTypesTest.php index 83db96bf..05d399fa 100644 --- a/tests/Constraints/BasicTypesTest.php +++ b/tests/Constraints/BasicTypesTest.php @@ -4,14 +4,13 @@ class BasicTypesTest extends BaseTestCase { - /** @var string */ + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; - /** @var bool */ + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator { - yield [ '{ "string":null diff --git a/tests/Constraints/ConstTest.php b/tests/Constraints/ConstTest.php index 2801a96e..f0792b43 100644 --- a/tests/Constraints/ConstTest.php +++ b/tests/Constraints/ConstTest.php @@ -4,9 +4,9 @@ class ConstTest extends BaseTestCase { - /** @var string */ + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-06/schema#'; - /** @var bool */ + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator diff --git a/tests/Constraints/DependenciesTest.php b/tests/Constraints/DependenciesTest.php index 7a89ebe2..cb6027d2 100644 --- a/tests/Constraints/DependenciesTest.php +++ b/tests/Constraints/DependenciesTest.php @@ -4,9 +4,9 @@ class DependenciesTest extends BaseTestCase { - /** @var string */ + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; - /** @var bool */ + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator diff --git a/tests/Constraints/EnumTest.php b/tests/Constraints/EnumTest.php index a4752387..6b2dec18 100644 --- a/tests/Constraints/EnumTest.php +++ b/tests/Constraints/EnumTest.php @@ -4,9 +4,9 @@ class EnumTest extends BaseTestCase { - /** @var string */ + /** @var string */ protected $schemaSpec = 'http://json-schema.org/draft-03/schema#'; - /** @var bool */ + /** @var bool */ protected $validateSchema = true; public function getInvalidTests(): \Generator diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 9d2288a0..ef9dabda 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -1,6 +1,5 @@ [ + yield 'oneOf with type coercion should not affect value passed to each sub schema (#790)' => [ 'input' => << [ 'input' => '[1,2,2]', 'schema' => '{ From 4b32d8227daafc786ffce2f719e71280153846aa Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:49:10 +0200 Subject: [PATCH 106/114] refactor: add declare strict types to all tests --- tests/ConstraintErrorTest.php | 3 ++- tests/Constraints/AdditionalPropertiesTest.php | 2 ++ tests/Constraints/ArraysTest.php | 2 ++ tests/Constraints/BaseTestCase.php | 3 ++- tests/Constraints/BasicTypesTest.php | 2 ++ tests/Constraints/CoerciveTest.php | 3 ++- tests/Constraints/ConstTest.php | 2 ++ tests/Constraints/DefaultPropertiesTest.php | 3 ++- tests/Constraints/DependenciesTest.php | 2 ++ tests/Constraints/DisallowTest.php | 2 ++ tests/Constraints/DivisibleByTest.php | 2 ++ tests/Constraints/EnumTest.php | 2 ++ tests/Constraints/ExtendsTest.php | 2 ++ tests/Constraints/FormatTest.php | 2 ++ tests/Constraints/LongArraysTest.php | 3 ++- tests/Constraints/MinItemsMaxItemsTest.php | 2 ++ tests/Constraints/MinLengthMaxLengthMultiByteTest.php | 2 ++ tests/Constraints/MinLengthMaxLengthTest.php | 2 ++ tests/Constraints/MinMaxPropertiesTest.php | 2 ++ tests/Constraints/MinimumMaximumTest.php | 2 ++ tests/Constraints/NotTest.php | 2 ++ tests/Constraints/NumberAndIntegerTypesTest.php | 2 ++ tests/Constraints/OfPropertiesTest.php | 2 ++ tests/Constraints/PatternPropertiesTest.php | 2 ++ tests/Constraints/PatternTest.php | 2 ++ tests/Constraints/PointerTest.php | 3 ++- tests/Constraints/ReadOnlyTest.php | 2 ++ tests/Constraints/RequireTest.php | 2 ++ tests/Constraints/RequiredPropertyTest.php | 2 ++ tests/Constraints/SchemaValidationTest.php | 3 ++- tests/Constraints/SelfDefinedSchemaTest.php | 2 ++ tests/Constraints/TupleTypingTest.php | 2 ++ tests/Constraints/TypeTest.php | 3 ++- tests/Constraints/UnionTypesTest.php | 2 ++ tests/Constraints/UnionWithNullValueTest.php | 2 ++ tests/Constraints/UniqueItemsTest.php | 2 ++ tests/Constraints/ValidationExceptionTest.php | 3 ++- tests/Constraints/WrongMessagesFailingTestCaseTest.php | 2 ++ tests/Drafts/Draft3Test.php | 2 ++ tests/Drafts/Draft4Test.php | 2 ++ tests/Exception/InvalidArgumentExceptionTest.php | 2 ++ tests/Exception/InvalidSchemaMediaTypeExceptionTest.php | 2 ++ tests/Exception/InvalidSourceUriExceptionTest.php | 2 ++ tests/Exception/JsonDecodingExceptionTest.php | 2 ++ tests/Exception/ResourceNotFoundExceptionTest.php | 2 ++ tests/Exception/RuntimeExceptionTest.php | 2 ++ tests/Exception/UnresolvableJsonPointerExceptionTest.php | 2 ++ tests/Exception/UriResolverExceptionTest.php | 2 ++ tests/Iterators/ObjectIteratorTest.php | 3 ++- tests/RefTest.php | 3 ++- tests/SchemaStorageTest.php | 3 ++- tests/Uri/Retrievers/CurlTest.php | 2 ++ tests/Uri/Retrievers/FileGetContentsTest.php | 2 ++ tests/Uri/Retrievers/PredefinedArrayTest.php | 2 ++ tests/Uri/UriResolverTest.php | 2 ++ tests/Uri/UriRetrieverTest.php | 3 ++- tests/ValidatorTest.php | 2 ++ 57 files changed, 114 insertions(+), 13 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 158f3074..f31a1b53 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -1,12 +1,13 @@ Date: Mon, 23 Jun 2025 20:52:00 +0200 Subject: [PATCH 107/114] docs: remove remaining file headers with license reference --- tests/ConstraintErrorTest.php | 6 ------ tests/Constraints/BaseTestCase.php | 6 ------ tests/Constraints/CoerciveTest.php | 6 ------ tests/Constraints/DefaultPropertiesTest.php | 6 ------ tests/Constraints/FactoryTest.php | 7 ------- tests/Constraints/LongArraysTest.php | 6 ------ tests/Constraints/PointerTest.php | 6 ------ tests/Constraints/SchemaValidationTest.php | 6 ------ tests/Constraints/TypeTest.php | 6 ------ tests/Constraints/ValidationExceptionTest.php | 6 ------ tests/Entity/JsonPointerTest.php | 7 ------- tests/Iterators/ObjectIteratorTest.php | 6 ------ tests/RefTest.php | 6 ------ tests/SchemaStorageTest.php | 6 ------ tests/Uri/UriRetrieverTest.php | 6 ------ 15 files changed, 92 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index f31a1b53..09d7287c 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -2,12 +2,6 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ namespace JsonSchema\Tests; use JsonSchema\ConstraintError; diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index e4443e5a..fe0bf599 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -2,12 +2,6 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ namespace JsonSchema\Tests\Constraints; use Generator; diff --git a/tests/Constraints/CoerciveTest.php b/tests/Constraints/CoerciveTest.php index a96881ff..47dcc072 100644 --- a/tests/Constraints/CoerciveTest.php +++ b/tests/Constraints/CoerciveTest.php @@ -2,12 +2,6 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ namespace JsonSchema\Tests\Constraints; use JsonSchema\Constraints\Constraint; diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index 65815efd..e43b980e 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -2,12 +2,6 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ namespace JsonSchema\Tests\Constraints; use JsonSchema\Constraints\Constraint; diff --git a/tests/Constraints/FactoryTest.php b/tests/Constraints/FactoryTest.php index 9136f50d..0ff6e922 100644 --- a/tests/Constraints/FactoryTest.php +++ b/tests/Constraints/FactoryTest.php @@ -1,12 +1,5 @@ Date: Mon, 23 Jun 2025 20:52:46 +0200 Subject: [PATCH 108/114] docs: remove remaining class phpdoc comments --- tests/Constraints/TypeTest.php | 7 ------- tests/Entity/JsonPointerTest.php | 5 ----- 2 files changed, 12 deletions(-) diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 0f7766a6..3ba23abc 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -8,13 +8,6 @@ use JsonSchema\Constraints\TypeConstraint; use PHPUnit\Framework\TestCase; -/** - * Class TypeTest - * - * @package JsonSchema\Tests\Constraints - * - * @author hakre - */ class TypeTest extends TestCase { /** diff --git a/tests/Entity/JsonPointerTest.php b/tests/Entity/JsonPointerTest.php index 5641fc79..f6be6621 100644 --- a/tests/Entity/JsonPointerTest.php +++ b/tests/Entity/JsonPointerTest.php @@ -8,11 +8,6 @@ use JsonSchema\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; -/** - * @package JsonSchema\Tests\Entity - * - * @author Joost Nijhuis - */ class JsonPointerTest extends TestCase { /** From 8e7328a566e24e4671468b5b310dd20ae83b6186 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:54:31 +0200 Subject: [PATCH 109/114] test: remove unused @group annotations --- tests/Uri/Retrievers/FileGetContentsTest.php | 3 --- tests/Uri/Retrievers/PredefinedArrayTest.php | 3 --- tests/Uri/UriRetrieverTest.php | 3 --- 3 files changed, 9 deletions(-) diff --git a/tests/Uri/Retrievers/FileGetContentsTest.php b/tests/Uri/Retrievers/FileGetContentsTest.php index 6d957bf9..d48d7945 100644 --- a/tests/Uri/Retrievers/FileGetContentsTest.php +++ b/tests/Uri/Retrievers/FileGetContentsTest.php @@ -7,9 +7,6 @@ use JsonSchema\Uri\Retrievers\FileGetContents; use PHPUnit\Framework\TestCase; -/** - * @group FileGetContents - */ class FileGetContentsTest extends TestCase { public function testFetchMissingFile(): void diff --git a/tests/Uri/Retrievers/PredefinedArrayTest.php b/tests/Uri/Retrievers/PredefinedArrayTest.php index 308c2e00..5594abfd 100644 --- a/tests/Uri/Retrievers/PredefinedArrayTest.php +++ b/tests/Uri/Retrievers/PredefinedArrayTest.php @@ -7,9 +7,6 @@ use JsonSchema\Uri\Retrievers\PredefinedArray; use PHPUnit\Framework\TestCase; -/** - * @group PredefinedArray - */ class PredefinedArrayTest extends TestCase { private $retriever; diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index e1e2f8ca..5f7d2640 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -12,9 +12,6 @@ use JsonSchema\Validator; use PHPUnit\Framework\TestCase; -/** - * @group UriRetriever - */ class UriRetrieverTest extends TestCase { protected $validator; From aa3e0183a9c30042241a547e6a490e7d6bd55eb9 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:57:56 +0200 Subject: [PATCH 110/114] refactor: use ::class constant instead of string value --- tests/ConstraintErrorTest.php | 2 +- tests/Constraints/SchemaValidationTest.php | 4 ++-- tests/Constraints/TypeTest.php | 2 +- tests/Constraints/ValidationExceptionTest.php | 4 ++-- .../InvalidArgumentExceptionTest.php | 2 +- .../InvalidSchemaMediaTypeExceptionTest.php | 4 ++-- .../InvalidSourceUriExceptionTest.php | 4 ++-- tests/Exception/JsonDecodingExceptionTest.php | 4 ++-- .../ResourceNotFoundExceptionTest.php | 4 ++-- tests/Exception/RuntimeExceptionTest.php | 2 +- .../UnresolvableJsonPointerExceptionTest.php | 4 ++-- tests/Exception/UriResolverExceptionTest.php | 4 ++-- tests/Iterators/ObjectIteratorTest.php | 2 +- tests/RefTest.php | 2 +- tests/SchemaStorageTest.php | 16 +++++++-------- tests/Uri/Retrievers/CurlTest.php | 2 +- tests/Uri/UriRetrieverTest.php | 20 +++++++++---------- 17 files changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/ConstraintErrorTest.php b/tests/ConstraintErrorTest.php index 09d7287c..cc599010 100644 --- a/tests/ConstraintErrorTest.php +++ b/tests/ConstraintErrorTest.php @@ -19,7 +19,7 @@ public function testGetInvalidMessage(): void { $e = ConstraintError::MISSING_ERROR(); - $this->expectException('\JsonSchema\Exception\InvalidArgumentException'); + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing error message for missingError'); $e->getMessage(); diff --git a/tests/Constraints/SchemaValidationTest.php b/tests/Constraints/SchemaValidationTest.php index a0cbe5b4..e7b41967 100644 --- a/tests/Constraints/SchemaValidationTest.php +++ b/tests/Constraints/SchemaValidationTest.php @@ -97,7 +97,7 @@ public function testValidCases($schema): void public function testNonObjectSchema(): void { - $this->expectException('\JsonSchema\Exception\RuntimeException'); + $this->expectException(\JsonSchema\Exception\RuntimeException::class); $this->expectExceptionMessage('Cannot validate the schema of a non-object'); $this->testValidCases('"notAnObject"'); @@ -105,7 +105,7 @@ public function testNonObjectSchema(): void public function testInvalidSchemaException(): void { - $this->expectException('\JsonSchema\Exception\InvalidSchemaException'); + $this->expectException(\JsonSchema\Exception\InvalidSchemaException::class); $this->expectExceptionMessage('Schema did not pass validation'); $input = json_decode('{}'); diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index 3ba23abc..0aa830cb 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -121,7 +121,7 @@ public function testValidateTypeException(): void $data = new \stdClass(); $schema = json_decode('{"type": "notAValidTypeName"}'); - $this->expectException('JsonSchema\Exception\InvalidArgumentException'); + $this->expectException(\JsonSchema\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('object is an invalid type for notAValidTypeName'); $t->check($data, $schema); diff --git a/tests/Constraints/ValidationExceptionTest.php b/tests/Constraints/ValidationExceptionTest.php index d46fc633..bb0fd162 100644 --- a/tests/Constraints/ValidationExceptionTest.php +++ b/tests/Constraints/ValidationExceptionTest.php @@ -14,7 +14,7 @@ class ValidationExceptionTest extends TestCase public function testValidationException(): void { $exception = new ValidationException(); - $this->assertInstanceOf('\JsonSchema\Exception\ValidationException', $exception); + $this->assertInstanceOf(\JsonSchema\Exception\ValidationException::class, $exception); $checkValue = json_decode('{"propertyOne": "thisIsNotAnObject"}'); $schema = json_decode('{ @@ -40,7 +40,7 @@ public function testValidationException(): void $exception->getMessage() ); - $this->expectException('JsonSchema\Exception\ValidationException'); + $this->expectException(\JsonSchema\Exception\ValidationException::class); throw $exception; } } diff --git a/tests/Exception/InvalidArgumentExceptionTest.php b/tests/Exception/InvalidArgumentExceptionTest.php index f60ef19b..12b72a7a 100644 --- a/tests/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Exception/InvalidArgumentExceptionTest.php @@ -13,6 +13,6 @@ public function testHierarchy(): void { $exception = new InvalidArgumentException(); self::assertInstanceOf('\InvalidArgumentException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php b/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php index b8b6ad85..0d85647b 100644 --- a/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php +++ b/tests/Exception/InvalidSchemaMediaTypeExceptionTest.php @@ -13,7 +13,7 @@ public function testHierarchy(): void { $exception = new InvalidSchemaMediaTypeException(); self::assertInstanceOf('\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\RuntimeException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/InvalidSourceUriExceptionTest.php b/tests/Exception/InvalidSourceUriExceptionTest.php index 043b5baf..c302e82c 100644 --- a/tests/Exception/InvalidSourceUriExceptionTest.php +++ b/tests/Exception/InvalidSourceUriExceptionTest.php @@ -13,7 +13,7 @@ public function testHierarchy(): void { $exception = new InvalidSourceUriException(); self::assertInstanceOf('\InvalidArgumentException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\InvalidArgumentException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\InvalidArgumentException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/JsonDecodingExceptionTest.php b/tests/Exception/JsonDecodingExceptionTest.php index a683a13b..391c94d1 100644 --- a/tests/Exception/JsonDecodingExceptionTest.php +++ b/tests/Exception/JsonDecodingExceptionTest.php @@ -13,8 +13,8 @@ public function testHierarchy(): void { $exception = new JsonDecodingException(); self::assertInstanceOf('\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\RuntimeException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } public function testDefaultMessage() diff --git a/tests/Exception/ResourceNotFoundExceptionTest.php b/tests/Exception/ResourceNotFoundExceptionTest.php index f232e586..d225b0dd 100644 --- a/tests/Exception/ResourceNotFoundExceptionTest.php +++ b/tests/Exception/ResourceNotFoundExceptionTest.php @@ -13,7 +13,7 @@ public function testHierarchy(): void { $exception = new ResourceNotFoundException(); self::assertInstanceOf('\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\RuntimeException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/RuntimeExceptionTest.php b/tests/Exception/RuntimeExceptionTest.php index e17ff8ff..a30fa527 100644 --- a/tests/Exception/RuntimeExceptionTest.php +++ b/tests/Exception/RuntimeExceptionTest.php @@ -13,6 +13,6 @@ public function testHierarchy(): void { $exception = new RuntimeException(); self::assertInstanceOf('\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/UnresolvableJsonPointerExceptionTest.php b/tests/Exception/UnresolvableJsonPointerExceptionTest.php index 5395e615..68500b86 100644 --- a/tests/Exception/UnresolvableJsonPointerExceptionTest.php +++ b/tests/Exception/UnresolvableJsonPointerExceptionTest.php @@ -13,7 +13,7 @@ public function testHierarchy(): void { $exception = new UnresolvableJsonPointerException(); self::assertInstanceOf('\InvalidArgumentException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\InvalidArgumentException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\InvalidArgumentException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Exception/UriResolverExceptionTest.php b/tests/Exception/UriResolverExceptionTest.php index 8015f21a..0aaf01f4 100644 --- a/tests/Exception/UriResolverExceptionTest.php +++ b/tests/Exception/UriResolverExceptionTest.php @@ -13,7 +13,7 @@ public function testHierarchy(): void { $exception = new UriResolverException(); self::assertInstanceOf('\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception); - self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception); + self::assertInstanceOf(\JsonSchema\Exception\RuntimeException::class, $exception); + self::assertInstanceOf(\JsonSchema\Exception\ExceptionInterface::class, $exception); } } diff --git a/tests/Iterators/ObjectIteratorTest.php b/tests/Iterators/ObjectIteratorTest.php index 61bcafcc..8ee33fe4 100644 --- a/tests/Iterators/ObjectIteratorTest.php +++ b/tests/Iterators/ObjectIteratorTest.php @@ -34,7 +34,7 @@ public function testCreate(): void { $i = new ObjectIterator($this->testObject); - $this->assertInstanceOf('\JsonSchema\Iterator\ObjectIterator', $i); + $this->assertInstanceOf(\JsonSchema\Iterator\ObjectIterator::class, $i); } public function testInitialState(): void diff --git a/tests/RefTest.php b/tests/RefTest.php index 6d1055e9..574fe9ca 100644 --- a/tests/RefTest.php +++ b/tests/RefTest.php @@ -51,7 +51,7 @@ public function dataRefIgnoresSiblings(): array }', '{"propertyOne": 5}', true, - '\JsonSchema\Exception\UnresolvableJsonPointerException' + \JsonSchema\Exception\UnresolvableJsonPointerException::class ] ]; } diff --git a/tests/SchemaStorageTest.php b/tests/SchemaStorageTest.php index 40811926..502a5821 100644 --- a/tests/SchemaStorageTest.php +++ b/tests/SchemaStorageTest.php @@ -16,7 +16,7 @@ public function testResolveRef(): void $mainSchema = $this->getMainSchema(); $mainSchemaPath = 'http://www.example.com/schema.json'; - $uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface'); + $uriRetriever = $this->prophesize(\JsonSchema\UriRetrieverInterface::class); $uriRetriever->retrieve($mainSchemaPath)->willReturn($mainSchema)->shouldBeCalled(); $schemaStorage = new SchemaStorage($uriRetriever->reveal()); @@ -50,7 +50,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference(): $schema3Path = 'http://www.my-domain.com/schema3.json'; /** @var UriRetriever $uriRetriever */ - $uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface'); + $uriRetriever = $this->prophesize(\JsonSchema\UriRetrieverInterface::class); $uriRetriever->retrieve($mainSchemaPath)->willReturn($mainSchema)->shouldBeCalled(); $uriRetriever->retrieve($schema2Path)->willReturn($schema2)->shouldBeCalled(); $uriRetriever->retrieve($schema3Path)->willReturn($schema3)->shouldBeCalled(); @@ -97,13 +97,13 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference(): public function testUnresolvableJsonPointExceptionShouldBeThrown(): void { - $this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException'); + $this->expectException(\JsonSchema\Exception\UnresolvableJsonPointerException::class); $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'; - $uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface'); + $uriRetriever = $this->prophesize(\JsonSchema\UriRetrieverInterface::class); $uriRetriever->retrieve($mainSchemaPath) ->willReturn($mainSchema) ->shouldBeCalled(); @@ -114,7 +114,7 @@ public function testUnresolvableJsonPointExceptionShouldBeThrown(): void public function testResolveRefWithNoAssociatedFileName(): void { - $this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException'); + $this->expectException(\JsonSchema\Exception\UnresolvableJsonPointerException::class); $this->expectExceptionMessage("Could not resolve fragment '#': no file is defined"); $schemaStorage = new SchemaStorage(); @@ -259,14 +259,14 @@ public function testGetUriRetriever(): void { $s = new SchemaStorage(); $s->addSchema('http://json-schema.org/draft-04/schema#'); - $this->assertInstanceOf('\JsonSchema\Uri\UriRetriever', $s->getUriRetriever()); + $this->assertInstanceOf(\JsonSchema\Uri\UriRetriever::class, $s->getUriRetriever()); } public function testGetUriResolver(): void { $s = new SchemaStorage(); $s->addSchema('http://json-schema.org/draft-04/schema#'); - $this->assertInstanceOf('\JsonSchema\Uri\UriResolver', $s->getUriResolver()); + $this->assertInstanceOf(\JsonSchema\Uri\UriResolver::class, $s->getUriResolver()); } public function testMetaSchemaFixes(): void @@ -286,7 +286,7 @@ public function testNoDoubleResolve(): void { $schemaOne = json_decode('{"id": "test/schema", "$ref": "../test2/schema2"}'); - $uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface'); + $uriRetriever = $this->prophesize(\JsonSchema\UriRetrieverInterface::class); $uriRetriever->retrieve('test/schema')->willReturn($schemaOne)->shouldBeCalled(); $s = new SchemaStorage($uriRetriever->reveal()); diff --git a/tests/Uri/Retrievers/CurlTest.php b/tests/Uri/Retrievers/CurlTest.php index e9de67f2..c2c88067 100644 --- a/tests/Uri/Retrievers/CurlTest.php +++ b/tests/Uri/Retrievers/CurlTest.php @@ -21,7 +21,7 @@ public function testRetrieveNonexistantFile(): void { $c = new Curl(); - $this->expectException('\JsonSchema\Exception\ResourceNotFoundException'); + $this->expectException(\JsonSchema\Exception\ResourceNotFoundException::class); $this->expectExceptionMessage('JSON schema not found'); $c->retrieve(__DIR__ . '/notARealFile'); diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index 5f7d2640..0016cc4a 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -29,7 +29,7 @@ private function getRetrieverMock($returnSchema) throw new JsonDecodingException($error); } - $retriever = $this->createMock('JsonSchema\Uri\UriRetriever'); + $retriever = $this->createMock(\JsonSchema\Uri\UriRetriever::class); $retriever->expects($this->at(0)) ->method('retrieve') @@ -227,7 +227,7 @@ public function testResolveExcessLevelUp(): void public function testConfirmMediaTypeAcceptsJsonSchemaType(): void { - $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -239,7 +239,7 @@ public function testConfirmMediaTypeAcceptsJsonSchemaType(): void public function testConfirmMediaTypeAcceptsJsonType(): void { - $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) @@ -251,7 +251,7 @@ public function testConfirmMediaTypeAcceptsJsonType(): void public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes(): void { - $uriRetriever = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $uriRetriever = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $retriever = new UriRetriever(); $uriRetriever->expects($this->at(0)) ->method('getContentType') @@ -266,11 +266,11 @@ private function mockRetriever($schema): void { $retrieverMock = $this->getRetrieverMock($schema); - $factory = new \ReflectionProperty('JsonSchema\Constraints\BaseConstraint', 'factory'); + $factory = new \ReflectionProperty(\JsonSchema\Constraints\BaseConstraint::class, 'factory'); $factory->setAccessible(true); $factory = $factory->getValue($this->validator); - $retriever = new \ReflectionProperty('JsonSchema\Constraints\Factory', 'uriRetriever'); + $retriever = new \ReflectionProperty(\JsonSchema\Constraints\Factory::class, 'uriRetriever'); $retriever->setAccessible(true); $retriever->setValue($factory, $retrieverMock); } @@ -325,7 +325,7 @@ public function testRetrieveSchemaFromPackage(): void public function testInvalidContentTypeEndpointsDefault(): void { - $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -335,7 +335,7 @@ public function testInvalidContentTypeEndpointsDefault(): void public function testInvalidContentTypeEndpointsUnknown(): void { - $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); @@ -345,7 +345,7 @@ public function testInvalidContentTypeEndpointsUnknown(): void public function testInvalidContentTypeEndpointsAdded(): void { - $mock = $this->createMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface'); + $mock = $this->createMock(\JsonSchema\Uri\Retrievers\UriRetrieverInterface::class); $mock->method('getContentType')->willReturn('Application/X-Fake-Type'); $retriever = new UriRetriever(); $retriever->addInvalidContentTypeEndpoint('http://example.com'); @@ -378,7 +378,7 @@ public function testLoadSchemaJSONDecodingException(): void { $retriever = new UriRetriever(); - $this->expectException('JsonSchema\Exception\JsonDecodingException'); + $this->expectException(\JsonSchema\Exception\JsonDecodingException::class); $this->expectExceptionMessage('JSON syntax is malformed'); $retriever->retrieve('package://tests/fixtures/bad-syntax.json'); From ae952f8533ae4b9034479541d3d6dd2f9d15ba8e Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:59:03 +0200 Subject: [PATCH 111/114] refactor: use null coalescing operator --- tests/Constraints/BaseTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index fe0bf599..d3b4515e 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -52,7 +52,7 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode */ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = []): void { - $checkMode = $checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $checkMode; + $checkMode = $checkMode ?? Constraint::CHECK_MODE_TYPE_CAST; if ($this->validateSchema) { $checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA; } From 8cf9145371b15651504faa4bfa40b057ccc0a3a1 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 20:59:48 +0200 Subject: [PATCH 112/114] refactor: replace rand with random_int --- tests/Constraints/LongArraysTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Constraints/LongArraysTest.php b/tests/Constraints/LongArraysTest.php index 5d9cd03a..d5289fed 100644 --- a/tests/Constraints/LongArraysTest.php +++ b/tests/Constraints/LongArraysTest.php @@ -55,7 +55,7 @@ public function testLongNumberArray(): void $tmp = new \stdClass(); $tmp->p_array = array_map(function ($i) { - return rand(1, 1000) / 1000.0; + return random_int(1, 1000) / 1000.0; }, range(1, 100000)); $input = json_encode($tmp); From 5acd1e7abeae7bd834d268a69e1743e144b443a7 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 21:31:02 +0200 Subject: [PATCH 113/114] fix: fix test regression --- tests/Constraints/BaseTestCase.php | 4 +- tests/Constraints/UndefinedConstraintTest.php | 203 ++++++++---------- 2 files changed, 97 insertions(+), 110 deletions(-) diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index d3b4515e..f65037d6 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -87,14 +87,14 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M if ($this->validateSchema) { $checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA; } - $schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema))); + $schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema, false))); $schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json'); if (is_object($schema) && !isset($schema->{'$schema'})) { $schema->{'$schema'} = $this->schemaSpec; } $validator = new Validator(new Factory($schemaStorage, null, $checkMode)); - $checkValue = json_decode($input); + $checkValue = json_decode($input, false); $errorMask = $validator->validate($checkValue, $schema); $this->assertEquals(0, $errorMask); diff --git a/tests/Constraints/UndefinedConstraintTest.php b/tests/Constraints/UndefinedConstraintTest.php index eaf46fc2..d6fb2f2f 100644 --- a/tests/Constraints/UndefinedConstraintTest.php +++ b/tests/Constraints/UndefinedConstraintTest.php @@ -10,144 +10,131 @@ class UndefinedConstraintTest extends BaseTestCase { public function getInvalidTests(): \Generator { + yield from []; } public function getValidTests(): \Generator { yield 'oneOf with type coercion should not affect value passed to each sub schema (#790)' => [ - 'input' => << '{ + "id": "LOC1", + "related_locations": [ { - "id": "LOC1", - "related_locations": [ - { - "latitude": "51.047598", - "longitude": "3.729943" - } - ] + "latitude": "51.047598", + "longitude": "3.729943" } -JSON, - 'schema' => << '{ + "title": "Location", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "related_locations": { + "oneOf": [ + { + "type": "null" }, - "related_locations": { - "oneOf": [ - { - "type": "null" - }, - { - "type": "array", - "items": { - "type": "object", - "properties": { - "latitude": { - "type": "string" - }, - "longitude": { - "type": "string" - } - } + { + "type": "array", + "items": { + "type": "object", + "properties": { + "latitude": { + "type": "string" + }, + "longitude": { + "type": "string" } } - ] + } } - } + ] } -JSON, + } + }', 'checkMode' => Constraint::CHECK_MODE_COERCE_TYPES ]; yield 'oneOf with apply defaults should not affect value passed to each sub schema (#510)' => [ - 'input' => << << '{"foo": {"name": "bar"}}', + 'schema' => '{ + "oneOf": [ + { + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "name": {"enum":["baz"],"default":"baz"}, + "meta": {"enum":["baz"],"default":"baz"} } } - }, - { - "type": "object", - "properties": { - "foo": { - "type": "object", - "properties": { - "name": {"enum":["bar"],"default":"bar"}, - "meta": {"enum":["bar"],"default":"bar"} - } + } + }, + { + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "name": {"enum":["bar"],"default":"bar"}, + "meta": {"enum":["bar"],"default":"bar"} } } - }, - { - "type": "object", - "properties": { - "foo": { - "type": "object", - "properties": { - "name": {"enum":["zip"],"default":"zip"}, - "meta": {"enum":["zip"],"default":"zip"} - } + } + }, + { + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "name": {"enum":["zip"],"default":"zip"}, + "meta": {"enum":["zip"],"default":"zip"} } } } - ] - } -JSON, + } + ] + }', 'checkMode' => Constraint::CHECK_MODE_APPLY_DEFAULTS ]; yield 'anyOf with apply defaults should not affect value passed to each sub schema (#711)' => [ - 'input' => << '{ "b": 2 }', + 'schema' => '{ + "anyOf": [ { - "b": 2 - } -JSON, - 'schema' => << Constraint::CHECK_MODE_APPLY_DEFAULTS ]; } From 7dd4205aa063ad2da0bf72c43359c75aaa4e62ab Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 23 Jun 2025 21:35:29 +0200 Subject: [PATCH 114/114] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc32e7a..c346c4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed - Update test case to current (PHP) standards ([#831](https://github.com/jsonrainbow/json-schema/pull/831)) +- Upgrade test suite to use generators ([#834](https://github.com/jsonrainbow/json-schema/pull/834)) ## [6.4.2] - 2025-06-03 ### Fixed