mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user