diff --git a/src/Testing/CartFactory.php b/src/Testing/CartFactory.php index 9de5429..bc8cc78 100644 --- a/src/Testing/CartFactory.php +++ b/src/Testing/CartFactory.php @@ -14,7 +14,8 @@ public function __construct(private Cart $cart) {} public function withItems(int $count): static { - for ($i = 1; $i <= $count; $i++) { + $start = $this->cart->getContent()->count() + 1; + for ($i = $start; $i < $start + $count; $i++) { $this->cart->add($i, "Test Item {$i}", 10.00, 1); } diff --git a/tests/Unit/Testing/CartFactoryTest.php b/tests/Unit/Testing/CartFactoryTest.php index 7127cb5..e57a774 100644 --- a/tests/Unit/Testing/CartFactoryTest.php +++ b/tests/Unit/Testing/CartFactoryTest.php @@ -57,4 +57,18 @@ function makeCartForFactory(): Cart expect(array_unique($ids))->toHaveCount(3); }); + + test('withCoupon adds a coupon condition to the cart', function () { + $coupon = new class extends \Wearepixel\Cart\Coupons\Coupon { + protected string $code = 'SAVE10'; + protected string $value = '-10%'; + protected string $target = 'subtotal'; + + public function isValid(): bool { return true; } + }; + + $this->factory->withCoupon($coupon); + + expect($this->cart->getCondition('SAVE10'))->not->toBeNull(); + }); });