diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 50535b7..70b0b28 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -66,5 +66,34 @@ jobs:
run: composer test
-
- name: Run lint container
- run: (cd src/Bundle/test && bin/console lint:container)
+ name: Run lint container (with all services)
+ run: |
+ rm -rf src/Bundle/test/var/cache
+ (cd src/Bundle/test && bin/console lint:container)
+
+ -
+ name: Run lint container (with Swift Mailer)
+ run: |
+ rm -rf src/Bundle/test/var/cache
+ mv src/Bundle/test/config/packages/mailer.yaml mailer.yaml
+ composer remove symfony/mailer --dev
+ (cd src/Bundle/test && bin/console lint:container)
+
+ -
+ name: Run lint container (with symfony/mailer)
+ run: |
+ rm -rf src/Bundle/test/var/cache
+ mv mailer.yaml src/Bundle/test/config/packages/mailer.yaml
+ mv src/Bundle/test/config/bundles.php src/Bundle/test/config/bundles_swift.php
+ mv src/Bundle/test/config/bundles_no_swift.php src/Bundle/test/config/bundles.php
+ composer remove symfony/swiftmailer-bundle --dev
+ composer require symfony/mailer --dev
+ (cd src/Bundle/test && bin/console lint:container)
+
+ -
+ name: Run lint container (with no mailers)
+ run: |
+ rm -rf src/Bundle/test/var/cache
+ rm -f src/Bundle/test/config/packages/mailer.yaml
+ composer remove symfony/mailer --dev
+ (cd src/Bundle/test && bin/console lint:container)
diff --git a/.gitignore b/.gitignore
index fd1773e..ca16686 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
/composer.phar
/composer.lock
+
+/.phpunit.result.cache
diff --git a/composer.json b/composer.json
index d127e6d..7da4423 100644
--- a/composer.json
+++ b/composer.json
@@ -27,6 +27,7 @@
"php": "^8.0",
"sylius-labs/polyfill-symfony-event-dispatcher": "^1.0",
"symfony/config": "^5.4",
+ "symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/dependency-injection": "^5.4",
"symfony/framework-bundle": "^5.4",
"symfony/http-kernel": "^5.4",
@@ -46,6 +47,8 @@
"sylius-labs/coding-standard": "^4.0",
"symfony/console": "^5.4",
"symfony/dotenv": "^5.4",
+ "symfony/event-dispatcher": "^5.4",
+ "symfony/mailer": "^5.4",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/twig-bundle": "^5.4",
"vimeo/psalm": "^4.22",
diff --git a/phpstan.neon b/phpstan.neon
index 9e2b0b4..14d2116 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -23,4 +23,5 @@ parameters:
- '/Parameter \#1 \$event of method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) expects object, string given\./'
- '/Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\./'
+ - '/Cannot call method has\(\) on object\|null/'
- '/Property Sylius\\Component\\Mailer\\Model\\Email\:\:\$id is never written\, only read\./'
diff --git a/src/Bundle/DependencyInjection/SyliusMailerExtension.php b/src/Bundle/DependencyInjection/SyliusMailerExtension.php
index c55b5e6..f7025cc 100644
--- a/src/Bundle/DependencyInjection/SyliusMailerExtension.php
+++ b/src/Bundle/DependencyInjection/SyliusMailerExtension.php
@@ -13,90 +13,89 @@
namespace Sylius\Bundle\MailerBundle\DependencyInjection;
-use Sylius\Bundle\MailerBundle\Renderer\Adapter\EmailTwigAdapter;
-use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
-use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
+use Symfony\Component\Mailer\MailerInterface;
+use Twig\Environment;
-final class SyliusMailerExtension extends Extension
+final class SyliusMailerExtension extends ConfigurableExtension
{
/**
* {@inheritdoc}
*/
- public function load(array $configs, ContainerBuilder $container): void
+ protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
- $config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
+ $loader->load('services.xml');
- $configFiles = [
- 'services.xml',
- ];
-
- foreach ($configFiles as $configFile) {
- $loader->load($configFile);
- }
+ $this->configureSenderAdapter($mergedConfig, $container);
+ $this->configureRendererAdapter($mergedConfig, $container);
- $this->configureSenderAdapter($container, $config);
- $this->configureRendererAdapter($container, $config);
+ $container->setParameter('sylius.mailer.sender_name', $mergedConfig['sender']['name']);
+ $container->setParameter('sylius.mailer.sender_address', $mergedConfig['sender']['address']);
- $container->setParameter('sylius.mailer.sender_name', $config['sender']['name']);
- $container->setParameter('sylius.mailer.sender_address', $config['sender']['address']);
+ $templates = $mergedConfig['templates'] ?? ['Default' => '@SyliusMailer/default.html.twig'];
- $templates = $config['templates'] ?? ['Default' => '@SyliusMailer/default.html.twig'];
-
- $container->setParameter('sylius.mailer.emails', $config['emails']);
+ $container->setParameter('sylius.mailer.emails', $mergedConfig['emails']);
$container->setParameter('sylius.mailer.templates', $templates);
}
- /**
- * {@inheritdoc}
- */
- public function getConfiguration(array $config, ContainerBuilder $container): Configuration
+ private function configureSenderAdapter(array $mergedConfig, ContainerBuilder $container): void
{
- $configuration = new Configuration();
+ if (!ContainerBuilder::willBeAvailable('swiftmailer/swiftmailer', \Swift::class, ['symfony/swiftmailer-bundle'])) {
+ $container->removeDefinition('sylius.email_sender.adapter.swiftmailer');
+ }
- $container->addObjectResource($configuration);
+ if (!ContainerBuilder::willBeAvailable('symfony/mailer', MailerInterface::class, ['symfony/framework-bundle'])) {
+ $container->removeDefinition('sylius.email_sender.adapter.symfony_mailer');
+ }
- return $configuration;
- }
+ if (isset($mergedConfig['sender_adapter'])) {
+ $container->setAlias('sylius.email_sender.adapter', $mergedConfig['sender_adapter']);
- private function configureSenderAdapter(ContainerBuilder $container, array $config): void
- {
- $bundles = (array) $container->getParameter('kernel.bundles');
+ return;
+ }
- $defaultSenderAdapter = 'sylius.email_sender.adapter.default';
- if (array_key_exists('SwiftmailerBundle', $bundles)) {
- $swiftmailerAdapter = new ChildDefinition('sylius.email_sender.adapter.abstract');
- $swiftmailerAdapter->setClass(SwiftMailerAdapter::class);
- $swiftmailerAdapter->setArguments([new Reference('mailer'), new Reference('event_dispatcher')]);
- $swiftmailerAdapter->setPublic(true);
+ $services = [
+ 'sylius.email_sender.adapter.swiftmailer',
+ 'sylius.email_sender.adapter.symfony_mailer',
+ 'sylius.email_sender.adapter.default',
+ ];
- $container->setDefinition('sylius.email_sender.adapter.swiftmailer', $swiftmailerAdapter);
- $defaultSenderAdapter = 'sylius.email_sender.adapter.swiftmailer';
- }
+ foreach ($services as $service) {
+ if ($container->hasDefinition($service)) {
+ $container->setAlias('sylius.email_sender.adapter', $service);
- $container->setAlias('sylius.email_sender.adapter', $config['sender_adapter'] ?? $defaultSenderAdapter);
+ return;
+ }
+ }
}
- private function configureRendererAdapter(ContainerBuilder $container, array $config): void
+ private function configureRendererAdapter(array $mergedConfig, ContainerBuilder $container): void
{
- $bundles = (array) $container->getParameter('kernel.bundles');
+ if (!ContainerBuilder::willBeAvailable('twig/twig', Environment::class, ['symfony/twig-bundle'])) {
+ $container->removeDefinition('sylius.email_renderer.adapter.twig');
+ }
- $defaultRendererAdapter = 'sylius.email_renderer.adapter.default';
- if (array_key_exists('TwigBundle', $bundles)) {
- $twigAdapter = new ChildDefinition('sylius.email_renderer.adapter.abstract');
- $twigAdapter->setClass(EmailTwigAdapter::class);
- $twigAdapter->setArguments([new Reference('twig'), new Reference('event_dispatcher')]);
- $twigAdapter->setPublic(true);
+ if (isset($mergedConfig['renderer_adapter'])) {
+ $container->setAlias('sylius.email_renderer.adapter', $mergedConfig['renderer_adapter']);
- $container->setDefinition('sylius.email_renderer.adapter.twig', $twigAdapter);
- $defaultRendererAdapter = 'sylius.email_renderer.adapter.twig';
+ return;
}
- $container->setAlias('sylius.email_renderer.adapter', $config['renderer_adapter'] ?? $defaultRendererAdapter);
+ $services = [
+ 'sylius.email_renderer.adapter.twig',
+ 'sylius.email_renderer.adapter.default',
+ ];
+
+ foreach ($services as $service) {
+ if ($container->hasDefinition($service)) {
+ $container->setAlias('sylius.email_renderer.adapter', $service);
+
+ return;
+ }
+ }
}
}
diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml
index d4eed9e..3af30a0 100644
--- a/src/Bundle/Resources/config/services.xml
+++ b/src/Bundle/Resources/config/services.xml
@@ -40,7 +40,7 @@
-
+
+
+
+
+
-
+
+
+ The "%service_id%" service is deprecated and will be removed in 2.0, use the Symfony Mailer integration instead.
+
+
+
+
+
+
diff --git a/src/Bundle/Sender/Adapter/DefaultAdapter.php b/src/Bundle/Sender/Adapter/DefaultAdapter.php
index 632d158..754a5b9 100644
--- a/src/Bundle/Sender/Adapter/DefaultAdapter.php
+++ b/src/Bundle/Sender/Adapter/DefaultAdapter.php
@@ -39,8 +39,8 @@ public function send(
array $replyTo = []
): void {
throw new \RuntimeException(sprintf(
- 'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/swiftmailer-bundle" library).',
- SwiftMailerAdapter::class
+ 'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/mailer" library).',
+ SymfonyMailerAdapter::class
));
}
}
diff --git a/src/Bundle/Sender/Adapter/SwiftMailerAdapter.php b/src/Bundle/Sender/Adapter/SwiftMailerAdapter.php
index 2584377..6f29cc7 100644
--- a/src/Bundle/Sender/Adapter/SwiftMailerAdapter.php
+++ b/src/Bundle/Sender/Adapter/SwiftMailerAdapter.php
@@ -20,6 +20,9 @@
use Sylius\Component\Mailer\SyliusMailerEvents;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
+/**
+ * @deprecated The Swift Mailer integration is deprecated since sylius/mailer-bundle 1.8. Use the Symfony Mailer integration instead.
+ */
class SwiftMailerAdapter extends AbstractAdapter
{
/** @var \Swift_Mailer */
@@ -30,6 +33,12 @@ class SwiftMailerAdapter extends AbstractAdapter
public function __construct(\Swift_Mailer $mailer, ?EventDispatcherInterface $dispatcher = null)
{
+ trigger_deprecation(
+ 'sylius/mailer-bundle',
+ '1.8',
+ 'The Swift Mailer integration is deprecated and will be removed in 2.0. Use the Symfony Mailer integration instead.'
+ );
+
$this->mailer = $mailer;
$this->dispatcher = $dispatcher;
}
diff --git a/src/Bundle/Sender/Adapter/SymfonyMailerAdapter.php b/src/Bundle/Sender/Adapter/SymfonyMailerAdapter.php
new file mode 100644
index 0000000..8d411ac
--- /dev/null
+++ b/src/Bundle/Sender/Adapter/SymfonyMailerAdapter.php
@@ -0,0 +1,66 @@
+mailer = $mailer;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function send(
+ array $recipients,
+ string $senderAddress,
+ string $senderName,
+ RenderedEmail $renderedEmail,
+ EmailInterface $email,
+ array $data,
+ array $attachments = [],
+ array $replyTo = []
+ ): void {
+ $message = (new Email())
+ ->subject($renderedEmail->getSubject())
+ ->from(new Address($senderAddress, $senderName))
+ ->to(...$recipients)
+ ->replyTo(...$replyTo)
+ ->html($renderedEmail->getBody());
+
+ foreach ($attachments as $attachment) {
+ $message->attachFromPath($attachment);
+ }
+
+ $emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients, $replyTo);
+
+ $this->dispatcher?->dispatch($emailSendEvent, SyliusMailerEvents::EMAIL_PRE_SEND);
+
+ $this->mailer->send($message);
+
+ $this->dispatcher?->dispatch($emailSendEvent, SyliusMailerEvents::EMAIL_POST_SEND);
+ }
+}
diff --git a/src/Bundle/spec/Sender/Adapter/DefaultAdapterSpec.php b/src/Bundle/spec/Sender/Adapter/DefaultAdapterSpec.php
index c6f35cd..75464e3 100644
--- a/src/Bundle/spec/Sender/Adapter/DefaultAdapterSpec.php
+++ b/src/Bundle/spec/Sender/Adapter/DefaultAdapterSpec.php
@@ -14,7 +14,7 @@
namespace spec\Sylius\Bundle\MailerBundle\Sender\Adapter;
use PhpSpec\ObjectBehavior;
-use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter;
+use Sylius\Bundle\MailerBundle\Sender\Adapter\SymfonyMailerAdapter;
use Sylius\Component\Mailer\Model\EmailInterface;
use Sylius\Component\Mailer\Renderer\RenderedEmail;
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter;
@@ -32,8 +32,8 @@ function it_throws_an_exception_about_not_configured_email_sender_adapter(
): void {
$this
->shouldThrow(new \RuntimeException(sprintf(
- 'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/swiftmailer-bundle" library).',
- SwiftMailerAdapter::class
+ 'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/mailer" library).',
+ SymfonyMailerAdapter::class
)))
->during('send', [['pawel@sylius.com'], 'arnaud@sylius.com', 'arnaud', $renderedEmail, $email, []])
;
diff --git a/src/Bundle/spec/Sender/Adapter/SymfonyMailerAdapterSpec.php b/src/Bundle/spec/Sender/Adapter/SymfonyMailerAdapterSpec.php
new file mode 100644
index 0000000..365ac8e
--- /dev/null
+++ b/src/Bundle/spec/Sender/Adapter/SymfonyMailerAdapterSpec.php
@@ -0,0 +1,117 @@
+beConstructedWith($mailer);
+ }
+
+ function it_is_an_adapter(): void
+ {
+ $this->shouldHaveType(AbstractAdapter::class);
+ }
+
+ function it_sends_an_email_with_events(
+ MailerInterface $mailer,
+ EmailInterface $email,
+ EventDispatcherInterface $dispatcher,
+ RenderedEmail $renderedEmail
+ ): void {
+ $this->setEventDispatcher($dispatcher);
+
+ $renderedEmail->getSubject()->willReturn('subject');
+ $renderedEmail->getBody()->willReturn('body');
+
+ $dispatcher
+ ->dispatch(Argument::type(EmailSendEvent::class), SyliusMailerEvents::EMAIL_PRE_SEND)
+ ->shouldBeCalled()
+ ;
+
+ $mailer->send(Argument::type(Email::class))->shouldBeCalled();
+
+ $dispatcher
+ ->dispatch(Argument::type(EmailSendEvent::class), SyliusMailerEvents::EMAIL_POST_SEND)
+ ->shouldBeCalled()
+ ;
+
+ $this->send(
+ ['pawel@sylius.com'],
+ 'arnaud@sylius.com',
+ 'arnaud',
+ $renderedEmail,
+ $email,
+ []
+ );
+ }
+
+ function it_sends_an_email_with_attachments(
+ MailerInterface $mailer,
+ EmailInterface $email,
+ RenderedEmail $renderedEmail
+ ): void {
+ $renderedEmail->getSubject()->willReturn('subject');
+ $renderedEmail->getBody()->willReturn('body');
+
+ $mailer->send(Argument::type(Email::class))->shouldBeCalled();
+
+ $this->send(
+ ['pawel@sylius.com'],
+ 'arnaud@sylius.com',
+ 'arnaud',
+ $renderedEmail,
+ $email,
+ ['/path/to/file1.txt', '/path/to/file2.txt']
+ );
+ }
+
+ function it_does_not_handle_exceptions_from_the_mailer(
+ MailerInterface $mailer,
+ EmailInterface $email,
+ RenderedEmail $renderedEmail
+ ): void {
+ $exception = new TransportException('Testing');
+
+ $renderedEmail->getSubject()->willReturn('subject');
+ $renderedEmail->getBody()->willReturn('body');
+
+ $mailer->send(Argument::type(Email::class))->willThrow($exception);
+
+ $this->shouldThrow($exception)->during(
+ 'send',
+ [
+ ['pawel@sylius.com'],
+ 'arnaud@sylius.com',
+ 'arnaud',
+ $renderedEmail,
+ $email,
+ [],
+ ]
+ );
+ }
+}
diff --git a/src/Bundle/test/config/bundles.php b/src/Bundle/test/config/bundles.php
index 1ef5aa2..41d3c35 100644
--- a/src/Bundle/test/config/bundles.php
+++ b/src/Bundle/test/config/bundles.php
@@ -13,7 +13,7 @@
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
- Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
+ Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
];
diff --git a/src/Bundle/test/config/bundles_no_swift.php b/src/Bundle/test/config/bundles_no_swift.php
new file mode 100644
index 0000000..9a0ea6d
--- /dev/null
+++ b/src/Bundle/test/config/bundles_no_swift.php
@@ -0,0 +1,18 @@
+ ['all' => true],
+ Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
+ Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
+];
diff --git a/src/Bundle/test/config/packages/mailer.yaml b/src/Bundle/test/config/packages/mailer.yaml
new file mode 100644
index 0000000..59f449a
--- /dev/null
+++ b/src/Bundle/test/config/packages/mailer.yaml
@@ -0,0 +1,3 @@
+framework:
+ mailer:
+ dsn: 'null://null'
diff --git a/src/Bundle/test/src/Tests/DependencyInjection/SyliusMailerExtensionTest.php b/src/Bundle/test/src/Tests/DependencyInjection/SyliusMailerExtensionTest.php
index 88e9e01..7617ff5 100644
--- a/src/Bundle/test/src/Tests/DependencyInjection/SyliusMailerExtensionTest.php
+++ b/src/Bundle/test/src/Tests/DependencyInjection/SyliusMailerExtensionTest.php
@@ -15,92 +15,46 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Sylius\Bundle\MailerBundle\DependencyInjection\SyliusMailerExtension;
-use Sylius\Bundle\MailerBundle\Renderer\Adapter\EmailDefaultAdapter;
-use Sylius\Bundle\MailerBundle\Renderer\Adapter\EmailTwigAdapter;
-use Sylius\Bundle\MailerBundle\Sender\Adapter\DefaultAdapter;
-use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter;
-use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
-use Symfony\Bundle\TwigBundle\TwigBundle;
-use Symfony\Component\DependencyInjection\Definition;
-use Symfony\Component\EventDispatcher\EventDispatcher;
-use Twig\Environment;
final class SyliusMailerExtensionTest extends AbstractExtensionTestCase
{
/** @test */
- public function it_configures_mailer_adapters_and_sender_with_default_data(): void
+ public function it_configures_the_bundle_with_the_default_configuration(): void
{
- $this->mockService('event_dispatcher', EventDispatcher::class);
-
- $this->container->setParameter('kernel.bundles', []);
-
$this->load();
- $this->compile();
$this->assertContainerBuilderHasParameter('sylius.mailer.sender_name', 'Example.com Store');
$this->assertContainerBuilderHasParameter('sylius.mailer.sender_address', 'no-reply@example.com');
+ $this->assertContainerBuilderHasParameter('sylius.mailer.emails');
+ $this->assertContainerBuilderHasParameter('sylius.mailer.templates');
- $this->assertContainerBuilderHasService('sylius.email_sender.adapter.default', DefaultAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter', 'sylius.email_sender.adapter.default');
-
- $this->assertContainerBuilderHasService('sylius.email_renderer.adapter.default', EmailDefaultAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter', 'sylius.email_renderer.adapter.default');
+ $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter');
+ $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter');
}
/** @test */
- public function it_configures_mailer_adapters_and_sender_with_custom_sender_data(): void
+ public function it_configures_the_bundle_with_custom_sender_data(): void
{
- $this->mockService('event_dispatcher', EventDispatcher::class);
- $this->container->setParameter('kernel.bundles', []);
-
$this->load(['sender' => ['name' => 'John Doe', 'address' => 'john@doe.com']]);
- $this->compile();
$this->assertContainerBuilderHasParameter('sylius.mailer.sender_name', 'John Doe');
$this->assertContainerBuilderHasParameter('sylius.mailer.sender_address', 'john@doe.com');
- $this->assertContainerBuilderHasService('sylius.email_sender.adapter.default', DefaultAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter', 'sylius.email_sender.adapter.default');
-
- $this->assertContainerBuilderHasService('sylius.email_renderer.adapter.default', EmailDefaultAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter', 'sylius.email_renderer.adapter.default');
+ $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter');
+ $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter');
}
/** @test */
- public function it_configures_twig_and_swiftmailer_adapters_if_they_are_available(): void
+ public function it_configures_the_bundle_with_custom_adapter_services(): void
{
- $this->mockService('event_dispatcher', EventDispatcher::class);
- $this->mockService('mailer', \Swift_Mailer::class);
- $this->mockService('twig', Environment::class);
-
- $this->container->setParameter(
- 'kernel.bundles',
- ['SwiftmailerBundle' => SwiftmailerBundle::class, 'TwigBundle' => TwigBundle::class]
- );
-
- $this->load();
- $this->compile();
+ $this->load(['sender_adapter' => 'sylius.email_sender.adapter.custom', 'renderer_adapter' => 'sylius.email_renderer.adapter.custom']);
- $this->assertContainerBuilderHasParameter('sylius.mailer.sender_name', 'Example.com Store');
- $this->assertContainerBuilderHasParameter('sylius.mailer.sender_address', 'no-reply@example.com');
-
- $this->assertContainerBuilderHasService('sylius.email_sender.adapter.swiftmailer', SwiftMailerAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter', 'sylius.email_sender.adapter.swiftmailer');
-
- $this->assertContainerBuilderHasService('sylius.email_renderer.adapter.twig', EmailTwigAdapter::class);
- $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter', 'sylius.email_renderer.adapter.twig');
+ $this->assertContainerBuilderHasAlias('sylius.email_renderer.adapter', 'sylius.email_renderer.adapter.custom');
+ $this->assertContainerBuilderHasAlias('sylius.email_sender.adapter', 'sylius.email_sender.adapter.custom');
}
protected function getContainerExtensions(): array
{
return [new SyliusMailerExtension()];
}
-
- private function mockService(string $id, string $class): void
- {
- $this->container->setDefinition(
- $id,
- (new Definition())->setClass(self::getMockClass($class))->setAutoconfigured(true)
- );
- }
}