feat: add Cart::fake(), assertion methods, and CartFactory

Adds Cart::fake() which swaps the active driver to NullDriver and returns
a CartFactory fluent test builder. Adds assertion methods (assertContains,
assertCount, assertTotalQuantity, assertSubTotal, assertTotal,
assertConditionApplied, assertEmpty, assertNotEmpty) to Cart for use in
tests. CartFactory provides withItems(), withCondition(), and withCoupon()
as chainable helpers for seeding cart state.
This commit is contained in:
Joel Male
2026-05-27 21:31:54 +10:00
parent c3a734bd7f
commit 61863e0bd5
4 changed files with 287 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Wearepixel\Cart\Testing;
use Wearepixel\Cart\Cart;
use Wearepixel\Cart\CartCondition;
use Wearepixel\Cart\Coupons\Coupon;
class CartFactory
{
public function __construct(private Cart $cart) {}
public function withItems(int $count): static
{
for ($i = 1; $i <= $count; $i++) {
$this->cart->add($i, "Test Item {$i}", 10.00, 1);
}
return $this;
}
public function withCondition(CartCondition $condition): static
{
$this->cart->condition($condition);
return $this;
}
public function withCoupon(Coupon $coupon): static
{
$this->cart->coupon($coupon);
return $this;
}
}