Skip to content

Commit 5d961ce

Browse files
committed
Fix issue with deprecated option values not handled correctly; migrate services configuration to non-deprecated values
1 parent b80a9e7 commit 5d961ce

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88

99
## 0.8.6 - 2017-08-24
10+
### Changed
11+
- Migrate service definitons to non-deprecated option configuration values
1012
### Fixed
1113
- Fix expected type of the `options.error_types` config value (scalar instead of array, discovered in #72)
14+
- Fix handling of deprecated options value
1215

1316
## 0.8.5 - 2017-08-22
1417
### Fixed

src/Sentry/SentryBundle/DependencyInjection/SentryExtension.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,7 @@ private function checkConfigurationOnForInvalidSettings(array $config, Container
6161
@trigger_error($deprecationMessage, E_USER_DEPRECATED);
6262
}
6363

64-
if ($config[$option] !== $default && $config['options'][$option] === $default) {
65-
$container->setParameter('sentry.options.' . $option, $config[$option]);
66-
}
67-
68-
// new option is used
69-
if ($config[$option] === $default && $config['options'][$option] !== $default) {
70-
$container->setParameter('sentry.' . $option, $config[$option]);
71-
}
72-
73-
// both are used
64+
// both are used, check if there are issues
7465
if (
7566
$config[$option] !== $default
7667
&& $config['options'][$option] !== $default
@@ -83,6 +74,14 @@ private function checkConfigurationOnForInvalidSettings(array $config, Container
8374
);
8475
throw new InvalidConfigurationException($message);
8576
}
77+
78+
// new option is used, overrides old one
79+
if ($config[$option] === $default && $config['options'][$option] !== $default) {
80+
$config[$option] = $config['options'][$option];
81+
}
82+
83+
$container->setParameter('sentry.' . $option, $config[$option]);
84+
$container->setParameter('sentry.options.' . $option, $config[$option]);
8685
}
8786
}
8887

@@ -96,6 +95,7 @@ private function getDeprecatedOptionsWithDefaults()
9695
'app_path' => '%kernel.root_dir%/..',
9796
'release' => null,
9897
'prefixes' => array('%kernel.root_dir%/..'),
98+
'error_types' => null,
9999
'excluded_app_paths' => array(
100100
'%kernel.root_dir%/../vendor',
101101
'%kernel.root_dir%/../app/cache',

src/Sentry/SentryBundle/Resources/config/services.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
services:
22
sentry.client:
33
class: '%sentry.client%'
4-
arguments: ['%sentry.dsn%', '%sentry.options%', '%sentry.error_types%']
4+
arguments: ['%sentry.dsn%', '%sentry.options%', '%sentry.options.error_types%']
55
calls:
6-
- [setRelease, ['%sentry.release%']]
7-
- [setEnvironment, ['%sentry.environment%']]
8-
- [setAppPath, ['%sentry.app_path%']]
9-
- [setExcludedAppPaths, ['%sentry.excluded_app_paths%']]
10-
- [setPrefixes, ['%sentry.prefixes%']]
116
- [install, []]
127

138
sentry.exception_listener:

test/DependencyInjection/SentryExtensionTest.php

+51
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,57 @@ public function test_that_it_uses_both_new_and_deprecated_values()
7070
);
7171
}
7272

73+
public function test_that_using_only_deprecated_values_doesnt_trigger_exception()
74+
{
75+
$container = $this->getContainer(
76+
array(
77+
static::CONFIG_ROOT => array(
78+
'app_path' => 'sentry/app/path',
79+
'error_types' => 'some-value',
80+
),
81+
)
82+
);
83+
84+
$this->assertSame('sentry/app/path', $container->getParameter('sentry.app_path'));
85+
$this->assertSame('some-value', $container->getParameter('sentry.error_types'));
86+
}
87+
88+
public function test_that_using_deprecated_values_works_on_both_options()
89+
{
90+
$container = $this->getContainer(
91+
array(
92+
static::CONFIG_ROOT => array(
93+
'app_path' => 'sentry/app/path',
94+
'error_types' => 'some-value',
95+
),
96+
)
97+
);
98+
99+
$this->assertSame('sentry/app/path', $container->getParameter('sentry.app_path'));
100+
$this->assertSame('sentry/app/path', $container->getParameter('sentry.options.app_path'));
101+
$this->assertSame('some-value', $container->getParameter('sentry.error_types'));
102+
$this->assertSame('some-value', $container->getParameter('sentry.options.error_types'));
103+
}
104+
105+
public function test_that_using_new_values_works_on_both_options()
106+
{
107+
$container = $this->getContainer(
108+
array(
109+
static::CONFIG_ROOT => array(
110+
'options' => array(
111+
'app_path' => 'sentry/app/path',
112+
'error_types' => 'some-value',
113+
),
114+
),
115+
)
116+
);
117+
118+
$this->assertSame('sentry/app/path', $container->getParameter('sentry.app_path'));
119+
$this->assertSame('sentry/app/path', $container->getParameter('sentry.options.app_path'));
120+
$this->assertSame('some-value', $container->getParameter('sentry.error_types'));
121+
$this->assertSame('some-value', $container->getParameter('sentry.options.error_types'));
122+
}
123+
73124
public function test_that_throws_exception_if_new_and_deprecated_values_dont_match()
74125
{
75126
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');

0 commit comments

Comments
 (0)