From b64cb2925fd5e548953a87cb81c51a1f46a672f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Wed, 12 Jun 2019 10:52:59 +0200 Subject: [PATCH] Fix 'Add support for headers in native mailer' --- DependencyInjection/MonologExtension.php | 2 +- Resources/config/schema/monolog-1.0.xsd | 8 ++++---- .../FixtureMonologExtensionTest.php | 11 +++++++++++ .../Fixtures/xml/native_mailer.xml | 16 ++++++++++++++++ .../Fixtures/yml/native_mailer.yml | 9 +++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 Tests/DependencyInjection/Fixtures/xml/native_mailer.xml create mode 100644 Tests/DependencyInjection/Fixtures/yml/native_mailer.yml diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 500a041b..ac1866aa 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -541,7 +541,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $handler['bubble'], )); if (!empty($handler['headers'])) { - $definition->addMethodCall('addHeader', $handler['headers']); + $definition->addMethodCall('addHeader', [$handler['headers']]); } break; diff --git a/Resources/config/schema/monolog-1.0.xsd b/Resources/config/schema/monolog-1.0.xsd index 6c23e93a..8c0854ec 100644 --- a/Resources/config/schema/monolog-1.0.xsd +++ b/Resources/config/schema/monolog-1.0.xsd @@ -28,6 +28,7 @@ + @@ -88,7 +89,6 @@ - @@ -189,8 +189,8 @@ - - - + + + diff --git a/Tests/DependencyInjection/FixtureMonologExtensionTest.php b/Tests/DependencyInjection/FixtureMonologExtensionTest.php index 23c0cfd7..2271b0df 100644 --- a/Tests/DependencyInjection/FixtureMonologExtensionTest.php +++ b/Tests/DependencyInjection/FixtureMonologExtensionTest.php @@ -216,6 +216,17 @@ public function testPsr3MessageProcessingDisabled() $this->assertNotContains(array('pushProcessor', array(new Reference('monolog.processor.psr_log_message'))), $methodCalls, 'The PSR-3 processor should not be enabled', false, false); } + public function testNativeMailer() + { + $container = $this->getContainer('native_mailer'); + + $logger = $container->getDefinition('monolog.handler.mailer'); + $methodCalls = $logger->getMethodCalls(); + + $this->assertCount(2, $methodCalls); + $this->assertSame(['addHeader', [['foo' => 'bar']]], $methodCalls[1]); + } + protected function getContainer($fixture) { $container = new ContainerBuilder(); diff --git a/Tests/DependencyInjection/Fixtures/xml/native_mailer.xml b/Tests/DependencyInjection/Fixtures/xml/native_mailer.xml new file mode 100644 index 00000000..6368359a --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/xml/native_mailer.xml @@ -0,0 +1,16 @@ + + + + + + + + bar + + + + diff --git a/Tests/DependencyInjection/Fixtures/yml/native_mailer.yml b/Tests/DependencyInjection/Fixtures/yml/native_mailer.yml new file mode 100644 index 00000000..eec25e33 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/yml/native_mailer.yml @@ -0,0 +1,9 @@ +monolog: + handlers: + mailer: + type: native_mailer + from_email: foo@example.com + to_email: bar@exemple.com + subject: a subject + headers: + foo: bar