Skip to content

Commit

Permalink
Fix type validation failing for "any" and false-y type wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Deuchnord committed Apr 6, 2022
1 parent 4c74da5 commit 03a5d22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/TypeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = fa
*/
protected function validateTypeNameWording($type)
{
if (!isset(self::$wording[$type])) {
if (!array_key_exists($type, self::$wording)) {
throw new StandardUnexpectedValueException(
sprintf(
'No wording for %s available, expected wordings are: [%s]',
Expand Down
26 changes: 25 additions & 1 deletion tests/Constraints/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,31 @@ private function assertTypeConstraintError($expected, TypeConstraint $actual)
$this->assertSame($expected, $actualMessage); // the same for the strictness
}

public function testValidateTypeNameWording()
public function validNameWordingDataProvider()
{
$wordings = array();

foreach (array_keys(TypeConstraint::$wording) as $value) {
$wordings[] = array($value);
}

return $wordings;
}

/**
* @dataProvider validNameWordingDataProvider
*/
public function testValidateTypeNameWording($nameWording)
{
$t = new TypeConstraint();
$r = new \ReflectionObject($t);
$m = $r->getMethod('validateTypeNameWording');
$m->setAccessible(true);

$m->invoke($t, $nameWording);
}

public function testInvalidateTypeNameWording()
{
$t = new TypeConstraint();
$r = new \ReflectionObject($t);
Expand Down

0 comments on commit 03a5d22

Please sign in to comment.