From d3019c11f53ddcc25715ac4a7b5aa951368209f7 Mon Sep 17 00:00:00 2001 From: Steve Tentrop Date: Mon, 19 Aug 2024 13:02:07 +0200 Subject: [PATCH] fix tests --- src/Services/CheckoutService.php | 19 +++++++++++-------- .../Services/CheckoutServiceShippingTest.php | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Services/CheckoutService.php b/src/Services/CheckoutService.php index 428f59ff0..ffe2b1106 100644 --- a/src/Services/CheckoutService.php +++ b/src/Services/CheckoutService.php @@ -409,7 +409,7 @@ public function getMethodOfPaymentId() * @var PaymentMethod $methodOfPayment */ foreach ($methodOfPaymentList as $methodOfPaymentKey => $methodOfPayment) { - if($basket->id > 0 && $basketAmount <= 0 && $methodOfPayment->paymentKey !== self::ALREADY_PAID_PAYMENT_KEY) { + if ($basket->id > 0 && $basketAmount <= 0 && $methodOfPayment->paymentKey !== self::ALREADY_PAID_PAYMENT_KEY) { unset($methodOfPaymentList[$methodOfPaymentKey]); continue; } @@ -421,7 +421,7 @@ public function getMethodOfPaymentId() if ($methodOfPaymentID === null || !$methodOfPaymentValid) { $methodOfPayment = array_shift($methodOfPaymentList); - if(!is_null($methodOfPayment)) { + if (!is_null($methodOfPayment)) { $methodOfPaymentID = $methodOfPayment->id; } @@ -461,9 +461,11 @@ public function preparePayment(): array $basketService = pluginApp(BasketService::class); $validateCheckoutEvent = $this->checkout->validateCheckout(); - if ($validateCheckoutEvent instanceof ValidateCheckoutEvent && !empty( + if ( + $validateCheckoutEvent instanceof ValidateCheckoutEvent && !empty( $validateCheckoutEvent->getErrorKeysList() - )) { + ) + ) { $dispatcher = pluginApp(Dispatcher::class); if ($dispatcher instanceof Dispatcher) { $dispatcher->fire(pluginApp(AfterBasketChanged::class), []); @@ -533,12 +535,12 @@ function () { $methodOfPaymentList = []; $basket = $this->basketRepository->load(); if ($basket->basketAmount <= 0 && $basket->id > 0) { - $methodOfPaymentList = array_filter($methodOfPaymentListOriginal, function($methodOfPayment) { + $methodOfPaymentList = array_filter($methodOfPaymentListOriginal, function ($methodOfPayment) { return $methodOfPayment->paymentKey === self::ALREADY_PAID_PAYMENT_KEY; }); } - if(!count($methodOfPaymentList)) { + if (!count($methodOfPaymentList)) { $methodOfPaymentList = $methodOfPaymentListOriginal; } @@ -749,10 +751,11 @@ public function getShippingProfileId(): int * Set the ID of the current shipping profile. * * @param int $shippingProfileId Id of the shipping profile to select. + * @param bool $force Force to set the shipping profile id. */ - public function setShippingProfileId(int $shippingProfileId) + public function setShippingProfileId(int $shippingProfileId, bool $force = false) { - $this->checkout->setShippingProfileId($shippingProfileId); + $this->checkout->setShippingProfileId($shippingProfileId, $force); } /** diff --git a/tests/Unit/Services/CheckoutServiceShippingTest.php b/tests/Unit/Services/CheckoutServiceShippingTest.php index 493085170..968c6c75c 100644 --- a/tests/Unit/Services/CheckoutServiceShippingTest.php +++ b/tests/Unit/Services/CheckoutServiceShippingTest.php @@ -210,7 +210,10 @@ public function it_gets_the_right_shipping_profiles($shippingList) $checkoutServiceMock = Mockery::mock(CheckoutService::class); $this->replaceInstanceByMock(CheckoutService::class, $checkoutServiceMock); - $checkoutServiceMock->shouldReceive('setShippingProfileId')->once()->andReturnSelf(); + $checkoutServiceMock->shouldReceive('setShippingProfileId')->with( + $shippingList[0]['parcelServicePresetId'], + true + ); $this->applicationMock->shouldReceive('getWebstoreId')->andReturn(1);