diff --git a/CHANGELOG.md b/CHANGELOG.md index c590b2dc..5131453c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased - ... + +## 3.4.0 (2020-01-17) + - Add support for `sentry/sentry` 2.3 (#298) + - Drop support for `sentry/sentry` < 2.3 (#298) + - Add support to `in_app_include` client option (#298) + - Remap `excluded_exception` option to use the new `IgnoreErrorIntegration` (#298) ## 3.3.2 (2020-01-16) -- Fix issue with exception listener under Symfony 4.3 (#301) + - Fix issue with exception listener under Symfony 4.3 (#301) ## 3.3.1 (2020-01-14) -- Fixed Release + - Fixed Release ## 3.3.0 (2020-01-14) - Add support for Symfony 5.0 (#266, thanks to @Big-Shark) diff --git a/composer.json b/composer.json index bc4c3cc9..f907e6dc 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^7.1", "jean85/pretty-package-versions": "^1.0", "ocramius/package-versions": "^1.3.0", - "sentry/sdk": "^2.0", + "sentry/sdk": "^2.1", "symfony/config": "^3.4||^4.0||^5.0", "symfony/console": "^3.4||^4.0||^5.0", "symfony/dependency-injection": "^3.4||^4.0||^5.0", diff --git a/phpstan.neon b/phpstan.neon index 36fbde23..bceac411 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,8 +6,6 @@ parameters: ignoreErrors: - "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./" - "/Call to function method_exists.. with 'Symfony.+' and 'getThrowable' 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./" - '/Class PHPUnit_Framework_TestCase not found/' - '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/' - diff --git a/phpunit.xml b/phpunit.xml index 3701ed6d..2695c705 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,6 @@ backupGlobals="false" bootstrap="vendor/autoload.php" cacheResult="false" - processIsolation="true" > diff --git a/src/Command/SentryTestCommand.php b/src/Command/SentryTestCommand.php index 7634adad..f7df7d6b 100644 --- a/src/Command/SentryTestCommand.php +++ b/src/Command/SentryTestCommand.php @@ -2,7 +2,7 @@ namespace Sentry\SentryBundle\Command; -use Sentry\SentryBundle\SentryBundle; +use Sentry\SentrySdk; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,7 +16,7 @@ public function __construct() protected function execute(InputInterface $input, OutputInterface $output): int { - $currentHub = SentryBundle::getCurrentHub(); + $currentHub = SentrySdk::getCurrentHub(); $client = $currentHub->getClient(); if (! $client) { diff --git a/src/DependencyInjection/ClientBuilderConfigurator.php b/src/DependencyInjection/ClientBuilderConfigurator.php index 4ccf4b8b..2b5f1d46 100644 --- a/src/DependencyInjection/ClientBuilderConfigurator.php +++ b/src/DependencyInjection/ClientBuilderConfigurator.php @@ -3,9 +3,6 @@ namespace Sentry\SentryBundle\DependencyInjection; use Sentry\ClientBuilderInterface; -use Sentry\Integration\ErrorListenerIntegration; -use Sentry\Integration\ExceptionListenerIntegration; -use Sentry\Integration\IntegrationInterface; use Sentry\SentryBundle\SentryBundle; class ClientBuilderConfigurator @@ -14,23 +11,5 @@ public static function configure(ClientBuilderInterface $clientBuilder): void { $clientBuilder->setSdkIdentifier(SentryBundle::SDK_IDENTIFIER); $clientBuilder->setSdkVersion(SentryBundle::getSdkVersion()); - - $options = $clientBuilder->getOptions(); - if (! $options->hasDefaultIntegrations()) { - return; - } - - $integrations = $options->getIntegrations(); - $options->setIntegrations(array_filter($integrations, static function (IntegrationInterface $integration): bool { - if ($integration instanceof ErrorListenerIntegration) { - return false; - } - - if ($integration instanceof ExceptionListenerIntegration) { - return false; - } - - return true; - })); } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bea54ec3..47ca3dc5 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -2,7 +2,6 @@ namespace Sentry\SentryBundle\DependencyInjection; -use Jean85\PrettyVersions; use PackageVersions\Versions; use Sentry\Options; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -58,14 +57,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->validate() ->ifTrue($this->isNotAValidCallback()) ->thenInvalid('Expecting callable or service reference, got %s'); - if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') { - $optionsChildNodes->booleanNode('capture_silenced_errors'); - } - if ($this->classSerializersAreSupported()) { - $optionsChildNodes->arrayNode('class_serializers') - ->defaultValue([]) - ->prototype('scalar'); - } + $optionsChildNodes->booleanNode('capture_silenced_errors'); + $optionsChildNodes->arrayNode('class_serializers') + ->defaultValue([]) + ->prototype('scalar'); $optionsChildNodes->integerNode('context_lines') ->min(0) ->max(99); @@ -75,6 +70,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->defaultValue('%kernel.environment%') ->cannotBeEmpty(); $optionsChildNodes->scalarNode('error_types'); + $optionsChildNodes->arrayNode('in_app_include') + ->defaultValue([ + '%kernel.project_dir%/src', + ]) + ->prototype('scalar'); $optionsChildNodes->arrayNode('in_app_exclude') ->defaultValue([ '%kernel.cache_dir%', @@ -82,7 +82,7 @@ public function getConfigTreeBuilder(): TreeBuilder ]) ->prototype('scalar'); $optionsChildNodes->arrayNode('excluded_exceptions') - ->defaultValue($defaultValues->getExcludedExceptions()) + ->defaultValue([]) ->prototype('scalar'); $optionsChildNodes->scalarNode('http_proxy'); $optionsChildNodes->arrayNode('integrations') @@ -97,15 +97,13 @@ 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->enumNode('max_request_body_size') + ->values([ + 'none', + 'small', + 'medium', + 'always', + ]); $optionsChildNodes->integerNode('max_breadcrumbs') ->min(1); $optionsChildNodes->integerNode('max_value_length') @@ -113,8 +111,7 @@ public function getConfigTreeBuilder(): TreeBuilder $optionsChildNodes->arrayNode('prefixes') ->defaultValue($defaultValues->getPrefixes()) ->prototype('scalar'); - $optionsChildNodes->scalarNode('project_root') - ->defaultValue('%kernel.project_dir%'); + $optionsChildNodes->scalarNode('project_root'); $optionsChildNodes->scalarNode('release') ->defaultValue(Versions::getVersion(Versions::ROOT_PACKAGE_NAME)) ->info('Release version to be reported to sentry, see https://docs.sentry.io/workflow/releases/?platform=php') @@ -193,14 +190,4 @@ private function isNotAValidCallback(): \Closure return true; }; } - - private function classSerializersAreSupported(): bool - { - return method_exists(Options::class, 'getClassSerializers'); - } - - private function maxRequestBodySizeIsSupported(): bool - { - return method_exists(Options::class, 'getMaxRequestBodySize'); - } } diff --git a/src/DependencyInjection/IntegrationFilterFactory.php b/src/DependencyInjection/IntegrationFilterFactory.php new file mode 100644 index 00000000..f74138d1 --- /dev/null +++ b/src/DependencyInjection/IntegrationFilterFactory.php @@ -0,0 +1,32 @@ +addMethodCall('setInAppExcludedPaths', [$processedOptions['in_app_exclude']]); } + if (\array_key_exists('in_app_include', $processedOptions)) { + $options->addMethodCall('setInAppIncludedPaths', [$processedOptions['in_app_include']]); + } + if (\array_key_exists('error_types', $processedOptions)) { $parsedValue = (new ErrorTypesParser($processedOptions['error_types']))->parse(); $options->addMethodCall('setErrorTypes', [$parsedValue]); @@ -114,14 +119,25 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $ $options->addMethodCall('setClassSerializers', [$classSerializers]); } + $integrations = []; if (\array_key_exists('integrations', $processedOptions)) { - $integrations = []; foreach ($processedOptions['integrations'] as $integrationName) { $integrations[] = new Reference(substr($integrationName, 1)); } + } - $options->addMethodCall('setIntegrations', [$integrations]); + if (\array_key_exists('excluded_exceptions', $processedOptions) && $processedOptions['excluded_exceptions']) { + $ignoreOptions = [ + 'ignore_exceptions' => $processedOptions['excluded_exceptions'], + ]; + + $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); } + + $integrationsCallable = new Definition('callable', [$integrations]); + $integrationsCallable->setFactory([IntegrationFilterFactory::class, 'create']); + + $options->addMethodCall('setIntegrations', [$integrationsCallable]); } private function valueToCallable($value) diff --git a/src/EventListener/ConsoleListener.php b/src/EventListener/ConsoleListener.php index f7e1eca3..15870f13 100644 --- a/src/EventListener/ConsoleListener.php +++ b/src/EventListener/ConsoleListener.php @@ -2,7 +2,7 @@ namespace Sentry\SentryBundle\EventListener; -use Sentry\SentryBundle\SentryBundle; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\Console\Event\ConsoleCommandEvent; @@ -38,7 +38,7 @@ public function onConsoleCommand(ConsoleCommandEvent $event): void $commandName = $command->getName(); } - SentryBundle::getCurrentHub() + SentrySdk::getCurrentHub() ->configureScope(static function (Scope $scope) use ($commandName): void { $scope->setTag('command', $commandName ?? 'N/A'); }); diff --git a/src/EventListener/RequestListener.php b/src/EventListener/RequestListener.php index 99c99a31..0e81b68f 100644 --- a/src/EventListener/RequestListener.php +++ b/src/EventListener/RequestListener.php @@ -2,7 +2,7 @@ namespace Sentry\SentryBundle\EventListener; -use Sentry\SentryBundle\SentryBundle; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\HttpKernel\Event\ControllerEvent; @@ -56,7 +56,7 @@ public function onKernelRequest(RequestEvent $event): void return; } - $currentClient = SentryBundle::getCurrentHub()->getClient(); + $currentClient = SentrySdk::getCurrentHub()->getClient(); if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) { return; } @@ -79,9 +79,9 @@ public function onKernelRequest(RequestEvent $event): void $userData['ip_address'] = $event->getRequest()->getClientIp(); - SentryBundle::getCurrentHub() + SentrySdk::getCurrentHub() ->configureScope(function (Scope $scope) use ($userData): void { - $scope->setUser($userData); + $scope->setUser($userData, true); }); } @@ -97,7 +97,7 @@ public function onKernelController(ControllerEvent $event): void $matchedRoute = (string) $event->getRequest()->attributes->get('_route'); - SentryBundle::getCurrentHub() + SentrySdk::getCurrentHub() ->configureScope(function (Scope $scope) use ($matchedRoute): void { $scope->setTag('route', $matchedRoute); }); diff --git a/src/EventListener/SubRequestListener.php b/src/EventListener/SubRequestListener.php index a6198c57..87970ac1 100644 --- a/src/EventListener/SubRequestListener.php +++ b/src/EventListener/SubRequestListener.php @@ -2,7 +2,7 @@ namespace Sentry\SentryBundle\EventListener; -use Sentry\SentryBundle\SentryBundle; +use Sentry\SentrySdk; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -24,7 +24,7 @@ public function onKernelRequest(RequestEvent $event): void return; } - SentryBundle::getCurrentHub()->pushScope(); + SentrySdk::getCurrentHub()->pushScope(); } /** @@ -38,6 +38,6 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void return; } - SentryBundle::getCurrentHub()->popScope(); + SentrySdk::getCurrentHub()->popScope(); } } diff --git a/src/SentryBundle.php b/src/SentryBundle.php index 7ae98468..03d95558 100644 --- a/src/SentryBundle.php +++ b/src/SentryBundle.php @@ -4,7 +4,6 @@ use Jean85\PrettyVersions; use Sentry\SentrySdk; -use Sentry\State\Hub; use Sentry\State\HubInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -23,11 +22,7 @@ public static function getSdkVersion(): string */ public static function getCurrentHub(): HubInterface { - if (class_exists(SentrySdk::class)) { - return SentrySdk::getCurrentHub(); - } - - return Hub::getCurrent(); + return SentrySdk::getCurrentHub(); } /** @@ -35,12 +30,6 @@ public static function getCurrentHub(): HubInterface */ public static function setCurrentHub(HubInterface $hub): void { - if (class_exists(SentrySdk::class)) { - SentrySdk::setCurrentHub($hub); - - return; - } - - Hub::setCurrent($hub); + SentrySdk::setCurrentHub($hub); } } diff --git a/test/BaseTestCase.php b/test/BaseTestCase.php index 8d4b6f7a..bf531286 100644 --- a/test/BaseTestCase.php +++ b/test/BaseTestCase.php @@ -3,10 +3,6 @@ namespace Sentry\SentryBundle\Test; use PHPUnit\Framework\TestCase; -use Sentry\Options; -use Sentry\SentrySdk; -use Sentry\State\Hub; -use Sentry\State\HubInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -15,38 +11,9 @@ abstract class BaseTestCase extends TestCase { - protected function classSerializersAreSupported(): bool - { - return method_exists(Options::class, 'getClassSerializers'); - } - - protected function maxRequestBodySizeIsSupported(): bool - { - return method_exists(Options::class, 'getMaxRequestBodySize'); - } - protected function getSupportedOptionsCount(): int { - $count = 23; - - if ($this->classSerializersAreSupported()) { - ++$count; - } - - if ($this->maxRequestBodySizeIsSupported()) { - ++$count; - } - - return $count; - } - - protected function setCurrentHub(HubInterface $hub): void - { - if (class_exists(SentrySdk::class)) { - SentrySdk::setCurrentHub($hub); - } else { - Hub::setCurrent($hub); - } + return 26; } protected function createRequestEvent(Request $request = null, int $type = KernelInterface::MASTER_REQUEST) diff --git a/test/Command/SentryTestCommandTest.php b/test/Command/SentryTestCommandTest.php index 80beb15f..08ced888 100644 --- a/test/Command/SentryTestCommandTest.php +++ b/test/Command/SentryTestCommandTest.php @@ -7,6 +7,7 @@ use Sentry\Options; use Sentry\SentryBundle\Command\SentryTestCommand; use Sentry\SentryBundle\Test\BaseTestCase; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -28,7 +29,7 @@ public function testExecuteSuccessfully(): void ->shouldBeCalled() ->willReturn($lastEventId); - $this->setCurrentHub($hub->reveal()); + SentrySdk::setCurrentHub($hub->reveal()); $commandTester = $this->executeCommand(); @@ -50,7 +51,7 @@ public function testExecuteFailsDueToMissingDSN(): void $hub->getClient() ->willReturn($client->reveal()); - $this->setCurrentHub($hub->reveal()); + SentrySdk::setCurrentHub($hub->reveal()); $commandTester = $this->executeCommand(); @@ -74,7 +75,7 @@ public function testExecuteFailsDueToMessageNotSent(): void ->shouldBeCalled() ->willReturn(null); - $this->setCurrentHub($hub->reveal()); + SentrySdk::setCurrentHub($hub->reveal()); $commandTester = $this->executeCommand(); @@ -91,7 +92,7 @@ public function testExecuteFailsDueToMissingClient(): void $hub->getClient() ->willReturn(null); - $this->setCurrentHub($hub->reveal()); + SentrySdk::setCurrentHub($hub->reveal()); $commandTester = $this->executeCommand(); diff --git a/test/DependencyInjection/ConfigurationTest.php b/test/DependencyInjection/ConfigurationTest.php index 7009068a..81177e90 100644 --- a/test/DependencyInjection/ConfigurationTest.php +++ b/test/DependencyInjection/ConfigurationTest.php @@ -2,7 +2,6 @@ namespace Sentry\SentryBundle\Test\DependencyInjection; -use Jean85\PrettyVersions; use PackageVersions\Versions; use Sentry\Options; use Sentry\SentryBundle\DependencyInjection\Configuration; @@ -17,11 +16,7 @@ public function testDataProviderIsMappingTheRightNumberOfOptions(): void $providerData = $this->optionValuesProvider(); $supportedOptions = \array_unique(\array_column($providerData, 0)); - $expectedCount = $this->getSupportedOptionsCount(); - - if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') { - ++$expectedCount; - } + $expectedCount = $this->getSupportedOptionsCount() + 1; $this->assertCount( $expectedCount, @@ -57,15 +52,18 @@ public function testConfigurationDefaults(): void 'console_error' => 128, ], 'options' => [ + 'class_serializers' => [], 'environment' => '%kernel.environment%', + 'in_app_include' => [ + '%kernel.project_dir%/src', + ], 'in_app_exclude' => [ '%kernel.cache_dir%', '%kernel.project_dir%/vendor', ], - 'integrations' => $defaultSdkValues->getIntegrations(), - 'excluded_exceptions' => $defaultSdkValues->getExcludedExceptions(), + 'integrations' => [], + 'excluded_exceptions' => [], 'prefixes' => $defaultSdkValues->getPrefixes(), - 'project_root' => '%kernel.project_dir%', 'tags' => [], 'release' => Versions::getVersion('sentry/sentry-symfony'), ], @@ -78,15 +76,13 @@ public function testConfigurationDefaults(): void ], ]; - if ($this->classSerializersAreSupported()) { - $expectedDefaults['options']['class_serializers'] = []; - } - $this->assertEquals($expectedDefaults, $processed); $this->assertArrayNotHasKey('server_name', $processed['options'], 'server_name has to be fetched at runtime, not before (see #181)'); } /** + * @group legacy + * * @dataProvider optionValuesProvider */ public function testOptionValuesProcessing(string $option, $value): void @@ -99,10 +95,12 @@ public function testOptionValuesProcessing(string $option, $value): void public function optionValuesProvider(): array { - $options = [ + return [ ['attach_stacktrace', true], ['before_breadcrumb', 'count'], ['before_send', 'count'], + ['capture_silenced_errors', true], + ['class_serializers', ['count']], ['context_lines', 4], ['context_lines', 99], ['default_integrations', true], @@ -111,11 +109,16 @@ public function optionValuesProvider(): array ['environment', 'staging'], ['error_types', E_ALL], ['http_proxy', '1.2.3.4:5678'], + ['in_app_include', ['some/path']], ['in_app_exclude', ['some/path']], ['integrations', []], ['excluded_exceptions', [\Throwable::class]], ['logger', 'some-logger'], ['max_breadcrumbs', 15], + ['max_request_body_size', 'none'], + ['max_request_body_size', 'small'], + ['max_request_body_size', 'medium'], + ['max_request_body_size', 'always'], ['max_value_length', 1000], ['prefixes', ['some-string']], ['project_root', '/some/dir'], @@ -128,23 +131,6 @@ public function optionValuesProvider(): array ['server_name', 'server001.example.com'], ['tags', ['tag-name' => 'value']], ]; - - if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() !== '2.0.0') { - $options[] = ['capture_silenced_errors', true]; - } - - 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']]; - } - - return $options; } /** @@ -171,6 +157,10 @@ public function invalidValuesProvider(): array ['before_send', [$this, 'is not a callable']], ['before_send', false], ['before_send', -1], + ['class_serializers', 'this is not a callable'], + ['class_serializers', [$this, 'is not a callable']], + ['class_serializers', false], + ['class_serializers', -1], ['context_lines', -1], ['context_lines', 99999], ['context_lines', 'string'], @@ -181,12 +171,15 @@ public function invalidValuesProvider(): array ['error_types', []], ['excluded_exceptions', 'some-string'], ['http_proxy', []], + ['in_app_include', 'some/single/path'], ['in_app_exclude', 'some/single/path'], ['integrations', [1]], ['integrations', 'a string'], ['logger', []], ['max_breadcrumbs', -1], ['max_breadcrumbs', 'string'], + ['max_request_body_size', null], + ['max_request_body_size', 'invalid'], ['max_value_length', -1], ['max_value_length', []], ['prefixes', 'string'], @@ -202,18 +195,6 @@ public function invalidValuesProvider(): array ['tags', 'invalid-unmapped-tag'], ]; - if ($this->classSerializersAreSupported()) { - $values[] = ['class_serializers', 'this is not a callable']; - $values[] = ['class_serializers', [$this, 'is not a callable']]; - $values[] = ['class_serializers', false]; - $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 0d35ab1d..701fcbc1 100644 --- a/test/DependencyInjection/SentryExtensionTest.php +++ b/test/DependencyInjection/SentryExtensionTest.php @@ -8,13 +8,15 @@ use Sentry\Breadcrumb; use Sentry\ClientInterface; use Sentry\Event; +use Sentry\Integration\ErrorListenerIntegration; +use Sentry\Integration\ExceptionListenerIntegration; use Sentry\Integration\IntegrationInterface; use Sentry\Monolog\Handler; use Sentry\Options; use Sentry\SentryBundle\DependencyInjection\SentryExtension; use Sentry\SentryBundle\EventListener\ErrorListener; -use Sentry\SentryBundle\SentryBundle; use Sentry\SentryBundle\Test\BaseTestCase; +use Sentry\SentrySdk; use Sentry\Severity; use Sentry\State\HubInterface; use Sentry\State\Scope; @@ -39,6 +41,7 @@ public function testDataProviderIsMappingTheRightNumberOfOptions(): void // subtracted one is `integration`, which cannot be tested with the provider $expectedCount = $this->getSupportedOptionsCount(); + --$expectedCount; // excluded_exceptions is remapped to the new IgnoreErrorIntegration if (PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion() === '2.0.0') { --$expectedCount; @@ -57,7 +60,7 @@ public function testOptionsDefaultValues(): void $options = $this->getOptionsFrom($container); $vendorDir = '/dir/project/root/vendor'; - $this->assertSame('/dir/project/root', $options->getProjectRoot()); + $this->assertContains('/dir/project/root/src', $options->getInAppIncludedPaths()); $this->assertNull($options->getDsn()); $this->assertSame('test', $options->getEnvironment()); @@ -119,16 +122,24 @@ public function optionsValueProvider(): array ['attach_stacktrace', true, 'shouldAttachStacktrace'], ['before_breadcrumb', __NAMESPACE__ . '\mockBeforeBreadcrumb', 'getBeforeBreadcrumbCallback'], ['before_send', __NAMESPACE__ . '\mockBeforeSend', 'getBeforeSendCallback'], + [ + 'class_serializers', + [ + self::class => __NAMESPACE__ . '\mockClassSerializer', + ], + 'getClassSerializers', + ], ['context_lines', 1], ['default_integrations', false, 'hasDefaultIntegrations'], ['enable_compression', false, 'isCompressionEnabled'], ['environment', 'staging'], ['error_types', E_ALL & ~E_NOTICE], + ['in_app_include', ['/some/path'], 'getInAppIncludedPaths'], ['in_app_exclude', ['/some/path'], 'getInAppExcludedPaths'], - ['excluded_exceptions', [\Throwable::class]], ['http_proxy', '1.2.3.4'], ['logger', 'sentry-logger'], ['max_breadcrumbs', 15], + ['max_request_body_size', 'always'], ['max_value_length', 1000], ['prefixes', ['/some/path/prefix/']], ['project_root', '/some/project/'], @@ -144,20 +155,6 @@ public function optionsValueProvider(): array $options[] = ['capture_silenced_errors', true, 'shouldCaptureSilencedErrors']; } - if ($this->classSerializersAreSupported()) { - $options['class_serializer'] = [ - 'class_serializers', - [ - self::class => __NAMESPACE__ . '\mockClassSerializer', - ], - 'getClassSerializers', - ]; - } - - if ($this->maxRequestBodySizeIsSupported()) { - $options[] = ['max_request_body_size', 'always']; - } - return $options; } @@ -203,8 +200,8 @@ public function testBeforeSendUsingServiceDefinition(): void { $container = $this->getContainer([ 'options' => [ - 'before_send' => '@callable_mock', - ], + 'before_send' => '@callable_mock', + ], ]); $beforeSendCallback = $this->getOptionsFrom($container)->getBeforeSendCallback(); @@ -228,8 +225,8 @@ public function testBeforeSendUsingScalarCallable($scalarCallable): void { $container = $this->getContainer([ 'options' => [ - 'before_send' => $scalarCallable, - ], + 'before_send' => $scalarCallable, + ], ]); $beforeSendCallback = $this->getOptionsFrom($container)->getBeforeSendCallback(); @@ -250,8 +247,8 @@ public function testBeforeSendWithInvalidServiceReference(): void { $container = $this->getContainer([ 'options' => [ - 'before_send' => '@event_dispatcher', - ], + 'before_send' => '@event_dispatcher', + ], ]); $this->expectException(\TypeError::class); @@ -263,8 +260,8 @@ public function testBeforeBreadcrumbUsingServiceDefinition(): void { $container = $this->getContainer([ 'options' => [ - 'before_breadcrumb' => '@callable_mock', - ], + 'before_breadcrumb' => '@callable_mock', + ], ]); $beforeBreadcrumbCallback = $this->getOptionsFrom($container)->getBeforeBreadcrumbCallback(); @@ -288,8 +285,8 @@ public function testBeforeBreadcrumbUsingScalarCallable($scalarCallable): void { $container = $this->getContainer([ 'options' => [ - 'before_breadcrumb' => $scalarCallable, - ], + 'before_breadcrumb' => $scalarCallable, + ], ]); $beforeBreadcrumbCallback = $this->getOptionsFrom($container)->getBeforeBreadcrumbCallback(); @@ -319,8 +316,8 @@ public function testBeforeBreadcrumbWithInvalidServiceReference(): void { $container = $this->getContainer([ 'options' => [ - 'before_breadcrumb' => '@event_dispatcher', - ], + 'before_breadcrumb' => '@event_dispatcher', + ], ]); $this->expectException(\TypeError::class); @@ -337,8 +334,24 @@ public function testIntegrations(): void ]); $integrations = $this->getOptionsFrom($container)->getIntegrations(); - $this->assertContainsOnlyInstancesOf(IntegrationMock::class, $integrations); - $this->assertCount(1, $integrations); + $this->assertNotEmpty($integrations); + + $found = false; + foreach ($integrations as $integration) { + if ($integration instanceof ErrorListenerIntegration) { + $this->fail('Should not have ErrorListenerIntegration registered'); + } + + if ($integration instanceof ExceptionListenerIntegration) { + $this->fail('Should not have ExceptionListenerIntegration registered'); + } + + if ($integration instanceof IntegrationMock) { + $found = true; + } + } + + $this->assertTrue($found, 'No IntegrationMock found in final integrations enabled'); } /** @@ -449,7 +462,7 @@ private function getContainer(array $configuration = []): Container $hub = $this->prophesize(HubInterface::class); $hub->bindClient(Argument::type(ClientMock::class)); - SentryBundle::setCurrentHub($hub->reveal()); + SentrySdk::setCurrentHub($hub->reveal()); $containerBuilder->compile(); @@ -458,7 +471,10 @@ private function getContainer(array $configuration = []): Container private function getOptionsFrom(Container $container): Options { - $this->assertTrue($container->has(self::OPTIONS_TEST_PUBLIC_ALIAS), 'Options (or public alias) missing from container!'); + $this->assertTrue( + $container->has(self::OPTIONS_TEST_PUBLIC_ALIAS), + 'Options (or public alias) missing from container!' + ); $options = $container->get(self::OPTIONS_TEST_PUBLIC_ALIAS); $this->assertInstanceOf(Options::class, $options); diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index f6690e37..b99b9e31 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -16,6 +16,9 @@ class_alias(TestCase::class, \PHPUnit_Framework_TestCase::class); class_alias(Client::class, KernelBrowser::class); } +/** + * @runTestsInSeparateProcesses + */ class End2EndTest extends WebTestCase { protected static function getKernelClass(): string diff --git a/test/EventListener/ConsoleListenerTest.php b/test/EventListener/ConsoleListenerTest.php index f503a4fc..1eb325f6 100644 --- a/test/EventListener/ConsoleListenerTest.php +++ b/test/EventListener/ConsoleListenerTest.php @@ -6,6 +6,7 @@ use Sentry\Event; use Sentry\SentryBundle\EventListener\ConsoleListener; use Sentry\SentryBundle\Test\BaseTestCase; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\Console\Command\Command; @@ -32,7 +33,7 @@ protected function setUp(): void $callable($scope); }); - $this->setCurrentHub($this->currentHub->reveal()); + SentrySdk::setCurrentHub($this->currentHub->reveal()); } public function testOnConsoleCommandAddsCommandName(): void diff --git a/test/EventListener/RequestListenerTest.php b/test/EventListener/RequestListenerTest.php index 9ffe10d7..e6577c55 100644 --- a/test/EventListener/RequestListenerTest.php +++ b/test/EventListener/RequestListenerTest.php @@ -8,6 +8,7 @@ use Sentry\Options; use Sentry\SentryBundle\EventListener\RequestListener; use Sentry\SentryBundle\Test\BaseTestCase; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\HttpFoundation\Request; @@ -48,7 +49,7 @@ protected function setUp(): void $callable($scope); }); - $this->setCurrentHub($this->currentHub->reveal()); + SentrySdk::setCurrentHub($this->currentHub->reveal()); } /** diff --git a/test/EventListener/SubRequestListenerTest.php b/test/EventListener/SubRequestListenerTest.php index 77c49386..317fe9cb 100644 --- a/test/EventListener/SubRequestListenerTest.php +++ b/test/EventListener/SubRequestListenerTest.php @@ -4,6 +4,7 @@ use Sentry\SentryBundle\EventListener\SubRequestListener; use Sentry\SentryBundle\Test\BaseTestCase; +use Sentry\SentrySdk; use Sentry\State\HubInterface; use Sentry\State\Scope; use Symfony\Component\HttpFoundation\Request; @@ -18,7 +19,7 @@ protected function setUp(): void { $this->currentHub = $this->prophesize(HubInterface::class); - $this->setCurrentHub($this->currentHub->reveal()); + SentrySdk::setCurrentHub($this->currentHub->reveal()); } public function testOnKernelRequestWithMasterRequest(): void diff --git a/test/SentryBundleTest.php b/test/SentryBundleTest.php index 16cfdfa7..a8d6ada4 100644 --- a/test/SentryBundleTest.php +++ b/test/SentryBundleTest.php @@ -13,7 +13,7 @@ use Sentry\SentryBundle\EventListener\ErrorListener; use Sentry\SentryBundle\EventListener\RequestListener; use Sentry\SentryBundle\EventListener\SubRequestListener; -use Sentry\SentryBundle\SentryBundle; +use Sentry\SentrySdk; use Sentry\State\Hub; use Sentry\State\HubInterface; use Symfony\Component\Console\ConsoleEvents; @@ -97,7 +97,7 @@ public function testContainerHasErrorListenerConfiguredCorrectly(): void $consoleListener = $container->getDefinition(ErrorListener::class); - $method = class_exists(ExceptionEvent::class) + $method = class_exists(ExceptionEvent::class) && method_exists(ExceptionEvent::class, 'getThrowable') ? 'onException' : 'onKernelException'; $expectedTag = [ @@ -151,7 +151,7 @@ private function getContainer(array $configuration = []): ContainerBuilder $extension = new SentryExtension(); $extension->load(['sentry' => $configuration], $containerBuilder); - SentryBundle::setCurrentHub(new Hub()); + SentrySdk::setCurrentHub(new Hub()); return $containerBuilder; }