/** @test */ public function should_run_closure_of_actions() { $this->product->action(function ($product) { $product->quantity(3); $product->freebie(true); $product->taxable(false); }); $this->assertEquals(3, $this->product->quantity); $this->assertTrue($this->product->freebie); $this->assertFalse($this->product->taxable); }
/** * Categorise a Product * * @param Product $product * @return void */ public function categorise(Product $product) { $product->taxable(false); }
/** * Add a product to the basket * * @param string $sku * @param string $name * @param Money $price * @param Closure $action * @return void */ public function add($sku, $name, Money $price, Closure $action = null) { $product = new Product($sku, $name, $price, $this->rate); if ($action) { $product->action($action); } $this->products->add($sku, $product); }
/** * Price: £25.00 * Rate: 0% * Quantity: 3 * Freebie: true * Taxable: true * Discount: £0 * Delivery: £0.99 * * @return Product */ public function nine() { $sku = '9'; $name = 'Gift Card'; $rate = new UnitedKingdomValueAddedTax(); $price = new Money(2500, new Currency('GBP')); $product = new Product($sku, $name, $price, $rate); $product->quantity(3); $product->freebie(true); $product->delivery(new Money(99, new Currency('GBP'))); return $product; }