/
ConfigurationTest.php
195 lines (172 loc) · 6.72 KB
/
ConfigurationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
namespace Sentry\SentryBundle\Test\DependencyInjection;
use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Sentry\Options;
use Sentry\SentryBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\HttpKernel\Kernel;
class ConfigurationTest extends TestCase
{
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;
public function testDataProviderIsMappingTheRightNumberOfOptions(): void
{
$providerData = $this->optionValuesProvider();
$supportedOptions = \array_unique(\array_column($providerData, 0));
$expectedCount = self::SUPPORTED_SENTRY_OPTIONS_COUNT;
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
++$expectedCount;
}
$this->assertCount(
$expectedCount,
$supportedOptions,
'Provider for configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
);
}
public function testInvalidDataProviderIsMappingTheRightNumberOfOptions(): void
{
$providerData = $this->invalidValuesProvider();
$supportedOptions = \array_unique(\array_column($providerData, 0));
$this->assertCount(
self::SUPPORTED_SENTRY_OPTIONS_COUNT,
$supportedOptions,
'Provider for invalid configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
);
}
public function testConfigurationDefaults(): void
{
$defaultSdkValues = new Options();
$processed = $this->processConfiguration([]);
$expectedDefaults = [
'dsn' => null,
'listener_priorities' => [
'request' => 1,
'sub_request' => 1,
'console' => 1,
'request_error' => 128,
'console_error' => 128,
],
'options' => [
'environment' => '%kernel.environment%',
'in_app_exclude' => [
'%kernel.cache_dir%',
'%kernel.root_dir%/../vendor',
],
'integrations' => $defaultSdkValues->getIntegrations(),
'excluded_exceptions' => $defaultSdkValues->getExcludedExceptions(),
'prefixes' => $defaultSdkValues->getPrefixes(),
'project_root' => '%kernel.root_dir%/..',
'tags' => [],
],
];
if (method_exists(Kernel::class, 'getProjectDir')) {
$expectedDefaults['options']['project_root'] = '%kernel.project_dir%';
$expectedDefaults['options']['in_app_exclude'][1] = '%kernel.project_dir%/vendor';
}
$this->assertEquals($expectedDefaults, $processed);
$this->assertArrayNotHasKey('server_name', $processed['options'], 'server_name has to be fetched at runtime, not before (see #181)');
}
/**
* @dataProvider optionValuesProvider
*/
public function testOptionValuesProcessing(string $option, $value): void
{
$input = ['options' => [$option => $value]];
$processed = $this->processConfiguration($input);
$this->assertArraySubset($input, $processed);
}
public function optionValuesProvider(): array
{
$options = [
['attach_stacktrace', true],
['before_breadcrumb', 'count'],
['before_send', 'count'],
['context_lines', 4],
['context_lines', 99],
['default_integrations', true],
['default_integrations', false],
['enable_compression', false],
['environment', 'staging'],
['error_types', E_ALL],
['http_proxy', '1.2.3.4:5678'],
['in_app_exclude', ['some/path']],
['integrations', []],
['excluded_exceptions', [\Throwable::class]],
['logger', 'some-logger'],
['max_breadcrumbs', 15],
['max_value_length', 1000],
['prefixes', ['some-string']],
['project_root', '/some/dir'],
['release', 'abc0123'],
['sample_rate', 0],
['sample_rate', 1],
['send_attempts', 1],
['send_attempts', 999],
['send_default_pii', true],
['server_name', 'server001.example.com'],
['tags', ['tag-name' => 'value']],
];
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
$options[] = ['capture_silenced_errors', true];
}
return $options;
}
/**
* @dataProvider invalidValuesProvider
*/
public function testInvalidValues(string $option, $value): void
{
$input = ['options' => [$option => $value]];
$this->expectException(InvalidConfigurationException::class);
$this->processConfiguration($input);
}
public function invalidValuesProvider(): array
{
return [
['attach_stacktrace', 'string'],
['before_breadcrumb', 'this is not a callable'],
['before_breadcrumb', [$this, 'is not a callable']],
['before_breadcrumb', false],
['before_breadcrumb', -1],
['before_send', 'this is not a callable'],
['before_send', [$this, 'is not a callable']],
['before_send', false],
['before_send', -1],
['context_lines', -1],
['context_lines', 99999],
['context_lines', 'string'],
['default_integrations', 'true'],
['default_integrations', 1],
['enable_compression', 'string'],
['environment', ''],
['error_types', []],
['excluded_exceptions', 'some-string'],
['http_proxy', []],
['in_app_exclude', 'some/single/path'],
['integrations', [1]],
['integrations', 'a string'],
['logger', []],
['max_breadcrumbs', -1],
['max_breadcrumbs', 'string'],
['max_value_length', -1],
['max_value_length', []],
['prefixes', 'string'],
['project_root', []],
['release', []],
['sample_rate', 1.1],
['sample_rate', -1],
['send_attempts', 1.5],
['send_attempts', 0],
['send_attempts', -1],
['send_default_pii', 'false'],
['server_name', []],
['tags', 'invalid-unmapped-tag'],
];
}
private function processConfiguration(array $values): array
{
$processor = new Processor();
return $processor->processConfiguration(new Configuration(), ['sentry' => $values]);
}
}