diff --git a/src/Cart.php b/src/Cart.php index b6b09e8..c756827 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -52,6 +52,9 @@ public function getDriver(): CartDriver return $this->driver; } + /** + * @internal For testing purposes only. Not intended for production use. + */ public function fake(): CartFactory { $this->driver = new NullDriver($this->driver->getSessionKey()); @@ -78,27 +81,30 @@ public function assertCount(int $count): void public function assertTotalQuantity(int|float $quantity): void { - Assert::assertEquals( + Assert::assertEqualsWithDelta( $quantity, - $this->getTotalQuantity(), + (float) $this->getTotalQuantity(), + 0.0001, "Failed asserting that cart total quantity is [{$quantity}]." ); } public function assertSubTotal(float $amount): void { - Assert::assertEquals( + Assert::assertEqualsWithDelta( $amount, - $this->getSubTotal(false), + (float) $this->getSubTotal(false), + 0.0001, "Failed asserting that cart subtotal is [{$amount}]." ); } public function assertTotal(float $amount): void { - Assert::assertEquals( + Assert::assertEqualsWithDelta( $amount, - $this->getTotal(), + (float) $this->getTotal(), + 0.0001, "Failed asserting that cart total is [{$amount}]." ); } diff --git a/tests/Unit/Testing/CartFactoryTest.php b/tests/Unit/Testing/CartFactoryTest.php index e57a774..441601f 100644 --- a/tests/Unit/Testing/CartFactoryTest.php +++ b/tests/Unit/Testing/CartFactoryTest.php @@ -58,6 +58,14 @@ function makeCartForFactory(): Cart expect(array_unique($ids))->toHaveCount(3); }); + test('consecutive withItems calls produce unique IDs', function () { + $this->factory->withItems(2)->withItems(2); + + $ids = $this->cart->getContent()->keys()->toArray(); + expect(array_unique($ids))->toHaveCount(4); + expect($this->cart->getContent()->count())->toBe(4); + }); + test('withCoupon adds a coupon condition to the cart', function () { $coupon = new class extends \Wearepixel\Cart\Coupons\Coupon { protected string $code = 'SAVE10';