Skip to content

Commit 50b7043

Browse files
committed
Add class_serializers to the options
1 parent c63b80d commit 50b7043

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public function getConfigTreeBuilder(): TreeBuilder
5757
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
5858
$optionsChildNodes->booleanNode('capture_silenced_errors');
5959
}
60+
if ($this->classSerializersAreSupported()) {
61+
$optionsChildNodes->arrayNode('class_serializers')
62+
->defaultValue([])
63+
->prototype('scalar');
64+
}
6065
$optionsChildNodes->integerNode('context_lines')
6166
->min(0)
6267
->max(99);
@@ -163,4 +168,15 @@ private function isNotAValidCallback(): \Closure
163168
return true;
164169
};
165170
}
171+
172+
private function classSerializersAreSupported(): bool
173+
{
174+
try {
175+
new Options(['class_serializers' => []]);
176+
177+
return true;
178+
} catch (\Throwable $throwable) {
179+
return false;
180+
}
181+
}
166182
}

test/DependencyInjection/ConfigurationTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testDataProviderIsMappingTheRightNumberOfOptions(): void
1919
$providerData = $this->optionValuesProvider();
2020
$supportedOptions = \array_unique(\array_column($providerData, 0));
2121

22-
$expectedCount = self::SUPPORTED_SENTRY_OPTIONS_COUNT;
22+
$expectedCount = $this->getSupportedOptionsCount();
2323

2424
if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') {
2525
++$expectedCount;
@@ -38,7 +38,7 @@ public function testInvalidDataProviderIsMappingTheRightNumberOfOptions(): void
3838
$supportedOptions = \array_unique(\array_column($providerData, 0));
3939

4040
$this->assertCount(
41-
self::SUPPORTED_SENTRY_OPTIONS_COUNT,
41+
$this->getSupportedOptionsCount(),
4242
$supportedOptions,
4343
'Provider for invalid configuration options mismatch: ' . PHP_EOL . print_r($supportedOptions, true)
4444
);
@@ -76,6 +76,10 @@ public function testConfigurationDefaults(): void
7676
$expectedDefaults['options']['in_app_exclude'][1] = '%kernel.project_dir%/vendor';
7777
}
7878

79+
if ($this->classSerializersAreSupported()) {
80+
$expectedDefaults['options']['class_serializers'] = [];
81+
}
82+
7983
$this->assertEquals($expectedDefaults, $processed);
8084
$this->assertArrayNotHasKey('server_name', $processed['options'], 'server_name has to be fetched at runtime, not before (see #181)');
8185
}
@@ -127,6 +131,10 @@ public function optionValuesProvider(): array
127131
$options[] = ['capture_silenced_errors', true];
128132
}
129133

134+
if ($this->classSerializersAreSupported()) {
135+
$options[] = ['class_serializers', ['count']];
136+
}
137+
130138
return $options;
131139
}
132140

@@ -154,6 +162,10 @@ public function invalidValuesProvider(): array
154162
['before_send', [$this, 'is not a callable']],
155163
['before_send', false],
156164
['before_send', -1],
165+
['class_serializers', 'this is not a callable'],
166+
['class_serializers', [$this, 'is not a callable']],
167+
['class_serializers', false],
168+
['class_serializers', -1],
157169
['context_lines', -1],
158170
['context_lines', 99999],
159171
['context_lines', 'string'],
@@ -192,4 +204,24 @@ private function processConfiguration(array $values): array
192204

193205
return $processor->processConfiguration(new Configuration(), ['sentry' => $values]);
194206
}
207+
208+
private function classSerializersAreSupported(): bool
209+
{
210+
try {
211+
new Options(['class_serializers' => []]);
212+
213+
return true;
214+
} catch (\Throwable $throwable) {
215+
return false;
216+
}
217+
}
218+
219+
private function getSupportedOptionsCount(): int
220+
{
221+
if ($this->classSerializersAreSupported()) {
222+
return self::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
223+
}
224+
225+
return self::SUPPORTED_SENTRY_OPTIONS_COUNT;
226+
}
195227
}

0 commit comments

Comments
 (0)