Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Ожидаем два возможных формата DateTime для поля DateLastChange (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkovch authored May 1, 2021
1 parent c075e38 commit 97f4388
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Common/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/Deserialization/InfoReportResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
30 changes: 30 additions & 0 deletions tests/Fixtures/data/InfoReportDateLastChangeYmdHisPMixed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<InfoReport>
<Order Number="ORD-121121" Date="2020-03-04" DispatchNumber="111222333" TariffTypeCode="136" Weight="1.5" DeliverySum="265" DateLastChange="2020-03-05 04:30:00" CashOnDeliv="3792" CashOnDelivFact="3792" CashOnDelivType="cashless" deliveryMode="4" pvzCode="ENG1" deliveryVariant="PVZCDEK">
<SendCity Code="415" PostCode="610000" Name="Киров"/>
<RecCity Code="214" PostCode="413100" Name="Энгельс"/>
<Package Number="_" BarCode="1" Weight="1.5" VolumeWeight="1.3" SizeA="65" SizeB="10" SizeC="10">
<Item WareKey="00123" Comment="Item name" Cost="3500" Payment="3500" VATRate="VATX" VATSum="0" Weight="1" Amount="1" DelivAmount="1"/>
</Package>
<AddedService ServiceCode="2" Sum="12.34"/>
<AddedService ServiceCode="42" Sum="567.89"/>
</Order>
<Order Number="ORD-121122" Date="2020-03-04" DispatchNumber="111222334" TariffTypeCode="136" Weight="1.5" DeliverySum="265" DateLastChange="2020-03-06 05:30:00+03:00" CashOnDeliv="3792" CashOnDelivFact="3792" CashOnDelivType="cashless" deliveryMode="4" pvzCode="ENG1" deliveryVariant="PVZCDEK">
<SendCity Code="415" PostCode="610000" Name="Киров"/>
<RecCity Code="214" PostCode="413100" Name="Энгельс"/>
<Package Number="_" BarCode="1" Weight="1.5" VolumeWeight="1.3" SizeA="65" SizeB="10" SizeC="10">
<Item WareKey="00123" Comment="Item name" Cost="3500" Payment="3500" VATRate="VATX" VATSum="0" Weight="1" Amount="1" DelivAmount="1"/>
</Package>
<AddedService ServiceCode="2" Sum="12.34"/>
<AddedService ServiceCode="42" Sum="567.89"/>
</Order>
<Order Number="ORD-121123" Date="2020-03-05" DispatchNumber="111222335" TariffTypeCode="136" Weight="1.5" DeliverySum="265" DateLastChange="2020-03-07 06:30:00+05:00" CashOnDeliv="3792" CashOnDelivFact="3792" CashOnDelivType="cashless" deliveryMode="4" pvzCode="ENG1" deliveryVariant="PVZCDEK">
<SendCity Code="415" PostCode="610000" Name="Киров"/>
<RecCity Code="214" PostCode="413100" Name="Энгельс"/>
<Package Number="_" BarCode="1" Weight="1.5" VolumeWeight="1.3" SizeA="65" SizeB="10" SizeC="10">
<Item WareKey="00123" Comment="Item name" Cost="3500" Payment="3500" VATRate="VATX" VATSum="0" Weight="1" Amount="1" DelivAmount="1"/>
</Package>
<AddedService ServiceCode="2" Sum="12.34"/>
<AddedService ServiceCode="42" Sum="567.89"/>
</Order>
</InfoReport>

0 comments on commit 97f4388

Please sign in to comment.