Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type validation failing for "any" and false-y type wording #686

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/TypeConstraint.php
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
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