Skip to content

Commit

Permalink
Throw exception if fixtures are wrongly configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Aug 23, 2019
1 parent 9887940 commit 1e69302
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ private function generateItems(OrderInterface $order): void
$products = $this->productRepository->findAll();
$generatedItems = [];

$shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($order->getChannel());
$shippingMethodsAvailable = count($shippingMethods) > 0;

for ($i = 0; $i < $numberOfItems; ++$i) {
/** @var ProductInterface $product */
$product = $this->faker->randomElement($products);
Expand All @@ -197,7 +194,6 @@ private function generateItems(OrderInterface $order): void
/** @var OrderItemInterface $item */
$item = $generatedItems[$variant->getCode()];
$this->orderItemQuantityModifier->modify($item, $item->getQuantity() + random_int(1, 5));
$variant->setShippingRequired($shippingMethodsAvailable);

continue;
}
Expand Down Expand Up @@ -238,10 +234,17 @@ private function selectShipping(OrderInterface $order): void
return;
}

$shippingMethod = $this
->faker
->randomElement($this->shippingMethodRepository->findEnabledForChannel($order->getChannel()))
;
$channel = $order->getChannel();
$shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($channel);

if (count($shippingMethods) === 0) {
throw new \InvalidArgumentException(sprintf(
'You have no shipping method available for the channel with code "%s", but they are required to proceed an order',
$channel->getCode()
));
}

$shippingMethod = $this->faker->randomElement($shippingMethods);

/** @var ChannelInterface $channel */
$channel = $order->getChannel();
Expand Down

0 comments on commit 1e69302

Please sign in to comment.