Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public function getConfigTreeBuilder()
->thenInvalid('The token and user have to be specified to use a PushoverHandler')
->end()
->validate()
->ifTrue(function ($v) { return 'raven' === $v['type'] && !array_key_exists('dsn', $v); })
->ifTrue(function ($v) { return 'raven' === $v['type'] && !array_key_exists('dsn', $v) && null === $v['client_id']; })
->thenInvalid('The DSN has to be specified to use a RavenHandler')
->end()
->validate()
Expand Down
5 changes: 2 additions & 3 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,14 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
break;

case 'raven':
$clientId = 'monolog.raven.client.' . sha1($handler['dsn']);
if (null !== $handler['client_id']) {
$clientId = $handler['client_id'];
}
if (!$container->hasDefinition($clientId)) {
} else {
$client = new Definition("Raven_Client", array(
$handler['dsn']
));
$client->setPublic(false);
$clientId = 'monolog.raven.client.'.sha1($handler['dsn']);
$container->setDefinition($clientId, $client);
}
$definition->setArguments(array(
Expand Down
38 changes: 31 additions & 7 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,19 @@ public function testSocketHandler()

}

public function testRavenHandler()
public function testRavenHandlerWhenConfigurationIsWrong()
{
$dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1';

try {
$this->getContainer(array(array('handlers' => array('raven' => array('type' => 'raven')))));
$this->fail();
} catch (InvalidConfigurationException $e) {
$this->assertContains('DSN', $e->getMessage());
}
}

public function testRavenHandlerWhenADSNIsSpecified()
{
$dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1';

$container = $this->getContainer(array(array('handlers' => array('raven' => array(
'type' => 'raven', 'dsn' => $dsn)
Expand All @@ -234,15 +237,36 @@ public function testRavenHandler()

$handler = $container->getDefinition('monolog.handler.raven');
$this->assertDICDefinitionClass($handler, '%monolog.handler.raven.class%');
}

public function testRavenHandlerWhenADSNAndAClientAreSpecified()
{
$container = $this->getContainer(array(array('handlers' => array('raven' => array(
'type' => 'raven', 'dsn' => $dsn, 'client_id' => 'raven.client')
'type' => 'raven', 'dsn' => 'foobar', 'client_id' => 'raven.client')
))));

$this->assertTrue($container->hasDefinition('raven.client'));
$this->assertFalse($container->hasDefinition('raven.client'));

$logger = $container->getDefinition('monolog.logger');
$this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.raven')));

$handler = $container->getDefinition('raven.client');
$this->assertDICDefinitionClass($handler, 'Raven_Client');
$handler = $container->getDefinition('monolog.handler.raven');
$this->assertDICConstructorArguments($handler, array(new Reference('raven.client'), 100, true));
}

public function testRavenHandlerWhenAClientIsSpecified()
{
$container = $this->getContainer(array(array('handlers' => array('raven' => array(
'type' => 'raven', 'client_id' => 'raven.client')
))));

$this->assertFalse($container->hasDefinition('raven.client'));

$logger = $container->getDefinition('monolog.logger');
$this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.raven')));

$handler = $container->getDefinition('monolog.handler.raven');
$this->assertDICConstructorArguments($handler, array(new Reference('raven.client'), 100, true));
}

public function testLogglyHandler()
Expand Down