Skip to content

Commit

Permalink
Merge pull request #249 from getsentry/add-max_request_body_size-option
Browse files Browse the repository at this point in the history
Add max_request_body_size option
  • Loading branch information
Jean85 committed Sep 27, 2019
2 parents 5b8b5de + 8ec0ee6 commit aa7d969
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix Hub initialization for `ErrorListener` (#243, thanks to @teohhanhui)
- Fix compatibility with sentry/sentry 2.2+ (#244)
- Add support for `class_serializers` option (#245)
- Add support for `max_request_body_size` option (#249)

## 3.1.0 - 2019-07-02
- Add support for Symfony 2.8 (#233, thanks to @nocive)
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Expand Up @@ -6,10 +6,11 @@ parameters:
ignoreErrors:
- "/Call to function method_exists.. with 'Symfony.+' and 'getProjectDir' will always evaluate to false./"
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getClassSerializers' will always evaluate to false./"
- "/Call to function method_exists.. with 'Sentry..Options' and 'getMaxRequestBodySi...' will always evaluate to false./"
- '/Parameter \$.+ of method Sentry\\SentryBundle\\EventListener\\ErrorListener::onConsoleException\(\) has invalid typehint type Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Call to method getException\(\) on an unknown class Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent./'
- '/Access to undefined constant Symfony\\Component\\Console\\ConsoleEvents::EXCEPTION./'
- '/Sentry\\SentrySdk/'

includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
Expand Down
20 changes: 14 additions & 6 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -93,6 +93,15 @@ public function getConfigTreeBuilder(): TreeBuilder
})
->thenInvalid('Expecting service reference, got "%s"');
$optionsChildNodes->scalarNode('logger');
if ($this->maxRequestBodySizeIsSupported()) {
$optionsChildNodes->enumNode('max_request_body_size')
->values([
'none',
'small',
'medium',
'always',
]);
}
$optionsChildNodes->integerNode('max_breadcrumbs')
->min(1);
$optionsChildNodes->integerNode('max_value_length')
Expand Down Expand Up @@ -171,12 +180,11 @@ private function isNotAValidCallback(): \Closure

private function classSerializersAreSupported(): bool
{
try {
new Options(['class_serializers' => []]);
return method_exists(Options::class, 'getClassSerializers');
}

return true;
} catch (\Throwable $throwable) {
return false;
}
private function maxRequestBodySizeIsSupported(): bool
{
return method_exists(Options::class, 'getMaxRequestBodySize');
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/SentryExtension.php
Expand Up @@ -67,6 +67,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
'excluded_exceptions',
'http_proxy',
'logger',
'max_request_body_size',
'max_breadcrumbs',
'max_value_length',
'prefixes',
Expand Down
24 changes: 13 additions & 11 deletions test/BaseTestCase.php
Expand Up @@ -4,29 +4,31 @@

use PHPUnit\Framework\TestCase;
use Sentry\Options;
use Sentry\SentryBundle\Test\DependencyInjection\ConfigurationTest;

abstract class BaseTestCase extends TestCase
{
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;

protected function classSerializersAreSupported(): bool
{
try {
new Options(['class_serializers' => []]);
return method_exists(Options::class, 'getClassSerializers');
}

return true;
} catch (\Throwable $throwable) {
return false;
}
protected function maxRequestBodySizeIsSupported(): bool
{
return method_exists(Options::class, 'getMaxRequestBodySize');
}

protected function getSupportedOptionsCount(): int
{
$count = 23;

if ($this->classSerializersAreSupported()) {
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
++$count;
}

if ($this->maxRequestBodySizeIsSupported()) {
++$count;
}

return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT;
return $count;
}
}
12 changes: 12 additions & 0 deletions test/DependencyInjection/ConfigurationTest.php
Expand Up @@ -130,6 +130,13 @@ public function optionValuesProvider(): array
}

if ($this->classSerializersAreSupported()) {
$options[] = ['max_request_body_size', 'none'];
$options[] = ['max_request_body_size', 'small'];
$options[] = ['max_request_body_size', 'medium'];
$options[] = ['max_request_body_size', 'always'];
}

if ($this->maxRequestBodySizeIsSupported()) {
$options[] = ['class_serializers', ['count']];
}

Expand Down Expand Up @@ -198,6 +205,11 @@ public function invalidValuesProvider(): array
$values[] = ['class_serializers', -1];
}

if ($this->maxRequestBodySizeIsSupported()) {
$values[] = ['max_request_body_size', null];
$values[] = ['max_request_body_size', 'invalid'];
}

return $values;
}

Expand Down
4 changes: 4 additions & 0 deletions test/DependencyInjection/SentryExtensionTest.php
Expand Up @@ -148,6 +148,10 @@ public function optionsValueProvider(): array
];
}

if ($this->maxRequestBodySizeIsSupported()) {
$options[] = ['max_request_body_size', 'always'];
}

return $options;
}

Expand Down

0 comments on commit aa7d969

Please sign in to comment.