@@ -19,7 +19,7 @@ abstract class BaseTestCase extends VeryBaseTestCase
19
19
/**
20
20
* @dataProvider getInvalidTests
21
21
*
22
- * @param int-mask-of<Constraint::CHECK_MODE_*> $checkMode
22
+ * @param ? int-mask-of<Constraint::CHECK_MODE_*> $checkMode
23
23
*/
24
24
public function testInvalidCases (string $ input , string $ schema , ?int $ checkMode = Constraint::CHECK_MODE_NORMAL , array $ errors = []): void
25
25
{
@@ -28,8 +28,9 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
28
28
$ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
29
29
}
30
30
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 ' );
33
34
if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
34
35
$ schema ->{'$schema ' } = $ this ->schemaSpec ;
35
36
}
@@ -38,7 +39,7 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
38
39
$ checkValue = json_decode ($ input , false );
39
40
$ errorMask = $ validator ->validate ($ checkValue , $ schema );
40
41
41
- $ this ->assertTrue ((bool ) ($ errorMask & Validator::ERROR_DOCUMENT_VALIDATION ));
42
+ $ this ->assertTrue ((bool ) ($ errorMask & Validator::ERROR_DOCUMENT_VALIDATION ), ' Document is invalid ' );
42
43
$ this ->assertGreaterThan (0 , $ validator ->numErrors ());
43
44
44
45
if ([] !== $ errors ) {
@@ -49,8 +50,10 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
49
50
50
51
/**
51
52
* @dataProvider getInvalidForAssocTests
53
+ *
54
+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
52
55
*/
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
54
57
{
55
58
$ checkMode = $ checkMode ?? Constraint::CHECK_MODE_TYPE_CAST ;
56
59
if ($ this ->validateSchema ) {
@@ -60,8 +63,9 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
60
63
$ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
61
64
}
62
65
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 ' );
65
69
if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
66
70
$ schema ->{'$schema ' } = $ this ->schemaSpec ;
67
71
}
@@ -81,14 +85,18 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
81
85
82
86
/**
83
87
* @dataProvider getValidTests
88
+ *
89
+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
84
90
*/
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
86
92
{
87
93
if ($ this ->validateSchema ) {
88
94
$ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
89
95
}
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 ' );
92
100
if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
93
101
$ schema ->{'$schema ' } = $ this ->schemaSpec ;
94
102
}
@@ -103,8 +111,10 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
103
111
104
112
/**
105
113
* @dataProvider getValidForAssocTests
114
+ *
115
+ * @param ?int-mask-of<Constraint::CHECK_MODE_*> $checkMode
106
116
*/
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
108
118
{
109
119
if ($ this ->validateSchema ) {
110
120
$ checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA ;
@@ -113,9 +123,9 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
113
123
$ this ->markTestSkipped ('Test indicates that it is not for "CHECK_MODE_TYPE_CAST" ' );
114
124
}
115
125
116
- $ schema = json_decode ($ schema );
126
+ $ schema = json_decode ($ schema, false );
117
127
$ 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 ' );
119
129
if (is_object ($ schema ) && !isset ($ schema ->{'$schema ' })) {
120
130
$ schema ->{'$schema ' } = $ this ->schemaSpec ;
121
131
}
@@ -124,7 +134,7 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
124
134
$ validator = new Validator (new Factory ($ schemaStorage , null , $ checkMode ));
125
135
126
136
$ errorMask = $ validator ->validate ($ value , $ schema );
127
- $ this ->assertEquals (0 , $ errorMask );
137
+ $ this ->assertEquals (0 , $ errorMask, $ this -> validatorErrorsToString ( $ validator ) );
128
138
$ this ->assertTrue ($ validator ->isValid (), print_r ($ validator ->getErrors (), true ));
129
139
}
130
140
@@ -141,4 +151,14 @@ public function getInvalidForAssocTests(): Generator
141
151
{
142
152
yield from $ this ->getInvalidTests ();
143
153
}
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
+ }
144
164
}
0 commit comments