1313use RecursiveDirectoryIterator ;
1414use RecursiveIteratorIterator ;
1515
16- class JsonSchemaTestSuite extends TestCase
16+ class JsonSchemaTestSuiteTest extends TestCase
1717{
1818 /**
1919 * @dataProvider casesDataProvider
2020 */
21- public function testIt (
21+ public function testTestCaseValidatesCorrectly (
2222 string $ testCaseDescription ,
2323 string $ testDescription ,
2424 \stdClass $ schema ,
2525 mixed $ data ,
26- bool $ expectedValidationResult
26+ bool $ expectedValidationResult ,
27+ bool $ optional
2728 ): void
2829 {
2930 $ schemaStorage = new SchemaStorage ();
3031 $ schemaStorage ->addSchema (property_exists ($ schema , 'id ' ) ? $ schema ->id : SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI , $ schema );
3132 $ this ->loadRemotesIntoStorage ($ schemaStorage );
3233 $ validator = new Validator (new Factory ($ schemaStorage ));
3334
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+ }
3541
3642 self ::assertEquals ($ expectedValidationResult , count ($ validator ->getErrors ()) === 0 );
3743 }
@@ -65,7 +71,7 @@ function ($file) {
6571 $ name = sprintf (
6672 '[%s/%s%s]: %s: %s is expected to be %s ' ,
6773 basename ($ draft ),
68- str_contains ($ file ->getPathname (), 'optional ' ) ? 'optional/ ' : '' ,
74+ str_contains ($ file ->getPathname (), '/ optional/ ' ) ? 'optional/ ' : '' ,
6975 $ file ->getBasename (),
7076 $ testCase ->description ,
7177 $ test ->description ,
@@ -78,6 +84,7 @@ function ($file) {
7884 'schema ' => $ testCase ->schema ,
7985 'data ' => $ test ->data ,
8086 'expectedValidationResult ' => $ test ->valid ,
87+ 'optional ' => str_contains ($ file ->getPathname (), '/optional/ ' )
8188 ];
8289 }
8390
0 commit comments