From 2ddf4362c02c5193244fb6e291170516ef5e89d6 Mon Sep 17 00:00:00 2001 From: Ayrton Ricardo Date: Mon, 10 Dec 2018 14:21:09 +0100 Subject: [PATCH 1/2] Change validation to allow fields described as DateTimeInterface. --- ModelDescriber/ObjectModelDescriber.php | 2 +- Tests/Functional/Entity/User.php | 21 +++++++++++++++++++++ Tests/Functional/FunctionalTest.php | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index a7f9634..267a662 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -106,7 +106,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar $property->setType('number'); $property->setFormat('float'); } elseif (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) { - if (is_subclass_of($type->getClassName(), \DateTimeInterface::class)) { + if (is_a($type->getClassName(), \DateTimeInterface::class, true)) { $property->setType('string'); $property->setFormat('date-time'); } else { diff --git a/Tests/Functional/Entity/User.php b/Tests/Functional/Entity/User.php index bb03ea4..6a1469b 100644 --- a/Tests/Functional/Entity/User.php +++ b/Tests/Functional/Entity/User.php @@ -78,6 +78,11 @@ class User */ private $status; + /** + * @var \DateTimeInterface + */ + private $dateAsInterface; + /** * @param float $money */ @@ -134,4 +139,20 @@ class User public function setStatus(string $status) { } + + /** + * @return \DateTimeInterface + */ + public function getDateAsInterface(): \DateTimeInterface + { + return $this->dateAsInterface; + } + + /** + * @param \DateTimeInterface $dateAsInterface + */ + public function setDateAsInterface(\DateTimeInterface $dateAsInterface) + { + $this->dateAsInterface = $dateAsInterface; + } } diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index a1ef239..baf9ae1 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -220,6 +220,10 @@ class FunctionalTest extends WebTestCase 'type' => 'string', 'enum' => ['disabled', 'enabled'], ], + 'dateAsInterface' => [ + 'type' => 'string', + 'format' => 'date-time', + ] ], ], $this->getModel('User')->toArray() From 2f53cc9c122012390b9f453e55f7a606b8f9dd02 Mon Sep 17 00:00:00 2001 From: Ayrton Ricardo Date: Mon, 10 Dec 2018 14:25:08 +0100 Subject: [PATCH 2/2] Add ',' in the end of array --- Tests/Functional/FunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index baf9ae1..6b3ce63 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -223,7 +223,7 @@ class FunctionalTest extends WebTestCase 'dateAsInterface' => [ 'type' => 'string', 'format' => 'date-time', - ] + ], ], ], $this->getModel('User')->toArray()