function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, FlashBagInterface $flashBag, StockableInterface $stockable) { $stockable->getOnHand()->willReturn('30'); $stockable->getInventoryName()->willReturn('Inventory Name'); $event->getException()->willReturn(new InsufficientStockException($stockable->getWrappedObject(), 42)); $event->setResponse(Argument::type(RedirectResponse::class))->shouldBeCalled(); $translator->trans('sylius.checkout.out_of_stock', ['%quantity%' => '30', '%name%' => 'Inventory Name'], 'flashes')->willReturn('message translated'); $flashBag->add('notice', 'message translated')->shouldBeCalled(); $session->getBag('flashes')->willReturn($flashBag); $router->generate('redirect_to_url')->willReturn('url'); $this->onKernelException($event); }
function it_performs_kernel_exception_action_successfully(UrlGeneratorInterface $router, SessionInterface $session, TranslatorInterface $translator, GetResponseForExceptionEvent $event, InsufficientStockException $exception, FlashBagInterface $flashBag, StockableInterface $stockable) { $stockable->getOnHand()->shouldBeCalled()->willReturn('30'); $stockable->getInventoryName()->shouldBeCalled()->willReturn('Inventory Name'); $exception->getStockable()->shouldBeCalledTimes(2)->willReturn($stockable); $event->getException()->shouldBeCalled()->willReturn($exception); $event->setResponse(Argument::type('Symfony\\Component\\HttpFoundation\\RedirectResponse'))->shouldBeCalled(); $translator->trans('sylius.checkout.out_of_stock', array('%quantity%' => '30', '%name%' => 'Inventory Name'), 'flashes')->shouldBeCalled()->willReturn('message translated'); $flashBag->add('notice', 'message translated')->shouldBeCalled(); $session->getBag('flashes')->shouldBeCalled()->willReturn($flashBag); $router->generate('redirect_to_url')->shouldBeCalled()->willReturn('url'); $this->onKernelException($event)->shouldReturn(null); }
/** * @param StockableInterface $stockable * @param int $quantity * @param \Exception|null $previousException */ public function __construct(StockableInterface $stockable, $quantity, \Exception $previousException = null) { $this->stockable = $stockable; parent::__construct(sprintf('Only %d %s(s) on hand, %d requested.', $stockable->getOnHand(), $stockable->getInventoryName(), $quantity), 0, $previousException); }
/** * {@inheritdoc} */ public function getInventoryName() { return $this->stockable->getInventoryName(); }
function it_returns_its_stockable_name(StockableInterface $stockable) { $stockable->getInventoryName()->willReturn('[IPHONE5] iPhone 5'); $this->setStockable($stockable); $this->getInventoryName()->shouldReturn('[IPHONE5] iPhone 5'); }