Skip to content

Commit 03a5d22

Browse files
author
Jérôme Deuchnord
committed
Fix type validation failing for "any" and false-y type wording
1 parent 4c74da5 commit 03a5d22

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = fa
151151
*/
152152
protected function validateTypeNameWording($type)
153153
{
154-
if (!isset(self::$wording[$type])) {
154+
if (!array_key_exists($type, self::$wording)) {
155155
throw new StandardUnexpectedValueException(
156156
sprintf(
157157
'No wording for %s available, expected wordings are: [%s]',

tests/Constraints/TypeTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,31 @@ private function assertTypeConstraintError($expected, TypeConstraint $actual)
9494
$this->assertSame($expected, $actualMessage); // the same for the strictness
9595
}
9696

97-
public function testValidateTypeNameWording()
97+
public function validNameWordingDataProvider()
98+
{
99+
$wordings = array();
100+
101+
foreach (array_keys(TypeConstraint::$wording) as $value) {
102+
$wordings[] = array($value);
103+
}
104+
105+
return $wordings;
106+
}
107+
108+
/**
109+
* @dataProvider validNameWordingDataProvider
110+
*/
111+
public function testValidateTypeNameWording($nameWording)
112+
{
113+
$t = new TypeConstraint();
114+
$r = new \ReflectionObject($t);
115+
$m = $r->getMethod('validateTypeNameWording');
116+
$m->setAccessible(true);
117+
118+
$m->invoke($t, $nameWording);
119+
}
120+
121+
public function testInvalidateTypeNameWording()
98122
{
99123
$t = new TypeConstraint();
100124
$r = new \ReflectionObject($t);

0 commit comments

Comments
 (0)