Skip to content

Commit b0639a1

Browse files
committed
Map the max_request_body_size option in Configuration
1 parent 5b8b5de commit b0639a1

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function getConfigTreeBuilder(): TreeBuilder
9393
})
9494
->thenInvalid('Expecting service reference, got "%s"');
9595
$optionsChildNodes->scalarNode('logger');
96+
if ($this->maxRequestBodySizeIsSupported()) {
97+
$optionsChildNodes->enumNode('max_request_body_size')
98+
->values([
99+
'none',
100+
'small',
101+
'medium',
102+
'always',
103+
]);
104+
}
96105
$optionsChildNodes->integerNode('max_breadcrumbs')
97106
->min(1);
98107
$optionsChildNodes->integerNode('max_value_length')
@@ -170,9 +179,19 @@ private function isNotAValidCallback(): \Closure
170179
}
171180

172181
private function classSerializersAreSupported(): bool
182+
{
183+
return $this->optionIsSupported('class_serializers', []);
184+
}
185+
186+
private function maxRequestBodySizeIsSupported(): bool
187+
{
188+
return $this->optionIsSupported('max_request_body_size', 'none');
189+
}
190+
191+
private function optionIsSupported(string $name, $defaultValue): bool
173192
{
174193
try {
175-
new Options(['class_serializers' => []]);
194+
new Options([$name => $defaultValue]);
176195

177196
return true;
178197
} catch (\Throwable $throwable) {

test/BaseTestCase.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,42 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Sentry\Options;
7-
use Sentry\SentryBundle\Test\DependencyInjection\ConfigurationTest;
87

98
abstract class BaseTestCase extends TestCase
109
{
11-
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;
12-
1310
protected function classSerializersAreSupported(): bool
1411
{
15-
try {
16-
new Options(['class_serializers' => []]);
12+
return $this->optionIsSupported('class_serializers', []);
13+
}
1714

18-
return true;
19-
} catch (\Throwable $throwable) {
20-
return false;
21-
}
15+
protected function maxRequestBodySizeIsSupported(): bool
16+
{
17+
return $this->optionIsSupported('max_request_body_size', 'none');
2218
}
2319

2420
protected function getSupportedOptionsCount(): int
2521
{
22+
$count = 23;
23+
2624
if ($this->classSerializersAreSupported()) {
27-
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
25+
++$count;
26+
}
27+
28+
if ($this->maxRequestBodySizeIsSupported()) {
29+
++$count;
2830
}
2931

30-
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT;
32+
return $count;
33+
}
34+
35+
private function optionIsSupported(string $name, $defaultValue): bool
36+
{
37+
try {
38+
new Options([$name => $defaultValue]);
39+
40+
return true;
41+
} catch (\Throwable $throwable) {
42+
return false;
43+
}
3144
}
3245
}

test/DependencyInjection/ConfigurationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public function optionValuesProvider(): array
112112
['excluded_exceptions', [\Throwable::class]],
113113
['logger', 'some-logger'],
114114
['max_breadcrumbs', 15],
115+
['max_request_body_size', 'none'],
116+
['max_request_body_size', 'small'],
117+
['max_request_body_size', 'medium'],
118+
['max_request_body_size', 'always'],
115119
['max_value_length', 1000],
116120
['prefixes', ['some-string']],
117121
['project_root', '/some/dir'],
@@ -174,6 +178,8 @@ public function invalidValuesProvider(): array
174178
['integrations', [1]],
175179
['integrations', 'a string'],
176180
['logger', []],
181+
['max_request_body_size', null],
182+
['max_request_body_size', 'invalid'],
177183
['max_breadcrumbs', -1],
178184
['max_breadcrumbs', 'string'],
179185
['max_value_length', -1],

0 commit comments

Comments
 (0)