/** * @Transform :order */ public function getOrderByNumber($orderNumber) { $orderNumber = $this->getOrderNumber($orderNumber); $order = $this->orderRepository->findOneBy(['number' => $orderNumber]); Assert::notNull($order, sprintf('Cannot find order with number %s', $orderNumber)); return $order; }
/** * @When I delete the order :orderNumber */ public function iDeleteTheOrder($orderNumber) { /** @var OrderInterface $order */ $order = $this->orderRepository->findOneBy(['number' => $orderNumber]); if (null === $order) { throw new \InvalidArgumentException(sprintf('Order with %s number was not found in an order repository', $orderNumber)); } $this->orderRepository->remove($order); }
function it_throws_an_exception_when_order_is_not_found(OrderRepositoryInterface $orderRepository) { $orderRepository->findOneBy(['number' => '#00000000'])->willReturn(null); $this->shouldThrow(new \InvalidArgumentException('Order with #00000000 number was not found in an order repository'))->during('iDeleteTheOrder', ['#00000000']); }
/** * @Then /^([^"]+) should not exist in the registry$/ */ public function orderShouldNotExistInTheRegistry(OrderInterface $order) { /** @var OrderInterface $order */ $order = $this->orderRepository->findOneBy(['number' => $order->getNumber()]); expect($order)->toBe(null); }
function it_throws_an_exception_if_order_still_exists(OrderRepositoryInterface $orderRepository, OrderInterface $order) { $order->getNumber()->willReturn('#00000000'); $orderRepository->findOneBy(['number' => '#00000000'])->willReturn($order); $this->shouldThrow(NotEqualException::class)->during('orderShouldNotExistInTheRegistry', [$order]); }