forked from getsentry/sentry-symfony
/
ConfigurationTest.php
208 lines (183 loc) · 6.44 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
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
declare(strict_types=1);
namespace Sentry\SentryBundle\Tests\DependencyInjection;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Jean85\PrettyVersions;
use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\DependencyInjection\Configuration;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Messenger\MessageBusInterface;
final class ConfigurationTest extends TestCase
{
public function testProcessConfigurationWithDefaultConfiguration(): void
{
$expectedBundleDefaultConfig = [
'register_error_listener' => true,
'logger' => null,
'transport_factory' => 'Sentry\\Transport\\TransportFactoryInterface',
'options' => [
'integrations' => [],
'prefixes' => array_merge(['%kernel.project_dir%'], array_filter(explode(\PATH_SEPARATOR, get_include_path() ?: ''))),
'trace_propagation_targets' => [],
'environment' => '%kernel.environment%',
'release' => PrettyVersions::getRootPackageVersion()->getPrettyVersion(),
'tags' => [],
'in_app_exclude' => [
'%kernel.cache_dir%',
'%kernel.build_dir%',
'%kernel.project_dir%/vendor',
],
'in_app_include' => [],
'class_serializers' => [],
],
'messenger' => [
'enabled' => interface_exists(MessageBusInterface::class),
'capture_soft_fails' => true,
],
'tracing' => [
'enabled' => true,
'dbal' => [
'enabled' => class_exists(DoctrineBundle::class),
'connections' => [],
],
'twig' => [
'enabled' => class_exists(TwigBundle::class),
],
'cache' => [
'enabled' => class_exists(CacheItem::class),
],
'http_client' => [
'enabled' => class_exists(HttpClient::class),
],
'console' => [
'excluded_commands' => ['messenger:consume'],
],
],
];
$this->assertSame($expectedBundleDefaultConfig, $this->processConfiguration([]));
}
/**
* @param int|float $value
*
* @dataProvider sampleRateOptionDataProvider
*/
public function testSampleRateOption($value): void
{
$config = $this->processConfiguration(['options' => ['sample_rate' => $value]]);
$this->assertSame($value, $config['options']['sample_rate']);
}
/**
* @return \Generator<mixed>
*/
public function sampleRateOptionDataProvider(): \Generator
{
yield [0];
yield [1];
yield [0.0];
yield [1.0];
yield [0.01];
yield [0.9];
}
/**
* @param int|float $value
*
* @dataProvider sampleRateOptionWithInvalidValuesDataProvider
*/
public function testSampleRateOptionWithInvalidValues($value, string $exceptionMessage): void
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->processConfiguration(['options' => ['sample_rate' => $value]]);
}
/**
* @return \Generator<mixed>
*/
public function sampleRateOptionWithInvalidValuesDataProvider(): \Generator
{
yield [
-1,
'The value -1 is too small for path "sentry.options.sample_rate". Should be greater than or equal to 0',
];
yield [
2,
'The value 2 is too big for path "sentry.options.sample_rate". Should be less than or equal to 1',
];
yield [
-0.1,
'The value -0.1 is too small for path "sentry.options.sample_rate". Should be greater than or equal to 0',
];
yield [
1.01,
'The value 1.01 is too big for path "sentry.options.sample_rate". Should be less than or equal to 1',
];
}
/**
* @param int|float $value
*
* @dataProvider tracesSampleRateOptionDataProvider
*/
public function testTracesSampleRateOption($value): void
{
$config = $this->processConfiguration(['options' => ['traces_sample_rate' => $value]]);
$this->assertSame($value, $config['options']['traces_sample_rate']);
}
/**
* @return \Generator<mixed>
*/
public function tracesSampleRateOptionDataProvider(): \Generator
{
yield [0];
yield [1];
yield [0.0];
yield [1.0];
yield [0.01];
yield [0.9];
}
/**
* @param int|float $value
*
* @dataProvider tracesSampleRateOptionWithInvalidValuesDataProvider
*/
public function testTracesSampleRateOptionWithInvalidValues($value, string $exceptionMessage): void
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage($exceptionMessage);
$this->processConfiguration(['options' => ['traces_sample_rate' => $value]]);
}
/**
* @return \Generator<mixed>
*/
public function tracesSampleRateOptionWithInvalidValuesDataProvider(): \Generator
{
yield [
-1,
'The value -1 is too small for path "sentry.options.traces_sample_rate". Should be greater than or equal to 0',
];
yield [
2,
'The value 2 is too big for path "sentry.options.traces_sample_rate". Should be less than or equal to 1',
];
yield [
-0.1,
'The value -0.1 is too small for path "sentry.options.traces_sample_rate". Should be greater than or equal to 0',
];
yield [
1.01,
'The value 1.01 is too big for path "sentry.options.traces_sample_rate". Should be less than or equal to 1',
];
}
/**
* @param array<string, mixed> $values
*
* @return array<string, mixed>
*/
private function processConfiguration(array $values): array
{
$processor = new Processor();
return $processor->processConfiguration(new Configuration(), ['sentry' => $values]);
}
}