diff --git a/composer.json b/composer.json index 44c9685..6396812 100644 --- a/composer.json +++ b/composer.json @@ -59,4 +59,4 @@ "pestphp/pest-plugin": true } } -} \ No newline at end of file +} diff --git a/tests/Unit/DatabaseCartTest.php b/tests/Unit/DatabaseCartTest.php index a344a57..1a232f0 100644 --- a/tests/Unit/DatabaseCartTest.php +++ b/tests/Unit/DatabaseCartTest.php @@ -159,4 +159,23 @@ expect($this->cart->getContent()->count())->toEqual(0, 'Cart content should be 0'); expect(MockCartModel::all()->count())->toEqual(0, 'The carts database table should have 0 rows'); }); + + test('can clear cart conditions after clearing the cart', function () { + $condition = new CartCondition([ + 'name' => '10% Off', + 'type' => 'coupon', + 'target' => 'subtotal', + 'value' => '-10%', + ]); + + $this->cart->add(1, 'Sample Item', 100.99, 2, []); + $this->cart->condition($condition); + + $this->cart->clear(); + + // This was throwing "Call to a member function save() on array" + // because clear() replaced $this->session with a plain array + expect(fn () => $this->cart->clearCartConditions())->not->toThrow(Error::class); + expect($this->cart->getConditions())->toBeEmpty(); + }); });