|
@@ -20,7 +20,6 @@ class MonologExtensionTest extends TestCase
|
|
|
{
|
|
|
public function testLoadWithDefault()
|
|
|
{
|
|
|
- // logger
|
|
|
$container = new ContainerBuilder();
|
|
|
$loader = new MonologExtension();
|
|
|
|
|
@@ -38,7 +37,6 @@ class MonologExtensionTest extends TestCase
|
|
|
|
|
|
public function testLoadWithCustomValues()
|
|
|
{
|
|
|
- // logger
|
|
|
$container = new ContainerBuilder();
|
|
|
$loader = new MonologExtension();
|
|
|
|
|
@@ -56,7 +54,6 @@ class MonologExtensionTest extends TestCase
|
|
|
|
|
|
public function testLoadWithSeveralHandlers()
|
|
|
{
|
|
|
- // logger
|
|
|
$container = new ContainerBuilder();
|
|
|
$loader = new MonologExtension();
|
|
|
|
|
@@ -83,6 +80,147 @@ class MonologExtensionTest extends TestCase
|
|
|
$this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false));
|
|
|
}
|
|
|
|
|
|
+ public function testLoadWithOverwriting()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'),
|
|
|
+ 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'),
|
|
|
+ 'nested' => array('type' => 'stream')
|
|
|
+ )),
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'),
|
|
|
+ ))
|
|
|
+ ), $container);
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.logger'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.custom'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.main'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.nested'));
|
|
|
+
|
|
|
+ $logger = $container->getDefinition('monolog.logger');
|
|
|
+ $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main')));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.custom');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.main');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testLoadWithNewAtEnd()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'),
|
|
|
+ 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'),
|
|
|
+ 'nested' => array('type' => 'stream')
|
|
|
+ )),
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'),
|
|
|
+ 'new' => array('type' => 'stream', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR'),
|
|
|
+ ))
|
|
|
+ ), $container);
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.logger'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.custom'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.main'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.nested'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.new'));
|
|
|
+
|
|
|
+ $logger = $container->getDefinition('monolog.logger');
|
|
|
+ $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.new')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main')));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.new');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testLoadWithNewAndPriority()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'),
|
|
|
+ 'main' => array('type' => 'buffer', 'level' => 'INFO', 'handler' => 'nested'),
|
|
|
+ 'nested' => array('type' => 'stream')
|
|
|
+ )),
|
|
|
+ array('handlers' => array(
|
|
|
+ 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'),
|
|
|
+ 'first' => array('type' => 'rotatingfile', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => 3),
|
|
|
+ 'last' => array('type' => 'stream', 'path' => '/tmp/last.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => -3),
|
|
|
+ ))
|
|
|
+ ), $container);
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.logger'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.custom'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.main'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.nested'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.first'));
|
|
|
+ $this->assertTrue($container->hasDefinition('monolog.handler.last'));
|
|
|
+
|
|
|
+ $logger = $container->getDefinition('monolog.logger');
|
|
|
+ $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.last')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main')));
|
|
|
+ $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.first')));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.main');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.buffer.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), 0, \Monolog\Logger::INFO, false));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.first');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.rotatingfile.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true));
|
|
|
+
|
|
|
+ $handler = $container->getDefinition('monolog.handler.last');
|
|
|
+ $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%');
|
|
|
+ $this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
+ */
|
|
|
+ public function testExceptionWhenUsingFingerscrossedWithoutHandler()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(array('handlers' => array('main' => array('type' => 'fingerscrossed')))), $container);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
+ */
|
|
|
+ public function testExceptionWhenUsingBufferWithoutHandler()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(array('handlers' => array('main' => array('type' => 'buffer')))), $container);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
+ */
|
|
|
+ public function testExceptionWhenUsingServiceWithoutId()
|
|
|
+ {
|
|
|
+ $container = new ContainerBuilder();
|
|
|
+ $loader = new MonologExtension();
|
|
|
+
|
|
|
+ $loader->load(array(array('handlers' => array('main' => array('type' => 'service')))), $container);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
*/
|