diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index de8cfaf9..e6e6a1eb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -230,11 +230,6 @@ parameters: count: 1 path: test/End2End/App/Kernel.php - - - message: "#^Class PHPUnit_Framework_TestCase not found\\.$#" - count: 1 - path: test/End2End/End2EndTest.php - - message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#" count: 1 diff --git a/src/DependencyInjection/IntegrationFilterFactory.php b/src/DependencyInjection/IntegrationFilterFactory.php deleted file mode 100644 index e33d6c1f..00000000 --- a/src/DependencyInjection/IntegrationFilterFactory.php +++ /dev/null @@ -1,35 +0,0 @@ - $processedOptions['excluded_exceptions'], - ]; - - $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); - } + // we ignore fatal errors wrapped by Symfony because they produce double event reporting + $processedOptions['excluded_exceptions'][] = FatalError::class; + $ignoreOptions = [ + 'ignore_exceptions' => $processedOptions['excluded_exceptions'], + ]; - $integrationsCallable = new Definition('callable', [$integrations]); - $integrationsCallable->setFactory([IntegrationFilterFactory::class, 'create']); + $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); - $options->addMethodCall('setIntegrations', [$integrationsCallable]); + $options->addMethodCall('setIntegrations', [$integrations]); } /** diff --git a/test/DependencyInjection/SentryExtensionTest.php b/test/DependencyInjection/SentryExtensionTest.php index 0e68b747..b84efb6a 100644 --- a/test/DependencyInjection/SentryExtensionTest.php +++ b/test/DependencyInjection/SentryExtensionTest.php @@ -8,8 +8,6 @@ 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; @@ -339,14 +337,6 @@ public function testIntegrations(): void $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; } diff --git a/test/End2End/App/Controller/MainController.php b/test/End2End/App/Controller/MainController.php index 6fdb9c23..500cccd1 100644 --- a/test/End2End/App/Controller/MainController.php +++ b/test/End2End/App/Controller/MainController.php @@ -31,6 +31,13 @@ public function exception(): Response throw new \RuntimeException('This is an intentional error'); } + public function fatal(): Response + { + $foo = eval("return new class() implements \Serializable {};"); + + return new Response('This response should not happen: ' . json_encode($foo)); + } + public function index(): Response { $this->sentry->captureMessage('Hello there'); @@ -38,6 +45,13 @@ public function index(): Response return new Response('Hello there'); } + public function notice(): Response + { + @trigger_error('This is an intentional notice', E_USER_NOTICE); + + return new Response('Hello there'); + } + public function subrequest(): Response { $request = $this->requestStack->getCurrentRequest(); diff --git a/test/End2End/App/config.yml b/test/End2End/App/config.yml index 7f966599..684c93cc 100644 --- a/test/End2End/App/config.yml +++ b/test/End2End/App/config.yml @@ -1,3 +1,8 @@ +sentry: + options: + capture_silenced_errors: true + error_types: E_ALL & ~E_USER_DEPRECATED + framework: router: { resource: "%routing_config_dir%/routing.yml" } secret: secret @@ -8,6 +13,17 @@ services: alias: Sentry\State\HubInterface public: true + Sentry\ClientBuilderInterface: + class: Sentry\ClientBuilder + arguments: + - '@Sentry\Options' + calls: + - method: setTransportFactory + arguments: + - '@Sentry\SentryBundle\Test\End2End\StubTransportFactory' + + Sentry\SentryBundle\Test\End2End\StubTransportFactory: ~ + Sentry\SentryBundle\Test\End2End\App\Controller\MainController: autowire: true tags: diff --git a/test/End2End/StubTransportFactory.php b/test/End2End/StubTransportFactory.php new file mode 100644 index 00000000..0e375505 --- /dev/null +++ b/test/End2End/StubTransportFactory.php @@ -0,0 +1,39 @@ +getMessage()) { + $message = $event->getMessage(); + } elseif ($event->getExceptions()) { + $message = $event->getExceptions()[0]['value']; + } else { + $message = 'NO MESSAGE NOR EXCEPTIONS'; + } + + file_put_contents( + End2EndTest::SENT_EVENTS_LOG, + $event->getId() . ': ' . $message . PHP_EOL . StubTransportFactory::SEPARATOR . PHP_EOL, + FILE_APPEND + ); + + return $event->getId(); + } + }; + } +} diff --git a/test/SentryBundleTest.php b/test/SentryBundleTest.php index aa91657b..87ad492b 100644 --- a/test/SentryBundleTest.php +++ b/test/SentryBundleTest.php @@ -127,7 +127,7 @@ public function testContainerHasTestCommandRegisteredCorrectly(): void $this->assertArrayHasKey('console.command', $consoleListener->getTags()); } - public function testIntegrationsListenersAreDisabledByDefault(): void + public function testIntegrationsListenersAreEnabled(): void { $container = $this->getContainer(); @@ -135,8 +135,8 @@ public function testIntegrationsListenersAreDisabledByDefault(): void $this->assertInstanceOf(HubInterface::class, $hub); $this->assertInstanceOf(IntegrationInterface::class, $hub->getIntegration(RequestIntegration::class)); - $this->assertNull($hub->getIntegration(ErrorListenerIntegration::class)); - $this->assertNull($hub->getIntegration(ExceptionListenerIntegration::class)); + $this->assertNotNull($hub->getIntegration(ErrorListenerIntegration::class)); + $this->assertNotNull($hub->getIntegration(ExceptionListenerIntegration::class)); } private function getContainer(): ContainerBuilder