Skip to content

Allow explicit null value for dsn configuration option #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## 4.0.3 (2021-03-03)
- Fix regression from #454 for `null` value on DSN not disabling Sentry (#457)

## 4.0.2 (2021-03-03)

- Add `kernel.project_dir` to `prefixes` default value to trim paths to the project root (#434)
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
{
$options = $config['options'];

if (isset($config['dsn'])) {
if (\array_key_exists('dsn', $config)) {
$options['dsn'] = $config['dsn'];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/DependencyInjection/Fixtures/php/dsn_empty_string.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'dsn' => '',
]);
10 changes: 10 additions & 0 deletions tests/DependencyInjection/Fixtures/php/dsn_false.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'dsn' => false,
]);
10 changes: 10 additions & 0 deletions tests/DependencyInjection/Fixtures/php/dsn_null.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'dsn' => null,
]);
11 changes: 11 additions & 0 deletions tests/DependencyInjection/Fixtures/xml/dsn_empty_string.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config dsn="">
</sentry:config>
</container>
11 changes: 11 additions & 0 deletions tests/DependencyInjection/Fixtures/xml/dsn_false.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config dsn="false">
</sentry:config>
</container>
11 changes: 11 additions & 0 deletions tests/DependencyInjection/Fixtures/xml/dsn_null.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config dsn="null">
</sentry:config>
</container>
2 changes: 2 additions & 0 deletions tests/DependencyInjection/Fixtures/yml/dsn_empty_string.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sentry:
dsn: ''
2 changes: 2 additions & 0 deletions tests/DependencyInjection/Fixtures/yml/dsn_false.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sentry:
dsn: false
2 changes: 2 additions & 0 deletions tests/DependencyInjection/Fixtures/yml/dsn_null.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sentry:
dsn: ~
28 changes: 28 additions & 0 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ public function testIgnoreErrorsIntegrationIsNotAddedTwiceIfAlreadyConfigured():
$this->assertSame(1, $ignoreErrorsIntegrationsCount);
}

public function testEmptyDsnIsPropagatedToOptions(): void
{
$this->assertDsnPropagation('dsn_empty_string', '');
}

public function testFalseDsnIsPropagatedToOptions(): void
{
$this->assertDsnPropagation('dsn_false', false);
}

public function testNullDsnIsPropagatedToOptions(): void
{
$this->assertDsnPropagation('dsn_null', null);
}

private function createContainerFromFixture(string $fixtureFile): ContainerBuilder
{
$container = new ContainerBuilder(new EnvPlaceholderParameterBag([
Expand Down Expand Up @@ -292,4 +307,17 @@ private function assertDefinitionMethodCallAt(array $methodCall, string $method,
$this->assertSame($method, $methodCall[0]);
$this->assertEquals($arguments, $methodCall[1]);
}

/**
* @param mixed $result
*/
private function assertDsnPropagation(string $fixtureFile, $result): void
{
$container = $this->createContainerFromFixture($fixtureFile);
$optionsDefinition = $container->getDefinition('sentry.client.options');

$this->assertSame(Options::class, $optionsDefinition->getClass());
$this->assertTrue(\array_key_exists('dsn', $optionsDefinition->getArgument(0)));
$this->assertSame($result, $optionsDefinition->getArgument(0)['dsn']);
}
}