Переглянути джерело

[MonologBundle] Added a proper exception when the handler type is invalid

Christophe Coevoet 14 роки тому
батько
коміт
eab8ffc5ef

+ 7 - 2
src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php

@@ -188,13 +188,18 @@ class MonologExtension extends Extension
             ));
             break;
 
-        default:
-            // Handler using the constructor of AbstractHandler without adding their own arguments
+        // Handlers using the constructor of AbstractHandler without adding their own arguments
+        case 'test':
+        case 'null':
+        case 'debug':
             $definition->setArguments(array(
                 $handler['level'],
                 $handler['bubble'],
             ));
             break;
+
+        default:
+            throw new \InvalidArgumentException(sprintf('Invalid handler type "%s" given for handler "%s"', $handler['type'], $name));
         }
 
         if (!empty($handler['formatter'])) {

+ 11 - 0
src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php

@@ -188,6 +188,17 @@ class MonologExtensionTest extends TestCase
         $this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true));
     }
 
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testExceptionWhenInvalidHandler()
+    {
+        $container = new ContainerBuilder();
+        $loader = new MonologExtension();
+
+        $loader->load(array(array('handlers' => array('main' => array('type' => 'invalid_handler')))), $container);
+    }
+
     /**
      * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
      */