13
13
use RecursiveDirectoryIterator ;
14
14
use RecursiveIteratorIterator ;
15
15
16
- class JsonSchemaTestSuite extends TestCase
16
+ class JsonSchemaTestSuiteTest extends TestCase
17
17
{
18
18
/**
19
19
* @dataProvider casesDataProvider
20
20
*/
21
- public function testIt (
21
+ public function testTestCaseValidatesCorrectly (
22
22
string $ testCaseDescription ,
23
23
string $ testDescription ,
24
24
\stdClass $ schema ,
25
25
mixed $ data ,
26
- bool $ expectedValidationResult
26
+ bool $ expectedValidationResult ,
27
+ bool $ optional
27
28
): void
28
29
{
29
30
$ schemaStorage = new SchemaStorage ();
30
31
$ schemaStorage ->addSchema (property_exists ($ schema , 'id ' ) ? $ schema ->id : SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI , $ schema );
31
32
$ this ->loadRemotesIntoStorage ($ schemaStorage );
32
33
$ validator = new Validator (new Factory ($ schemaStorage ));
33
34
34
- $ result = $ validator ->validate ($ data , $ schema );
35
+ $ validator ->validate ($ data , $ schema );
36
+
37
+ if ($ optional && $ expectedValidationResult !== (count ($ validator ->getErrors ()) === 0 )) {
38
+ $ this ->markTestSkipped ('Optional test case would fail ' );
39
+ return ;
40
+ }
35
41
36
42
self ::assertEquals ($ expectedValidationResult , count ($ validator ->getErrors ()) === 0 );
37
43
}
@@ -65,7 +71,7 @@ function ($file) {
65
71
$ name = sprintf (
66
72
'[%s/%s%s]: %s: %s is expected to be %s ' ,
67
73
basename ($ draft ),
68
- str_contains ($ file ->getPathname (), 'optional ' ) ? 'optional/ ' : '' ,
74
+ str_contains ($ file ->getPathname (), '/ optional/ ' ) ? 'optional/ ' : '' ,
69
75
$ file ->getBasename (),
70
76
$ testCase ->description ,
71
77
$ test ->description ,
@@ -78,6 +84,7 @@ function ($file) {
78
84
'schema ' => $ testCase ->schema ,
79
85
'data ' => $ test ->data ,
80
86
'expectedValidationResult ' => $ test ->valid ,
87
+ 'optional ' => str_contains ($ file ->getPathname (), '/optional/ ' )
81
88
];
82
89
}
83
90
0 commit comments