Skip to content

Commit

Permalink
Fix - Method remove into ShippingModifiers (#1600)
Browse files Browse the repository at this point in the history
The ShippingModifiers store modifiers in collection, the method remove
tried to remove the key that didn't exist.

---------

Co-authored-by: Glenn Jacobs <glenn@neondigital.co.uk>
  • Loading branch information
lguichard and glennjacobs committed May 6, 2024
1 parent 6e0752a commit 98474d9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/Base/ShippingModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
61 changes: 61 additions & 0 deletions packages/core/tests/Unit/Base/ShippingModifiersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Lunar\Tests\Unit\Base;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Lunar\Base\ShippingModifier;
use Lunar\Base\ShippingModifiers;
use Lunar\Models\Cart;
use Lunar\Models\Currency;
use Lunar\Tests\TestCase;

class ShippingModifiersTest extends TestCase
{
use RefreshDatabase;

private Cart $cart;

private ShippingModifiers $shippingModifiers;

private ShippingModifier $class;

public function setUp(): void
{
parent::setUp();

$currency = Currency::factory()->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());
}

}

0 comments on commit 98474d9

Please sign in to comment.