From 97f4388c0b1b0db683b396d5b024c0df484ce585 Mon Sep 17 00:00:00 2001 From: Vladislav Kovchenkov Date: Sat, 1 May 2021 18:57:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B6=D0=B8=D0=B4=D0=B0=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=B4=D0=B2=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0=20Dat?= =?UTF-8?q?eTime=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8F=20DateLas?= =?UTF-8?q?tChange=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Order.php | 2 +- .../InfoReportResponseTest.php | 23 ++++++++++++++ .../InfoReportDateLastChangeYmdHisPMixed.xml | 30 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/data/InfoReportDateLastChangeYmdHisPMixed.xml diff --git a/src/Common/Order.php b/src/Common/Order.php index bf32eb7..969091d 100644 --- a/src/Common/Order.php +++ b/src/Common/Order.php @@ -353,7 +353,7 @@ public static function withNumberAndDate(string $Number, \DateTimeInterface $Dat /** * @JMS\XmlAttribute - * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP', '', 'Y-m-d\TH:i:sP', 'Y-m-d H:i:s'>") + * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP', '', 'Y-m-d\TH:i:sP', ['Y-m-d H:i:s', 'Y-m-d H:i:sP']>") * * @var \DateTimeImmutable|null */ diff --git a/tests/Deserialization/InfoReportResponseTest.php b/tests/Deserialization/InfoReportResponseTest.php index cd26918..d59238c 100644 --- a/tests/Deserialization/InfoReportResponseTest.php +++ b/tests/Deserialization/InfoReportResponseTest.php @@ -164,4 +164,27 @@ public function test_it_serializes_to_empty_json() $response = new InfoReportResponse(); $this->assertSame([], $response->jsonSerialize()); } + + public function test_date_last_change_with_mixed_datetime_format() + { + $response = $this->getSerializer()->deserialize(FixtureLoader::load('InfoReportDateLastChangeYmdHisPMixed.xml'), InfoReportResponse::class, 'xml'); + + /** @var $response InfoReportResponse */ + $this->assertInstanceOf(InfoReportResponse::class, $response); + + $this->assertCount(3, $response->getOrders()); + $this->assertCount(3, $response); + + $order = $response->getOrders()[0]; + $this->assertSame('ORD-121121', $order->getNumber()); + $this->assertSame('2020-03-05 04:30:00', $order->getDateLastChange()->format('Y-m-d H:i:s')); + + $order = $response->getOrders()[1]; + $this->assertSame('ORD-121122', $order->getNumber()); + $this->assertSame('2020-03-06 05:30:00', $order->getDateLastChange()->format('Y-m-d H:i:s')); + + $order = $response->getOrders()[2]; + $this->assertSame('ORD-121123', $order->getNumber()); + $this->assertSame('2020-03-07 06:30:00+05:00', $order->getDateLastChange()->format('Y-m-d H:i:sP')); + } } diff --git a/tests/Fixtures/data/InfoReportDateLastChangeYmdHisPMixed.xml b/tests/Fixtures/data/InfoReportDateLastChangeYmdHisPMixed.xml new file mode 100644 index 0000000..f19a6df --- /dev/null +++ b/tests/Fixtures/data/InfoReportDateLastChangeYmdHisPMixed.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +