Skip to content

Commit 5193169

Browse files
committed
fix: correct test suite test case
1 parent e7c8b31 commit 5193169

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

tests/Constraints/BaseTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK
4343
$checkValue = json_decode($input);
4444
$errorMask = $validator->validate($checkValue, $schema);
4545

46-
$this->assertTrue((bool) ($errorMask & Validator::ERROR_DOCUMENT_VALIDATION));
46+
$this->assertTrue((bool) ($errorMask & Validator::ERROR_DOCUMENT_VALIDATION), 'Document is invalid');
4747
$this->assertGreaterThan(0, $validator->numErrors());
4848

4949
if ([] !== $errors) {

tests/JsonSchemaTestSuite.php renamed to tests/JsonSchemaTestSuiteTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,31 @@
1313
use RecursiveDirectoryIterator;
1414
use 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

Comments
 (0)