Skip to content

Commit cc73694

Browse files
bobvandevijverJean85
andauthoredMar 3, 2021
Allow explicit null value for dsn configuration option (#457)
* Allow explicit null value for dsn configuration option * Add tests for falsy dsn configuration values * Add changelog entry Co-authored-by: Alessandro Lai <alessandro.lai85@gmail.com>
1 parent b46eb30 commit cc73694

12 files changed

+101
-1
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
## 4.0.3 (2021-03-03)
6+
- Fix regression from #454 for `null` value on DSN not disabling Sentry (#457)
7+
58
## 4.0.2 (2021-03-03)
69

710
- Add `kernel.project_dir` to `prefixes` default value to trim paths to the project root (#434)

‎src/DependencyInjection/SentryExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
6767
{
6868
$options = $config['options'];
6969

70-
if (isset($config['dsn'])) {
70+
if (\array_key_exists('dsn', $config)) {
7171
$options['dsn'] = $config['dsn'];
7272
}
7373

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->loadFromExtension('sentry', [
9+
'dsn' => '',
10+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->loadFromExtension('sentry', [
9+
'dsn' => false,
10+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
/** @var ContainerBuilder $container */
8+
$container->loadFromExtension('sentry', [
9+
'dsn' => null,
10+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">
8+
9+
<sentry:config dsn="">
10+
</sentry:config>
11+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">
8+
9+
<sentry:config dsn="false">
10+
</sentry:config>
11+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">
8+
9+
<sentry:config dsn="null">
10+
</sentry:config>
11+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sentry:
2+
dsn: ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sentry:
2+
dsn: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sentry:
2+
dsn: ~

‎tests/DependencyInjection/SentryExtensionTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ public function testIgnoreErrorsIntegrationIsNotAddedTwiceIfAlreadyConfigured():
263263
$this->assertSame(1, $ignoreErrorsIntegrationsCount);
264264
}
265265

266+
public function testEmptyDsnIsPropagatedToOptions(): void
267+
{
268+
$this->assertDsnPropagation('dsn_empty_string', '');
269+
}
270+
271+
public function testFalseDsnIsPropagatedToOptions(): void
272+
{
273+
$this->assertDsnPropagation('dsn_false', false);
274+
}
275+
276+
public function testNullDsnIsPropagatedToOptions(): void
277+
{
278+
$this->assertDsnPropagation('dsn_null', null);
279+
}
280+
266281
private function createContainerFromFixture(string $fixtureFile): ContainerBuilder
267282
{
268283
$container = new ContainerBuilder(new EnvPlaceholderParameterBag([
@@ -292,4 +307,17 @@ private function assertDefinitionMethodCallAt(array $methodCall, string $method,
292307
$this->assertSame($method, $methodCall[0]);
293308
$this->assertEquals($arguments, $methodCall[1]);
294309
}
310+
311+
/**
312+
* @param mixed $result
313+
*/
314+
private function assertDsnPropagation(string $fixtureFile, $result): void
315+
{
316+
$container = $this->createContainerFromFixture($fixtureFile);
317+
$optionsDefinition = $container->getDefinition('sentry.client.options');
318+
319+
$this->assertSame(Options::class, $optionsDefinition->getClass());
320+
$this->assertTrue(\array_key_exists('dsn', $optionsDefinition->getArgument(0)));
321+
$this->assertSame($result, $optionsDefinition->getArgument(0)['dsn']);
322+
}
295323
}

0 commit comments

Comments
 (0)