diff --git a/CHANGELOG.md b/CHANGELOG.md index 96128f47..f6a56a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/phpstan.neon b/phpstan.neon index b1cacf0f..ac460414 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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 diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 288fa59c..8a25035f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -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') @@ -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'); } } diff --git a/src/DependencyInjection/SentryExtension.php b/src/DependencyInjection/SentryExtension.php index fbb52b77..4d177b40 100644 --- a/src/DependencyInjection/SentryExtension.php +++ b/src/DependencyInjection/SentryExtension.php @@ -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', diff --git a/test/BaseTestCase.php b/test/BaseTestCase.php index 4b4cbbb6..56acab8d 100644 --- a/test/BaseTestCase.php +++ b/test/BaseTestCase.php @@ -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; } } diff --git a/test/DependencyInjection/ConfigurationTest.php b/test/DependencyInjection/ConfigurationTest.php index 8305c4b8..97874a57 100644 --- a/test/DependencyInjection/ConfigurationTest.php +++ b/test/DependencyInjection/ConfigurationTest.php @@ -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']]; } @@ -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; } diff --git a/test/DependencyInjection/SentryExtensionTest.php b/test/DependencyInjection/SentryExtensionTest.php index c4625512..e66f5d6a 100644 --- a/test/DependencyInjection/SentryExtensionTest.php +++ b/test/DependencyInjection/SentryExtensionTest.php @@ -148,6 +148,10 @@ public function optionsValueProvider(): array ]; } + if ($this->maxRequestBodySizeIsSupported()) { + $options[] = ['max_request_body_size', 'always']; + } + return $options; }