From 03a5d2266dd425c9659ce92cc814f5837e092fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Tue, 5 Apr 2022 15:28:21 +0200 Subject: [PATCH] Fix type validation failing for "any" and false-y type wording --- src/JsonSchema/Constraints/TypeConstraint.php | 2 +- tests/Constraints/TypeTest.php | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/JsonSchema/Constraints/TypeConstraint.php b/src/JsonSchema/Constraints/TypeConstraint.php index b57c6f5e..be8e0672 100644 --- a/src/JsonSchema/Constraints/TypeConstraint.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -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]', diff --git a/tests/Constraints/TypeTest.php b/tests/Constraints/TypeTest.php index ca6bf7cf..a10996da 100644 --- a/tests/Constraints/TypeTest.php +++ b/tests/Constraints/TypeTest.php @@ -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);