From fca4da8b85a09b647b699d4d88f2dcb53f81a332 Mon Sep 17 00:00:00 2001 From: Florian de Vries Date: Fri, 13 Sep 2024 16:29:14 +0200 Subject: [PATCH] test: increase coverage --- .../Pdk/Context/Service/WcContextServiceTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Pdk/Context/Service/WcContextServiceTest.php b/tests/Unit/Pdk/Context/Service/WcContextServiceTest.php index 5d4634183..1a4776228 100644 --- a/tests/Unit/Pdk/Context/Service/WcContextServiceTest.php +++ b/tests/Unit/Pdk/Context/Service/WcContextServiceTest.php @@ -8,6 +8,7 @@ use MyParcelNL\Pdk\App\Cart\Contract\PdkCartRepositoryInterface; use MyParcelNL\Pdk\App\ShippingMethod\Model\PdkShippingMethod; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\Pdk\Settings\Model\CheckoutSettings; use MyParcelNL\WooCommerce\Tests\Uses\UsesMockWcPdkInstance; use WC_Product; use WC_Shipping_Flat_Rate; @@ -50,7 +51,11 @@ function add_product_to_cart(?int $shippingClassId = null) $contextService = Pdk::get(WcContextService::class); $cartRepository = Pdk::get(PdkCartRepositoryInterface::class); - $shippingClass = $input['shippingMethod']; + factory(CheckoutSettings::class) + ->withAllowedShippingMethods(['-1' => ['shipping_class:12']]) + ->store(); + + $shippingMethodClassName = $input['shippingMethod']; $shippingClassId = $input['shippingClassId'] ?? null; $shippingPrice = $input['shippingPrice'] ?? 0; $termAsArray = $input['termAsArray'] ?? false; @@ -75,10 +80,10 @@ function add_product_to_cart(?int $shippingClassId = null) ->make(); $pdkCart->shippingMethod = $pdkShippingMethod; - $shippingMethod = wpFactory($shippingClass) + $shippingMethod = wpFactory($shippingMethodClassName) ->withId(456); if ($shippingPrice) { - $shippingMethod->instance_settings["class_cost_$wpTerm->term_id"] = $shippingPrice; + $shippingMethod->withInstanceSettings(['class_cost_12' => $shippingPrice]); } $shippingMethod->store(); @@ -107,7 +112,7 @@ function add_product_to_cart(?int $shippingClassId = null) ], 'expected' => [ 'basePrice' => 0.0, - 'highestShippingClass' => '', + 'highestShippingClass' => 'shipping_class:12', ], ], 'product without shipping class' => [