Sonata\Component\Basket\Loader::getBasket PHP Метод

getBasket() публичный Метод

Get the basket.
public getBasket ( ) : Sonata\Component\Basket\BasketInterface
Результат Sonata\Component\Basket\BasketInterface
    public function getBasket()
    {
        if (!$this->basket) {
            try {
                $this->basket = $this->basketFactory->load($this->customerSelector->get());
            } catch (\Exception $e) {
                // something went wrong while loading the basket
                throw $e;
            }
        }
        return $this->basket;
    }

Usage Example

Пример #1
0
 /**
  * @expectedException        RuntimeException
  */
 public function testExceptionLoadBasket()
 {
     $this->setExpectedException('RuntimeException');
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $basketFactory = $this->getMock('Sonata\\Component\\Basket\\BasketFactoryInterface');
     $basketFactory->expects($this->once())->method('load')->will($this->returnCallback(function () {
         throw new \RuntimeException();
     }));
     $customerSelector = $this->getMock('Sonata\\Component\\Customer\\CustomerSelectorInterface');
     $customerSelector->expects($this->once())->method('get')->will($this->returnValue($customer));
     $loader = new Loader($basketFactory, $customerSelector);
     $loader->getBasket();
 }