public function testAvailableMethods() { $deliveryMethod_low = new ServiceDelivery(); $deliveryMethod_low->setCode('ups_low'); $deliveryMethod_low->setEnabled(true); $deliveryMethod_low->setPriority(1); $deliveryMethod_high = new ServiceDelivery(); $deliveryMethod_high->setCode('ups_high'); $deliveryMethod_high->setEnabled(true); $deliveryMethod_high->setPriority(2); $deliveryMethod_high_bis = new ServiceDelivery(); $deliveryMethod_high_bis->setCode('ups_high_bis'); $deliveryMethod_high_bis->setEnabled(true); $deliveryMethod_high_bis->setPriority(2); $deliveryPool = new DeliveryPool(); $deliveryPool->addMethod($deliveryMethod_low); $deliveryPool->addMethod($deliveryMethod_high); $deliveryPool->addMethod($deliveryMethod_high_bis); $productPool = new ProductPool(); $productDelivery_low = $this->getMock('Sonata\\Component\\Product\\DeliveryInterface'); $productDelivery_low->expects($this->any())->method('getCode')->will($this->returnValue('ups_low')); $productDelivery_high = $this->getMock('Sonata\\Component\\Product\\DeliveryInterface'); $productDelivery_high->expects($this->any())->method('getCode')->will($this->returnValue('ups_high')); $productDelivery_high_bis = $this->getMock('Sonata\\Component\\Product\\DeliveryInterface'); $productDelivery_high_bis->expects($this->any())->method('getCode')->will($this->returnValue('ups_high_bis')); $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface'); $product->expects($this->once())->method('getDeliveries')->will($this->returnValue(array($productDelivery_low, $productDelivery_high, $productDelivery_high_bis))); $basketElement = $this->getMock('Sonata\\Component\\Basket\\BasketElementInterface'); $basketElement->expects($this->once())->method('getProduct')->will($this->returnValue($product)); $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface'); $basket->expects($this->once())->method('getBasketElements')->will($this->returnValue(array($basketElement))); $address = $this->getMock('Sonata\\Component\\Customer\\AddressInterface'); $selector = new Selector($deliveryPool, $productPool); $selector->setLogger($this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface')); $instances = $selector->getAvailableMethods($basket, $address); $this->assertCount(3, $instances); $this->assertEquals($instances[0]->getCode(), 'ups_high_bis'); $this->assertEquals($instances[1]->getCode(), 'ups_high'); $this->assertEquals($instances[2]->getCode(), 'ups_low'); }