Skip to content

Commit ad87d5a

Browse files
Jérôme DeuchnordSeldaek
Jérôme Deuchnord
authored andcommitted
Fix type validation failing for "any" and false-y type wording
1 parent 384f945 commit ad87d5a

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
@@ -134,7 +134,7 @@ protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = fa
134134
*/
135135
protected function validateTypeNameWording($type)
136136
{
137-
if (!isset(self::$wording[$type])) {
137+
if (!array_key_exists($type, self::$wording)) {
138138
throw new StandardUnexpectedValueException(
139139
sprintf(
140140
'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)