@@ -19,7 +19,7 @@ abstract class BaseTestCase extends VeryBaseTestCase
1919 /**
2020 * @dataProvider getInvalidTests
2121 *
22- * @param int-mask-of<Constraint::CHECK_MODE_*> $checkMode
22+ * @param ? int-mask-of<Constraint::CHECK_MODE_*> $checkMode
2323 */
2424 public function testInvalidCases (string $ input , string $ schema , ?int $ checkMode = Constraint::CHECK_MODE_NORMAL , array $ errors = []): void
2525 {
@@ -28,8 +28,9 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
2828 $ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
2929 }
3030
31- $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock (json_decode ($ schema , false )));
32- $ schema = $ schemaStorage ->getSchema ('http://www.my-domain.com/schema.json ' );
31+ $ schema = json_decode ($ schema , false );
32+ $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock ($ schema ));
33+ $ schema = $ schemaStorage ->getSchema ($ schema ->id ?? 'http://www.my-domain.com/schema.json ' );
3334 if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
3435 $ schema ->{'$schema ' } = $ this ->schemaSpec ;
3536 }
@@ -38,7 +39,7 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
3839 $ checkValue = json_decode ($ input , false );
3940 $ errorMask = $ validator ->validate ($ checkValue , $ schema );
4041
41- $ this ->assertTrue ((bool ) ($ errorMask & Validator::ERROR_DOCUMENT_VALIDATION ));
42+ $ this ->assertTrue ((bool ) ($ errorMask & Validator::ERROR_DOCUMENT_VALIDATION ), ' Document is invalid ' );
4243 $ this ->assertGreaterThan (0 , $ validator ->numErrors ());
4344
4445 if ([] !== $ errors ) {
@@ -49,8 +50,10 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
4950
5051 /**
5152 * @dataProvider getInvalidForAssocTests
53+ *
54+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
5255 */
53- public function testInvalidCasesUsingAssoc ($ input , $ schema , $ checkMode = Constraint::CHECK_MODE_TYPE_CAST , $ errors = []): void
56+ public function testInvalidCasesUsingAssoc (string $ input , string $ schema , ? int $ checkMode = Constraint::CHECK_MODE_TYPE_CAST , array $ errors = []): void
5457 {
5558 $ checkMode = $ checkMode ?? Constraint::CHECK_MODE_TYPE_CAST ;
5659 if ($ this ->validateSchema ) {
@@ -60,8 +63,9 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
6063 $ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
6164 }
6265
63- $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock (json_decode ($ schema )));
64- $ schema = $ schemaStorage ->getSchema ('http://www.my-domain.com/schema.json ' );
66+ $ schema = json_decode ($ schema , false );
67+ $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock ($ schema ));
68+ $ schema = $ schemaStorage ->getSchema ($ schema ->id ?? 'http://www.my-domain.com/schema.json ' );
6569 if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
6670 $ schema ->{'$schema ' } = $ this ->schemaSpec ;
6771 }
@@ -81,14 +85,18 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
8185
8286 /**
8387 * @dataProvider getValidTests
88+ *
89+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
8490 */
85- public function testValidCases ($ input , $ schema , $ checkMode = Constraint::CHECK_MODE_NORMAL ): void
91+ public function testValidCases (string $ input , string $ schema , ? int $ checkMode = Constraint::CHECK_MODE_NORMAL ): void
8692 {
8793 if ($ this ->validateSchema ) {
8894 $ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
8995 }
90- $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock (json_decode ($ schema , false )));
91- $ schema = $ schemaStorage ->getSchema ('http://www.my-domain.com/schema.json ' );
96+
97+ $ schema = json_decode ($ schema , false );
98+ $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock ($ schema ));
99+ $ schema = $ schemaStorage ->getSchema ($ schema ->id ?? 'http://www.my-domain.com/schema.json ' );
92100 if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
93101 $ schema ->{'$schema ' } = $ this ->schemaSpec ;
94102 }
@@ -103,8 +111,10 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
103111
104112 /**
105113 * @dataProvider getValidForAssocTests
114+ *
115+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
106116 */
107- public function testValidCasesUsingAssoc ($ input , $ schema , $ checkMode = Constraint::CHECK_MODE_TYPE_CAST ): void
117+ public function testValidCasesUsingAssoc (string $ input , string $ schema , ? int $ checkMode = Constraint::CHECK_MODE_TYPE_CAST ): void
108118 {
109119 if ($ this ->validateSchema ) {
110120 $ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
@@ -113,9 +123,9 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
113123 $ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
114124 }
115125
116- $ schema = json_decode ($ schema );
126+ $ schema = json_decode ($ schema, false );
117127 $ schemaStorage = new SchemaStorage ($ this ->getUriRetrieverMock ($ schema ), new UriResolver ());
118- $ schema = $ schemaStorage ->getSchema ('http://www.my-domain.com/schema.json ' );
128+ $ schema = $ schemaStorage ->getSchema ($ schema -> id ?? 'http://www.my-domain.com/schema.json ' );
119129 if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
120130 $ schema ->{'$schema ' } = $ this ->schemaSpec ;
121131 }
@@ -124,7 +134,7 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
124134 $ validator = new Validator (new Factory ($ schemaStorage , null , $ checkMode ));
125135
126136 $ errorMask = $ validator ->validate ($ value , $ schema );
127- $ this ->assertEquals (0 , $ errorMask );
137+ $ this ->assertEquals (0 , $ errorMask, $ this -> validatorErrorsToString ( $ validator ) );
128138 $ this ->assertTrue ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
129139 }
130140
@@ -141,4 +151,14 @@ public function getInvalidForAssocTests(): Generator
141151 {
142152 yield from $ this ->getInvalidTests ();
143153 }
154+
155+ private function validatorErrorsToString (Validator $ validator ): string
156+ {
157+ return implode (
158+ ', ' ,
159+ array_map (
160+ static function (array $ error ) { return $ error ['message ' ]; }, $ validator ->getErrors ()
161+ )
162+ );
163+ }
144164}
0 commit comments