diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ac9d0897..48190c2a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -451,10 +451,9 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->scalarNode('type') ->isRequired() - ->treatNullLike('null') ->beforeNormalization() - ->always() - ->then(function ($v) { return strtolower($v); }) + ->ifString()->then(function ($v) { return strtolower($v); }) + ->ifNull()->then(function ($v) { return 'null'; }) ->end() ->end() ->scalarNode('id')->end() // service & rollbar diff --git a/tests/DependencyInjection/FixtureMonologExtensionTestCase.php b/tests/DependencyInjection/FixtureMonologExtensionTestCase.php index 93c685ae..bccda2a8 100644 --- a/tests/DependencyInjection/FixtureMonologExtensionTestCase.php +++ b/tests/DependencyInjection/FixtureMonologExtensionTestCase.php @@ -13,6 +13,7 @@ use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Monolog\Handler\NoopHandler; +use Monolog\Handler\NullHandler; use Monolog\Processor\PsrLogMessageProcessor; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; @@ -312,6 +313,16 @@ public function testNativeMailer() $this->assertSame(['addHeader', [['Foo: bar', 'Baz: inga']]], $methodCalls[1]); } + public function testTypeNull() + { + $container = $this->getContainer('type_null'); + + $logger = $container->getDefinition('monolog.handler.null_handler'); + + $this->assertSame(NullHandler::class, $logger->getClass()); + $this->assertSame('DEBUG', $logger->getArgument(0)); + } + protected function getContainer($fixture) { $container = new ContainerBuilder(); diff --git a/tests/DependencyInjection/Fixtures/xml/type_null.xml b/tests/DependencyInjection/Fixtures/xml/type_null.xml new file mode 100644 index 00000000..d40106e2 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/xml/type_null.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/tests/DependencyInjection/Fixtures/yml/type_null.yml b/tests/DependencyInjection/Fixtures/yml/type_null.yml new file mode 100644 index 00000000..1992f1f2 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/yml/type_null.yml @@ -0,0 +1,4 @@ +monolog: + handlers: + null_handler: + type: null