Skip to content

Commit

Permalink
[Core] Test order confirmation mailing
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel committed Aug 21, 2020
1 parent b073d7b commit 45f570a
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@
use Sylius\Component\Core\Test\Services\EmailChecker;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Contracts\Translation\TranslatorInterface;

final class OrderEmailManagerTest extends KernelTestCase
{
public function testMailIsSentAndContentIsOk()
private const RECIPIENT_EMAIL = 'test@example.com';
private const LOCALE_CODE = 'en_US';
private const ORDER_NUMBER = '#000001';

/**
* @test
*/
public function it_sends_order_confiramtion_email()
{
static::bootKernel();

/** @var Filesystem $filesystem */
$filesystem = static::$kernel->getContainer()->get('filesystem');

/** @var TranslatorInterface $translator */
$translator = static::$kernel->getContainer()->get('translator');

/** @var EmailChecker $emailChecker */
$emailChecker = static::$kernel->getContainer()->get('sylius.behat.email_checker');

Expand All @@ -39,18 +51,27 @@ public function testMailIsSentAndContentIsOk()
$order = $this->prophesize(OrderInterface::class);
/** @var CustomerInterface|ObjectProphecy $customer */
$customer = $this->prophesize(CustomerInterface::class);
$customer->getEmail()->willReturn('test@example.com');
$customer->getEmail()->willReturn(self::RECIPIENT_EMAIL);
/** @var ChannelInterface|ObjectProphecy $channel */
$channel = $this->prophesize(ChannelInterface::class);

$order->getCustomer()->willReturn($customer->reveal());
$order->getChannel()->willReturn($channel->reveal());
$order->getLocaleCode()->willReturn('en_US');
$order->getNumber()->willReturn('#000001');
$order->getLocaleCode()->willReturn(self::LOCALE_CODE);
$order->getNumber()->willReturn(self::ORDER_NUMBER);
$order->getTokenValue()->willReturn('ASFAFA4654AF');

$orderEmailManager->sendConfirmationEmail($order->reveal());

$this->assertSame(1, $emailChecker->countMessagesTo('test@example.com'));
$this->assertSame(1, $emailChecker->countMessagesTo(self::RECIPIENT_EMAIL));
$this->assertTrue($emailChecker->hasMessageTo(
sprintf(
'%s %s %s',
$translator->trans('sylius.email.order_confirmation.your_order_number', [], null, self::LOCALE_CODE),
self::ORDER_NUMBER,
$translator->trans('sylius.email.order_confirmation.has_been_successfully_placed', [], null, self::LOCALE_CODE)
),
self::RECIPIENT_EMAIL
));
}
}
168 changes: 168 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Tests/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Tests;

use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
use FOS\RestBundle\FOSRestBundle;
use JMS\SerializerBundle\JMSSerializerBundle;
use Knp\Bundle\GaufretteBundle\KnpGaufretteBundle;
use Liip\ImagineBundle\LiipImagineBundle;
use Payum\Bundle\PayumBundle\PayumBundle;
use Sonata\BlockBundle\SonataBlockBundle;
use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle;
use Sylius\Bundle\AddressingBundle\SyliusAddressingBundle;
use Sylius\Bundle\AttributeBundle\SyliusAttributeBundle;
use Sylius\Bundle\ChannelBundle\SyliusChannelBundle;
use Sylius\Bundle\CoreBundle\SyliusCoreBundle;
use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle;
use Sylius\Bundle\CustomerBundle\SyliusCustomerBundle;
use Sylius\Bundle\FixturesBundle\SyliusFixturesBundle;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Bundle\InventoryBundle\SyliusInventoryBundle;
use Sylius\Bundle\LocaleBundle\SyliusLocaleBundle;
use Sylius\Bundle\MailerBundle\SyliusMailerBundle;
use Sylius\Bundle\MoneyBundle\SyliusMoneyBundle;
use Sylius\Bundle\OrderBundle\SyliusOrderBundle;
use Sylius\Bundle\PaymentBundle\SyliusPaymentBundle;
use Sylius\Bundle\PayumBundle\SyliusPayumBundle;
use Sylius\Bundle\ProductBundle\SyliusProductBundle;
use Sylius\Bundle\PromotionBundle\SyliusPromotionBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Sylius\Bundle\ReviewBundle\SyliusReviewBundle;
use Sylius\Bundle\ShippingBundle\SyliusShippingBundle;
use Sylius\Bundle\TaxationBundle\SyliusTaxationBundle;
use Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle;
use Sylius\Bundle\ThemeBundle\SyliusThemeBundle;
use Sylius\Bundle\UiBundle\SyliusUiBundle;
use Sylius\Bundle\UserBundle\SyliusUserBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle;
use winzou\Bundle\StateMachineBundle\winzouStateMachineBundle;

final class TestKernel extends BaseKernel
{
use MicroKernelTrait;

public function registerBundles(): array
{
return [
new FrameworkBundle(),
new SecurityBundle(),
new SwiftmailerBundle(),
new TwigBundle(),
new DoctrineBundle(),
new DoctrineCacheBundle(),
new SyliusOrderBundle(),
new SyliusMoneyBundle(),
new SyliusCurrencyBundle(),
new SyliusLocaleBundle(),
new SyliusProductBundle(),
new SyliusChannelBundle(),
new SyliusAttributeBundle(),
new SyliusTaxationBundle(),
new SyliusShippingBundle(),
new SyliusPaymentBundle(),
new SyliusMailerBundle(),
new SyliusPromotionBundle(),
new SyliusAddressingBundle(),
new SyliusInventoryBundle(),
new SyliusTaxonomyBundle(),
new SyliusUserBundle(),
new SyliusCustomerBundle(),
new SyliusUiBundle(),
new SyliusReviewBundle(),
new SyliusCoreBundle(),
new SyliusResourceBundle(),
new SyliusGridBundle(),
new winzouStateMachineBundle(),
new BazingaHateoasBundle(),
new JMSSerializerBundle(),
new FOSRestBundle(),
new KnpGaufretteBundle(),
new LiipImagineBundle(),
new PayumBundle(),
new StofDoctrineExtensionsBundle(),
new WhiteOctoberPagerfantaBundle(),
new SyliusFixturesBundle(),
new SyliusPayumBundle(),
new SyliusThemeBundle(),
new SonataBlockBundle(),
];
}

protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$containerBuilder->setParameter('locale', 'en_US');

$containerBuilder->loadFromExtension('framework', [
'test' => null,
'secret' => 'S0ME_SECRET',
'session' => [
'handler_id' => null,
],
'templating' => [
'engines' => ['twig'],
],
'default_locale' => '%locale%',
'translator' => [
'fallbacks' => [
'%locale%',
'en',
],
],
]);

$containerBuilder->loadFromExtension('security', [
'firewalls' => [
'main' => [
'anonymous' => true,
],
],
]);

$containerBuilder->loadFromExtension('doctrine', [
'dbal' => [
'driver' => 'pdo_mysql',
'server_version' => '5.7',
'charset' => 'UTF8',
'url' => 'sqlite:///%kernel.project_dir%/var/data.db',
],
]);

$containerBuilder->loadFromExtension('swiftmailer', [
'disable_delivery' => true,
'logging' => true,
'spool' => [
'type' => 'file',
'path' => '%kernel.cache_dir%/spool',
],
]);

$containerBuilder->loadFromExtension('stof_doctrine_extensions', [
'default_locale' => '%locale%',
]);

$containerBuilder->loadFromExtension('twig', [
'debug' =>'%kernel.debug%',
'strict_variables' =>'%kernel.debug%',
]);

$loader->load('@SyliusCoreBundle/Resources/config/app/config.yml');
}

protected function configureRoutes(RoutingConfigurator $routes): void
{
}
}
10 changes: 9 additions & 1 deletion src/Sylius/Bundle/CoreBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@
"knplabs/gaufrette": "^0.8",
"knplabs/knp-gaufrette-bundle": "^0.7",
"liip/imagine-bundle": "^2.3",
"sonata-project/block-bundle": "^4.2",
"swiftmailer/swiftmailer": "^6.2",
"sylius-labs/association-hydrator": "^1.1",
"sylius/addressing-bundle": "^1.6",
"sylius/attribute-bundle": "^1.6",
"sylius/channel-bundle": "^1.6",
"sylius/core": "^1.6",
"sylius/currency-bundle": "^1.6",
"sylius/customer-bundle": "^1.6",
"sylius/fixtures-bundle": "^1.6.1",
"sylius/grid-bundle": "^1.6",
"sylius/inventory-bundle": "^1.6",
"sylius/locale-bundle": "^1.6",
"sylius/money-bundle": "^1.6",
Expand All @@ -55,9 +58,13 @@
"sylius/taxation-bundle": "^1.6",
"sylius/taxonomy-bundle": "^1.6",
"sylius/theme-bundle": "^1.5",
"sylius/ui-bundle": "^1.6",
"sylius/user-bundle": "^1.6",
"symfony/framework-bundle": "^4.4",
"symfony/intl": "^4.4",
"symfony/messenger": "^4.4",
"symfony/swiftmailer-bundle": "^3.4",
"symfony/templating": "^4.4",
"winzou/state-machine-bundle": "^0.3"
},
"require-dev": {
Expand All @@ -83,7 +90,8 @@
},
"autoload-dev": {
"psr-4": {
"Sylius\\Bundle\\CoreBundle\\spec\\": "spec/"
"Sylius\\Bundle\\CoreBundle\\spec\\": "spec/",
"Sylius\\Bundle\\CoreBundle\\Tests\\": "Tests/"
}
},
"repositories": [
Expand Down
11 changes: 11 additions & 0 deletions src/Sylius/Bundle/CoreBundle/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
<directory>./Tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />

<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
<!-- ###- symfony/framework-bundle ### -->

<server name="KERNEL_CLASS" value="Sylius\Bundle\CoreBundle\Tests\TestKernel" />
</php>
</phpunit>

0 comments on commit 45f570a

Please sign in to comment.