Skip to content

Commit

Permalink
write order email send test in api bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin authored and GSadee committed May 25, 2021
1 parent 2ad9ec5 commit 224413a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke(SendOrderConfirmation $sendOrderConfirmation): void
$order = $this->orderRepository->findOneByTokenValue($sendOrderConfirmation->orderToken());

$this->emailSender->send(
Emails::ORDER_CONFIRMATION_RESENT,
Emails::ORDER_CONFIRMATION,
[$order->getCustomer()->getEmail()],
[
'order' => $order,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\Tests\Mailer;

use Prophecy\Prophecy\ObjectProphecy;
use Sylius\Bundle\ApiBundle\Command\SendOrderConfirmation;
use Sylius\Bundle\ApiBundle\CommandHandler\SendOrderConfirmationHandler;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Core\Test\Services\EmailChecker;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Contracts\Translation\TranslatorInterface;

final class OrderConfirmationResendTest extends KernelTestCase
{
/**
* @test
*/
public function it_resends_order_confirmation_email(): void
{
$container = self::bootKernel()->getContainer();

/** @var Filesystem $filesystem */
$filesystem = $container->get('filesystem');

/** @var TranslatorInterface $translator */
$translator = $container->get('translator');

/** @var EmailChecker $emailChecker */
$emailChecker = $container->get('sylius.behat.email_checker');

$filesystem->remove($emailChecker->getSpoolDirectory());

$emailSender = $container->get('sylius.email_sender');

/** @var OrderInterface|ObjectProphecy $order */
$order = $this->prophesize(OrderInterface::class);
/** @var CustomerInterface|ObjectProphecy $customer */
$customer = $this->prophesize(CustomerInterface::class);
$customer->getEmail()->willReturn('[email protected]');
/** @var ChannelInterface|ObjectProphecy $channel */
$channel = $this->prophesize(ChannelInterface::class);

$order->getCustomer()->willReturn($customer->reveal());
$order->getChannel()->willReturn($channel->reveal());
$order->getLocaleCode()->willReturn('pl_PL');
$order->getNumber()->willReturn('#000001');
$order->getTokenValue()->willReturn('TOKEN');

/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = $this->prophesize(OrderRepositoryInterface::class);

$orderRepository->findOneByTokenValue('TOKEN')->willReturn($order);

$sendOrderConfirmationEmailHandler = new SendOrderConfirmationHandler(
$emailSender,
$orderRepository->reveal()
);

$sendOrderConfirmationEmailHandler(new SendOrderConfirmation('TOKEN'));

self::assertSame(1, $emailChecker->countMessagesTo('[email protected]'));
self::assertTrue($emailChecker->hasMessageTo(
sprintf(
'%s %s %s',
$translator->trans('sylius.email.order_confirmation.your_order_number', [], null, 'pl_PL'),
'#000001',
$translator->trans('sylius.email.order_confirmation.has_been_successfully_placed', [], null, 'pl_PL')
),
'[email protected]'
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function it_sends_order_confirmation_message(
$customer->getEmail()->willReturn('[email protected]');

$sender->send(
Emails::ORDER_CONFIRMATION_RESENT,
Emails::ORDER_CONFIRMATION,
['[email protected]'],
[
'order' => $order->getWrappedObject(),
Expand Down

0 comments on commit 224413a

Please sign in to comment.