diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php old mode 100644 new mode 100755 index effac55..2b92628 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -21,11 +21,12 @@ public function getConfigTreeBuilder() $rootNode = $treeBuilder->root('kunstmaan_sentry'); $rootNode ->children() - ->arrayNode('environments') + ->booleanNode('enabled') + ->defaultValue(false) + ->end() + ->scalarNode('dsn') ->cannotBeEmpty() - ->defaultValue(array('prod')) - ->prototype('scalar') - ->end() + ->end() ->end(); // Here you should define the parameters that are allowed to diff --git a/DependencyInjection/KunstmaanSentryExtension.php b/DependencyInjection/KunstmaanSentryExtension.php old mode 100644 new mode 100755 index c72b17c..e0b148a --- a/DependencyInjection/KunstmaanSentryExtension.php +++ b/DependencyInjection/KunstmaanSentryExtension.php @@ -24,7 +24,8 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); - $container->setParameter($this->getAlias(). '.environments', $config['environments']); + $container->setParameter($this->getAlias(). '.enabled', $config['enabled']); + $container->setParameter($this->getAlias(). '.dsn', $config['dsn']); } } diff --git a/EventListener/ExceptionListener.php b/EventListener/ExceptionListener.php old mode 100644 new mode 100755 index 83aaa68..4ca0113 --- a/EventListener/ExceptionListener.php +++ b/EventListener/ExceptionListener.php @@ -16,17 +16,17 @@ class ExceptionListener protected $client; /** - * @var array $environments + * @var boolean $enabled */ - protected $environments; + protected $enabled; /** * @param Raven $client */ - public function __construct(Raven $client, $environments) + public function __construct(Raven $client, $enabled) { $this->client = $client; - $this->environments = $environments; + $this->enabled = $enabled; } /** @@ -44,7 +44,7 @@ public function onKernelException(GetResponseForExceptionEvent $event) if ($event->getRequest()->attributes->has("_controller")) { $culprit = $event->getRequest()->attributes->get("_controller"); } - if (!in_array($this->client->getEnvironment(), $this->environments)) { + if (!$this->enabled) { return array($exception, $culprit, $this->client->getEnvironment()); } else { $event_id = $this->client->getIdent($this->client->captureException($exception, $culprit, $this->client->getEnvironment())); diff --git a/KunstmaanSentryBundle.php b/KunstmaanSentryBundle.php old mode 100644 new mode 100755 index d445858..deb6140 --- a/KunstmaanSentryBundle.php +++ b/KunstmaanSentryBundle.php @@ -15,7 +15,7 @@ class KunstmaanSentryBundle extends Bundle */ public function boot() { - if (!in_array($this->container->getParameter('kernel.environment'), $this->container->getParameter('kunstmaan_sentry.environments'))) { + if (!$this->container->getParameter('kunstmaan_sentry.enabled')) { return; } diff --git a/Resources/config/services.xml b/Resources/config/services.xml old mode 100644 new mode 100755 index ca7e874..cf4f030 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + %kunstmaan_sentry.dsn% Kunstmaan\SentryBundle\Raven\Raven Kunstmaan\SentryBundle\EventListener\ExceptionListener Kunstmaan\SentryBundle\EventListener\ShutdownListener @@ -20,7 +20,7 @@ - %kunstmaan_sentry.environments% + %kunstmaan_sentry.enabled% diff --git a/Tests/EventListener/ExceptionListenerTest.php b/Tests/EventListener/ExceptionListenerTest.php old mode 100644 new mode 100755 index 372832c..9dde893 --- a/Tests/EventListener/ExceptionListenerTest.php +++ b/Tests/EventListener/ExceptionListenerTest.php @@ -14,45 +14,34 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase { - private function getListnerResult($environments, $currentEnv = 'test') + private function getListnerResult($enabled, $currentEnv = 'test') { $kernel = new \TestKernel($currentEnv , false); $raven = new Raven('http://public:secret@example.com/1', $kernel->getEnvironment()); - $listener = new ExceptionListener($raven, $environments); + $listener = new ExceptionListener($raven, $enabled); $request = new Request(); $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Exception("Test")); return $result = $listener->onKernelException($event); } /** - * @dataProvider unhandledEnvironmentsProvider * @covers \Kunstmaan\SentryBundle\EventListener\ExceptionListener */ - public function testExceptionListenerWithUnhandledEnv($environments) + public function testExceptionListenerWithUnhandledEnv() { - $result = $this->getListnerResult($environments, 'test'); + $result = $this->getListnerResult(false, 'test'); $this->assertTrue($result[0] instanceof Exception); $this->assertEmpty($result[1]); $this->assertEquals($result[2], 'test'); } /** - * @dataProvider unhandledEnvironmentsProvider * @covers \Kunstmaan\SentryBundle\EventListener\ExceptionListener */ - public function testExceptionListenerWithHandledEnv($environments) + public function testExceptionListenerWithHandledEnv() { ini_set('error_log','/dev/null'); - $result = $this->getListnerResult($environments, 'prod'); + $result = $this->getListnerResult(true, 'prod'); $this->assertTrue($result); } - - public static function unhandledEnvironmentsProvider() - { - return array( - array(array('prod', 'dev')), - array(array('prod', 'dev', 'stage')), - array(array('prod', 'dev', 'my_env')) - ); - } }