From 8cfd36e4b66f8aa0279447e21dee6be05243b1ec Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Thu, 20 Dec 2018 16:10:24 +0900 Subject: [PATCH] DeliveryResponse with a courier call added --- src/Responses/DeliveryResponse.php | 10 +++++++++ .../Deserialization/DeliveryResponseTest.php | 22 +++++++++++++++++++ .../data/DeliveryRequestWithCallSuccess.xml | 1 + 3 files changed, 33 insertions(+) create mode 100644 tests/Fixtures/data/DeliveryRequestWithCallSuccess.xml diff --git a/src/Responses/DeliveryResponse.php b/src/Responses/DeliveryResponse.php index e9ba050..f48ebd3 100644 --- a/src/Responses/DeliveryResponse.php +++ b/src/Responses/DeliveryResponse.php @@ -93,6 +93,16 @@ public function getRequests() return $this->requests; } + /** + * @return \Pipeline\Standard|CallCourier[] + */ + public function getCalls() + { + return fromArray($this->calls)->filter(function (CallCourier $call) { + return $call->getNumber() !== ''; + }); + } + /** * @JMS\PostDeserialize * diff --git a/tests/Deserialization/DeliveryResponseTest.php b/tests/Deserialization/DeliveryResponseTest.php index 8f00521..3ee1d51 100644 --- a/tests/Deserialization/DeliveryResponseTest.php +++ b/tests/Deserialization/DeliveryResponseTest.php @@ -124,6 +124,28 @@ public function test_missing_courier_call() } } + public function test_successful_request_with_call() + { + $response = $this->getSerializer()->deserialize(FixtureLoader::load('DeliveryRequestWithCallSuccess.xml'), DeliveryResponse::class, 'xml'); + + /** @var $response DeliveryResponse */ + $this->assertInstanceOf(DeliveryResponse::class, $response); + + $this->assertCount(1, $response->getOrders()); + + foreach ($response->getOrders() as $order) { + $this->assertSame('TESTING-123', $order->getNumber()); + $this->assertSame('110000123', $order->getDispatchNumber()); + } + + $this->assertCount(1, $response->getMessages()); + $this->assertCount(1, $response->getCalls()); + + foreach ($response->getCalls() as $call) { + $this->assertSame('22022033', $call->getNumber()); + } + } + public function test_it_serializes_to_empty_json() { $response = new DeliveryResponse(); diff --git a/tests/Fixtures/data/DeliveryRequestWithCallSuccess.xml b/tests/Fixtures/data/DeliveryRequestWithCallSuccess.xml new file mode 100644 index 0000000..d51218d --- /dev/null +++ b/tests/Fixtures/data/DeliveryRequestWithCallSuccess.xml @@ -0,0 +1 @@ +e5341942156970a92