-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write order email send test in api bundle
- Loading branch information
Showing
3 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/Sylius/Bundle/ApiBundle/Tests/CommandHandler/SendOrderConfirmationEmailHandlerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]' | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(), | ||
|