Skip to content

Commit 98c90f9

Browse files
committed
test: Add test case for unsupported drafts in strict mode
1 parent 77a9eba commit 98c90f9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/ValidatorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,31 @@ public function testDeprecatedCoerceDelegatesToValidate(): void
6767

6868
$this->assertTrue($validator->isValid(), 'Validation failed, but should have succeeded.');
6969
}
70+
71+
/** @dataProvider draftIdentifiersNotSupportedForStrictMode */
72+
public function testItThrowsForStrictValidationOnDraft(DraftIdentifiers $draft): void
73+
{
74+
$data = json_decode('"42"', false);
75+
$schema = json_decode('{"type":"integer"}', false);
76+
$factory = new Factory(null, null, Constraint::CHECK_MODE_NORMAL | Constraint::CHECK_MODE_STRICT);
77+
$factory->setDefaultDialect($draft->getValue());
78+
$validator = new Validator($factory);
79+
80+
$this->expectException(InvalidArgumentException::class);
81+
$this->expectExceptionMessage('Unknown constraint ' . $draft->toConstraintName());
82+
83+
$validator->validate($data, $schema);
84+
}
85+
86+
public function draftIdentifiersNotSupportedForStrictMode(): \Generator
87+
{
88+
foreach (DraftIdentifiers::getEnumerators() as $draft) {
89+
switch ($draft) {
90+
case DraftIdentifiers::DRAFT_6():
91+
break;
92+
default:
93+
yield $draft->toConstraintName() => [$draft];
94+
}
95+
}
96+
}
7097
}

0 commit comments

Comments
 (0)