getQuantity() public method

public getQuantity ( )
コード例 #1
0
 /**
  * Test quantity setter, if quantity is negative, must returns a quantity of 1
  */
 public function testNegativeQuantity()
 {
     $basketElement = new BasketElement();
     $basketElement->setQuantity(50);
     $this->assertEquals(50, $basketElement->getQuantity());
     $basketElement->setQuantity(-50);
     $this->assertEquals(1, $basketElement->getQuantity());
 }
コード例 #2
0
 public function testBasket()
 {
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $provider->expects($this->once())->method('basketAddProduct')->will($this->returnValue(true));
     $provider->expects($this->once())->method('createBasketElement')->will($this->returnValue($basketElement = new BasketElement()));
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->once())->method('findOneBy')->will($this->returnValue($product));
     $pool = $this->getMock('Sonata\\Component\\Product\\Pool');
     $pool->expects($this->once())->method('getProvider')->will($this->returnValue($provider));
     $pool->expects($this->once())->method('getManager')->will($this->returnValue($manager));
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('reset');
     $basket->expects($this->once())->method('buildPrices');
     $orderElement = $this->getMock('Sonata\\Component\\Order\\OrderElementInterface');
     $orderElement->expects($this->exactly(2))->method('getProductType');
     $orderElement->expects($this->exactly(1))->method('getProductId')->will($this->returnValue(2));
     $orderElement->expects($this->exactly(1))->method('getOptions')->will($this->returnValue(array()));
     $orderElement->expects($this->exactly(1))->method('getQuantity')->will($this->returnValue(2));
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->once())->method('getOrderElements')->will($this->returnValue(array($orderElement)));
     $order->expects($this->once())->method('getCustomer')->will($this->returnValue($customer));
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->expects($this->once())->method('getCurrency')->will($this->returnValue($currency));
     $transformer = new OrderTransformer($pool);
     $transformer->transformIntoBasket($order, $basket);
     $this->assertEquals(2, $basketElement->getQuantity());
 }