From 07603934ba2935d08f1b18c93f737b30e312ddf3 Mon Sep 17 00:00:00 2001 From: Ruslan Efanov Date: Tue, 6 Jul 2021 16:46:08 +0300 Subject: [PATCH] fix tests --- .../retailcrm/lib/service/OrderManager.php | 9 ++++++-- tests/system/lib/service/OrderManagerTest.php | 23 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/upload/system/library/retailcrm/lib/service/OrderManager.php b/src/upload/system/library/retailcrm/lib/service/OrderManager.php index a78ecfb..54a4647 100644 --- a/src/upload/system/library/retailcrm/lib/service/OrderManager.php +++ b/src/upload/system/library/retailcrm/lib/service/OrderManager.php @@ -172,10 +172,15 @@ class OrderManager { } } - private function checkExistCustomer(string $customerExternalId): bool + /** + * @param $customerExternalId + * + * @return bool + */ + private function checkExistCustomer($customerExternalId) { $result = $this->api->customersGet($customerExternalId); - return $result && $result->isSuccessful() && $result->offsetExists('customers'); + return $result && $result->isSuccessful() && $result->offsetExists('customer'); } } diff --git a/tests/system/lib/service/OrderManagerTest.php b/tests/system/lib/service/OrderManagerTest.php index dd809b9..0eb06fc 100644 --- a/tests/system/lib/service/OrderManagerTest.php +++ b/tests/system/lib/service/OrderManagerTest.php @@ -10,11 +10,32 @@ class OrderManagerTest extends TestCase { public function testCreateOrderWithCustomer() { $proxy = $this->getMockBuilder(\RetailcrmProxy::class) ->disableOriginalConstructor() - ->setMethods(['ordersCreate']) + ->setMethods(['ordersCreate','customersGet']) ->getMock(); $proxy->expects($this->once())->method('ordersCreate'); + $proxy->expects($this->once()) + ->method('customersGet') + ->willReturn(new \RetailcrmApiResponse( + 200, + json_encode( + [ + 'success' => true, + 'pagination' => [ + 'limit'=> 20, + 'totalCount' => 0, + 'currentPage' => 1, + 'totalPageCount' => 0 + ], + 'customer' => [ + 'id' => 1, + 'externalId' => 1 + ] + ] + ) + )); + $order_manager = $this->getOrderManager($proxy); $orderCheckoutModel = $this->loadModel('checkout/order');