Skip to content

Commit

Permalink
fix composer.json api platform, tests for api mailing added
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Nov 12, 2020
1 parent dc76ef8 commit cac900e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Receiving confirmation email after finalizing checkout
When I confirm my order
Then an email with the summary of order placed by "john@example.com" should be sent to him

@ui @email
@ui @email @api
Scenario: Receiving confirmation email after finalizing checkout in different locale than the default one
Given I have product "Sig Sauer P226" in the cart
And I have proceeded through checkout process in the "Polish (Poland)" locale with email "john@example.com"
Expand Down
87 changes: 36 additions & 51 deletions src/Sylius/Behat/Context/Setup/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod;
use Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod;
use Sylius\Component\Core\Model\AddressInterface;
<<<<<<< HEAD
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
Expand Down Expand Up @@ -62,28 +61,30 @@ public function __construct(
$this->paymentMethodRepository = $paymentMethodRepository;
$this->commandBus = $commandBus;
$this->addressFactory = $addressFactory;
=======
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Symfony\Component\Messenger\MessageBusInterface;
$this->sharedStorage = $sharedStorage;
}

final class CheckoutContext implements Context
{
/** @var MessageBusInterface */
private $commandBus;
/**
* @Given I have proceeded through checkout process in the :localeCode locale with email :email
*/
public function iHaveProceededThroughCheckoutProcessInTheLocaleWithEmail(string $localeCode, string $email)
{
$cartToken = $this->sharedStorage->get('cart_token');

/** @var SharedStorageInterface */
private $sharedStorage;
/** @var OrderInterface|null $cart */
$cart = $this->orderRepository->findCartByTokenValue($cartToken);
Assert::notNull($cart);

public function __construct(MessageBusInterface $commandBus, SharedStorageInterface $sharedStorage)
{
$this->commandBus = $commandBus;
>>>>>>> 7f2cb5abed... [API] Order confirmation email sending
$this->sharedStorage = $sharedStorage;
$cart->setLocaleCode($localeCode);

$command = new AddressOrder($email, $this->getDefaultAddress());
$command->setOrderTokenValue($cartToken);
$this->commandBus->dispatch($command);

$this->completeCheckout($cart);
}

/**
<<<<<<< HEAD
* @Given I have proceeded through checkout process
*/
public function iHaveProceededThroughCheckoutProcess(): void
Expand All @@ -94,62 +95,46 @@ public function iHaveProceededThroughCheckoutProcess(): void
$cart = $this->orderRepository->findCartByTokenValue($cartToken);
Assert::notNull($cart);

$command = new AddressOrder('rich@sylius.com', $this->getDefaultAddress());
$command->setOrderTokenValue($cartToken);
$this->commandBus->dispatch($command);

$this->completeCheckout($cart);
}

private function getDefaultAddress(): AddressInterface
{
/** @var AddressInterface $address */
$address = $this->addressFactory->createNew();

$address->setCity('New York');
$address->setStreet('Wall Street');
$address->setPostcode('00-001');
$address->setCountryCode('US');
$address->setFirstName('Richy');
$address->setLastName('Rich');

$command = new AddressOrder('rich@sylius.com', $address);
$command->setOrderTokenValue($cartToken);
$this->commandBus->dispatch($command);
return $address;
}

private function completeCheckout(OrderInterface $order): void
{
$command = new ChooseShippingMethod($this->shippingMethodRepository->findOneBy([])->getCode());
$command->setOrderTokenValue($cartToken);
$command->setOrderTokenValue($order->getTokenValue());

/** @var ShipmentInterface $shipment */
$shipment = $cart->getShipments()->first();
$shipment = $order->getShipments()->first();

$command->setSubresourceId((string) $shipment->getId());
$this->commandBus->dispatch($command);

$command = new ChoosePaymentMethod($this->paymentMethodRepository->findOneBy([])->getCode());
$command->setOrderTokenValue($cartToken);
$command->setOrderTokenValue($order->getTokenValue());

/** @var PaymentInterface $payment */
$payment = $cart->getPayments()->first();
$payment = $order->getPayments()->first();
$command->setSubresourceId((string) $payment->getId());

$this->commandBus->dispatch($command);
=======
* @Given /^I have completed addressing step with email "([^"]+)" and ("[^"]+" based billing address)$/
*/
public function iHaveCompletedAddressingStepWithEmail(string $email, AddressInterface $address): void
{
$addressOrder = new AddressOrder($email, $address);

$addressOrder->setOrderTokenValue($this->sharedStorage->get('cart_token'));

$this->commandBus->dispatch($addressOrder);
}

/**
* @Given I have proceeded order with :shippingMethod shipping method and :paymentMethod payment
*/
public function iProceedOrderWithShippingMethodAndPayment(ShippingMethodInterface $shippingMethod, PaymentMethodInterface $paymentMethod): void
{
$cartToken = $this->sharedStorage->get('cart_token');
$chooseShippingMethod = new ChooseShippingMethod(0, $shippingMethod->getCode());
$choosePaymentMethod = new ChoosePaymentMethod(0, $paymentMethod->getCode());

$chooseShippingMethod->setOrderTokenValue($cartToken);
$choosePaymentMethod->setOrderTokenValue($cartToken);

$this->commandBus->dispatch($chooseShippingMethod);
$this->commandBus->dispatch($choosePaymentMethod);
>>>>>>> 7f2cb5abed... [API] Order confirmation email sending
}
}
5 changes: 0 additions & 5 deletions src/Sylius/Behat/Resources/config/services/contexts/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="sylius.behat.context.setup.checkout" class="Sylius\Behat\Context\Setup\CheckoutContext">
<argument type="service" id="sylius_default.bus" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="sylius.behat.context.setup.channel" class="Sylius\Behat\Context\Setup\ChannelContext">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.factory.default_united_states_channel" />
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": "^7.3",
"api-platform/core": "^2.5",
"sylius/core-bundle": "^1.7",
"sylius/core-bundle": "dev-master",
"symfony/messenger": "^4.4"
},
"require-dev": {
Expand Down

0 comments on commit cac900e

Please sign in to comment.