Docs / Laravel Cart / Testing

Testing

Cart::fake()

Cart::fake() replaces the active driver with an in-memory NullDriver and returns a CartFactory for seeding test state.

use Wearepixel\Cart\Cart; // In your test $factory = app('cart')->fake(); $factory->withItems(3); $factory->withCondition(new CartCondition(['name' => 'GST', 'type' => 'tax', 'value' => '10%', 'target' => 'subtotal'])); // Or chain it app('cart')->fake()->withItems(2)->withCondition($condition);

Assertion Methods

After fake(), the Cart instance exposes assertion methods:

$cart = app('cart'); $cart->fake(); $cart->add(1, 'Widget', 50.00, 2); $cart->assertContains(1); // item exists $cart->assertCount(1); // 1 distinct item $cart->assertTotalQuantity(2); // 2 units $cart->assertSubTotal(100.00); // subtotal $cart->assertTotal(100.00); // total $cart->assertNotEmpty(); // cart has items $cart->assertEmpty(); // cart is empty $cart->assertConditionApplied('GST'); // condition present
Discovery Call

One call.
We'll both know.

An hour to walk through your project, ask the hard questions, and work out honestly if we're the right team for it.

  • One call per day - it gets our full attention
  • Australia's only Laravel Premier Partner
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen