Skip to content

Commit

Permalink
changed method in AddressOrderHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Aug 6, 2020
1 parent a508bc1 commit 12c412e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function __construct(
/**
* @Given I am at the checkout addressing step
* @When I complete the shipping step
* @When I complete the payment step
*/
public function intentionallyLeftBlank(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ default:
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.shop_api_security
- sylius.behat.context.setup.user
- sylius.behat.context.setup.customer

- sylius.behat.context.api.admin.managing_orders

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ public function __invoke(AddressOrder $addressOrder): OrderInterface
sprintf('Order with %s token cannot be addressed.', $tokenValue)
);

/** @var CustomerInterface|null $customer */
$customer = $this->provideCustomer($order, $addressOrder->email);

if (null === $order->getCustomer()) {
$order->setCustomer($customer);
$order->setCustomer($this->provideCustomerByEmail($addressOrder->email));
}

$order->setBillingAddress($addressOrder->billingAddress);
Expand All @@ -83,20 +80,16 @@ public function __invoke(AddressOrder $addressOrder): OrderInterface
$stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS);

$this->manager->persist($order);
$this->manager->flush();

return $order;
}

private function provideCustomer(OrderInterface $order, ?string $email): CustomerInterface
private function provideCustomerByEmail(?string $email): CustomerInterface
{
$customer = $order->getCustomer();
if (null === $customer) {
$customer = $this->customerRepository->findOneBy(['email' => $email]);
}
if (null === $customer) {
Assert::notNull($email, sprintf('Visitor should provide an email.'));
Assert::notNull($email, sprintf('Visitor should provide an email.'));

$customer = $this->customerRepository->findOneBy(['email' => $email]);
if (null === $customer) {
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function let(
ObjectManager $manager,
StateMachineFactoryInterface $stateMachineFactory
): void {
$this->beConstructedWith($orderRepository,$customerRepository, $customerFactory, $manager, $stateMachineFactory);
$this->beConstructedWith($orderRepository, $customerRepository, $customerFactory, $manager, $stateMachineFactory);
}

function it_handles_addressing_an_order_without_provided_shipping_address(
Expand Down Expand Up @@ -100,7 +100,6 @@ function it_handles_addressing_an_order_for_visitor(
$stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled();

$manager->persist($order)->shouldBeCalled();
$manager->flush()->shouldBeCalled();

$this($addressOrder);
}
Expand Down Expand Up @@ -140,7 +139,6 @@ function it_handles_addressing_an_order_for_logged_in_shop_user(
$stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled();

$manager->persist($order)->shouldBeCalled();
$manager->flush()->shouldBeCalled();

$this($addressOrder);
}
Expand Down Expand Up @@ -180,7 +178,6 @@ function it_handles_addressing_an_order_for_not_logged_in_shop_user(
$stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled();

$manager->persist($order)->shouldBeCalled();
$manager->flush()->shouldBeCalled();

$this($addressOrder);
}
Expand Down

0 comments on commit 12c412e

Please sign in to comment.