From 617f1673b83709c838e7dbc48bf1cf44f04e7f17 Mon Sep 17 00:00:00 2001 From: Lionel Guichard Date: Fri, 1 Mar 2024 11:28:47 +0100 Subject: [PATCH 1/2] Update ShippingModifiers.php --- packages/core/src/Base/ShippingModifiers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/Base/ShippingModifiers.php b/packages/core/src/Base/ShippingModifiers.php index 3f1b06e3db..d89fda1cf0 100644 --- a/packages/core/src/Base/ShippingModifiers.php +++ b/packages/core/src/Base/ShippingModifiers.php @@ -48,6 +48,6 @@ public function add($modifier) */ public function remove($modifier) { - $this->modifiers->forget($modifier); + $this->modifiers = $this->modifiers->reject(fn ($value) => $value == $modifier); } } From 8c882b33fe528de71c629f3e78da6b14c0ae3665 Mon Sep 17 00:00:00 2001 From: Lionel Guichard Date: Fri, 1 Mar 2024 15:17:15 +0100 Subject: [PATCH 2/2] Add tests --- .../tests/Unit/Base/ShippingModifiersTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 packages/core/tests/Unit/Base/ShippingModifiersTest.php diff --git a/packages/core/tests/Unit/Base/ShippingModifiersTest.php b/packages/core/tests/Unit/Base/ShippingModifiersTest.php new file mode 100644 index 0000000000..4aa2cb1dd5 --- /dev/null +++ b/packages/core/tests/Unit/Base/ShippingModifiersTest.php @@ -0,0 +1,61 @@ +create([ + 'decimal_places' => 2, + ]); + + $this->cart = Cart::factory()->create([ + 'currency_id' => $currency->id, + ]); + + $this->class = new class extends ShippingModifier + { + public function handle(Cart $cart) + { + // + } + }; + + $this->shippingModifiers = new ShippingModifiers(); + } + + /** @test */ + public function can_add_modifier() + { + $this->shippingModifiers->add($this->class::class); + + $this->assertCount(1, $this->shippingModifiers->getModifiers()); + } + + + public function can_remove_modifier() + { + $this->shippingModifiers->remove($this->class::class); + + $this->assertCount(0, $this->shippingModifiers->getModifiers()); + } + +}