/** * Test checkout class */ public function testCheckout() { $promotionalRules = new PromotionalRuleContainer(); $checkout = new Checkout($promotionalRules); $expected = array(); $checkout->scan($this->getItem001()); $expected[$this->getItem001()->getCode()] = $this->getItem001(); $this->assertSame($expected, $checkout->getItems()); $checkout->scan($this->getItem002()); $expected[$this->getItem002()->getCode()] = $this->getItem002(); $this->assertSame($expected, $checkout->getItems()); $total = 0; /** @var Item $item */ foreach ($expected as $item) { $total += $item->getPrice(); } $this->assertEquals($total, $checkout->total()); }
<?php use Babylon\Checkout\Checkout; require 'vendor/autoload.php'; require 'src/Babylon/configure.php'; $co = new Checkout($promotionalRuleContainer); $co->scan($item001); $co->scan($item002); $co->scan($item001); $co->scan($item003); $price = $co->total(); echo 'Price expected : ' . $price;