/** * Test total item numbers. * * @dataProvider dataGetTotalItemNumber */ public function testGetTotalItemNumber(array $quantities, $total) { $cartLines = new ArrayCollection([]); foreach ($quantities as $quantity) { if ($quantity > 0) { $cartLine = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartLineInterface'); $cartLine->method('getQuantity')->will($this->returnValue($quantity)); $cartLines->add($cartLine); } } $cart = new Cart(); $cart->setCartLines($cartLines); $this->assertEquals($total, $cart->getTotalItemNumber()); }
/** * addLine with empty cart. * * @group cart */ public function testAddLineInEmptyCart() { $cart = new Cart(); $cart->setCartLines(new ArrayCollection()); $this->assertEquals(0, $cart->getTotalItemNumber()); $purchaseable = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface'); $this->cartLineFactory->expects($this->exactly(1))->method('create')->will($this->returnValue(new CartLine())); $this->cartManager->addPurchasable($cart, $purchaseable, 1); $this->assertCount(1, $cart->getCartLines()); $this->assertEquals(1, $cart->getTotalItemNumber()); }