Skip to content
Permalink
Browse files

Merge pull request #276 from alcaeus/mark-service-handlers-nested

Allow marking service handlers as nested
  • Loading branch information...
Seldaek committed Dec 29, 2018
2 parents 8db4aa6 + 23e3c3b commit 09769ce4793c162d5e2a0df7a739aeed87289ab9
Showing with 29 additions and 0 deletions.
  1. +4 −0 DependencyInjection/MonologExtension.php
  2. +25 −0 Tests/DependencyInjection/MonologExtensionTest.php
@@ -131,6 +131,10 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
if ('service' === $handler['type']) {
$container->setAlias($handlerId, $handler['id']);
if (!empty($handler['nested']) && true === $handler['nested']) {
$this->markNestedHandler($handlerId);
}
return $handlerId;
}
@@ -84,6 +84,31 @@ public function testLoadWithServiceHandler()
$this->assertTrue($container->hasDefinition('monolog.logger'));
$this->assertTrue($container->hasAlias('monolog.handler.custom'));
$logger = $container->getDefinition('monolog.logger');
// Custom service handler must be pushed to logger
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', array('%monolog.use_microseconds%'));
$this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom')));
$handler = $container->findDefinition('monolog.handler.custom');
$this->assertDICDefinitionClass($handler, 'stdClass');
$this->assertDICConstructorArguments($handler, array('foo', false));
}
public function testLoadWithNestedServiceHandler()
{
$container = $this->getContainer(
array(array('handlers' => array('custom' => array('type' => 'service', 'id' => 'some.service.id', 'nested' => true)))),
array('some.service.id' => new Definition('stdClass', array('foo', false)))
);
$this->assertTrue($container->hasDefinition('monolog.logger'));
$this->assertTrue($container->hasAlias('monolog.handler.custom'));
$logger = $container->getDefinition('monolog.logger');
// Nested service handler must not be pushed to logger
$this->assertCount(1, $logger->getMethodCalls());
$this->assertDICDefinitionMethodCallAt(0, $logger, 'useMicrosecondTimestamps', array('%monolog.use_microseconds%'));
$handler = $container->findDefinition('monolog.handler.custom');
$this->assertDICDefinitionClass($handler, 'stdClass');
$this->assertDICConstructorArguments($handler, array('foo', false));

0 comments on commit 09769ce

Please sign in to comment.
You can’t perform that action at this time.