From e62ae6ddcee43f941cbee4c1008e15d5306ab551 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 12 Feb 2020 10:57:30 +0100 Subject: [PATCH 01/16] Reinforce E2E tests with log of sent events --- test/End2End/App/config.yml | 9 +++++++++ test/End2End/End2EndTest.php | 28 ++++++++++++++++++++++++++ test/End2End/StubTransportFactory.php | 29 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 test/End2End/StubTransportFactory.php diff --git a/test/End2End/App/config.yml b/test/End2End/App/config.yml index 7f966599..2f8bf5a1 100644 --- a/test/End2End/App/config.yml +++ b/test/End2End/App/config.yml @@ -8,6 +8,15 @@ services: alias: Sentry\State\HubInterface public: true + Sentry\ClientBuilderInterface: + class: Sentry\ClientBuilder + 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/End2EndTest.php b/test/End2End/End2EndTest.php index b99b9e31..a645c086 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -21,11 +21,27 @@ class_alias(Client::class, KernelBrowser::class); */ class End2EndTest extends WebTestCase { + public const SENT_EVENTS_LOG = '/tmp/sentry_e2e_test_sent_events.log'; + protected static function getKernelClass(): string { return Kernel::class; } + protected function setUp(): void + { + parent::setUp(); + + $this->assertEmpty(file_get_contents(self::SENT_EVENTS_LOG), 'Sent events log is not empty before starting test!'); + } + + protected function tearDown(): void + { + parent::tearDown(); + + file_put_contents(self::SENT_EVENTS_LOG, ''); + } + public function testGet200(): void { $client = static::createClient(['debug' => false]); @@ -38,6 +54,7 @@ public function testGet200(): void $this->assertSame(200, $response->getStatusCode()); $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); } public function testGet200BehindFirewall(): void @@ -52,6 +69,7 @@ public function testGet200BehindFirewall(): void $this->assertSame(200, $response->getStatusCode()); $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); } public function testGet200WithSubrequest(): void @@ -66,6 +84,7 @@ public function testGet200WithSubrequest(): void $this->assertSame(200, $response->getStatusCode()); $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); } public function testGet404(): void @@ -88,6 +107,7 @@ public function testGet404(): void } $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); } public function testGet500(): void @@ -111,6 +131,7 @@ public function testGet500(): void } $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); } private function assertLastEventIdIsNotNull(KernelBrowser $client): void @@ -123,4 +144,11 @@ private function assertLastEventIdIsNotNull(KernelBrowser $client): void $this->assertNotNull($hub->getLastEventId(), 'Last error not captured'); } + + private function assertEventCount(int $expectedCount): void + { + $events = file_get_contents(self::SENT_EVENTS_LOG); + $this->assertNotFalse($events, 'Cannot read sent events log'); + $this->assertCount($expectedCount, explode(PHP_EOL, trim($events)), 'Wrong number of events sent: ' . PHP_EOL . $events); + } } diff --git a/test/End2End/StubTransportFactory.php b/test/End2End/StubTransportFactory.php new file mode 100644 index 00000000..bea31ef6 --- /dev/null +++ b/test/End2End/StubTransportFactory.php @@ -0,0 +1,29 @@ +getId() . ': ' . $event->getExceptions()[0]['value'] . PHP_EOL, + FILE_APPEND + ); + + return $event->getId(); + } + }; + } +} From d2709de1679eb7ba8e405b7d6295f3eb9ae790df Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 12 Feb 2020 11:05:54 +0100 Subject: [PATCH 02/16] Add failing test for notices --- test/End2End/App/Controller/MainController.php | 7 +++++++ test/End2End/App/config.yml | 4 ++++ test/End2End/App/routing.yml | 4 ++++ test/End2End/End2EndTest.php | 14 ++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/test/End2End/App/Controller/MainController.php b/test/End2End/App/Controller/MainController.php index 6fdb9c23..429877df 100644 --- a/test/End2End/App/Controller/MainController.php +++ b/test/End2End/App/Controller/MainController.php @@ -38,6 +38,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 2f8bf5a1..3fb121a0 100644 --- a/test/End2End/App/config.yml +++ b/test/End2End/App/config.yml @@ -1,3 +1,7 @@ +sentry: + options: + capture_silenced_errors: true + framework: router: { resource: "%routing_config_dir%/routing.yml" } secret: secret diff --git a/test/End2End/App/routing.yml b/test/End2End/App/routing.yml index 651fd22c..3f2a9c43 100644 --- a/test/End2End/App/routing.yml +++ b/test/End2End/App/routing.yml @@ -13,3 +13,7 @@ secured200: subrequest: path: /subrequest defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::subrequest' } + +notice: + path: /notice + defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::notice' } diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index a645c086..fea0a80f 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -134,6 +134,20 @@ public function testGet500(): void $this->assertEventCount(1); } + public function testNotice(): void + { + $client = static::createClient(); + $client->request('GET', '/notice'); + + $response = $client->getResponse(); + + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(200, $response->getStatusCode()); + + $this->assertLastEventIdIsNotNull($client); + $this->assertEventCount(1); + } + private function assertLastEventIdIsNotNull(KernelBrowser $client): void { $container = $client->getContainer(); From 2a9d57e5ad35b79305040ef134a88d354d9a8f4d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 17:42:08 +0100 Subject: [PATCH 03/16] Fix wrong setup in test --- test/End2End/End2EndTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index fea0a80f..deaab058 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -32,13 +32,6 @@ protected function setUp(): void { parent::setUp(); - $this->assertEmpty(file_get_contents(self::SENT_EVENTS_LOG), 'Sent events log is not empty before starting test!'); - } - - protected function tearDown(): void - { - parent::tearDown(); - file_put_contents(self::SENT_EVENTS_LOG, ''); } From e7745c39f2f4e3bd955e814d6c92fd83543e8a1f Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 18:34:40 +0100 Subject: [PATCH 04/16] Improve E2E tests; add case for fatals --- .../End2End/App/Controller/MainController.php | 7 +++++ test/End2End/App/config.yml | 3 ++ test/End2End/App/routing.yml | 4 +++ test/End2End/End2EndTest.php | 30 ++++++++++++++++++- test/End2End/StubTransportFactory.php | 15 ++++++++-- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/test/End2End/App/Controller/MainController.php b/test/End2End/App/Controller/MainController.php index 429877df..3ea8a2f0 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 = new class() implements \Serializable {}; + + return new Response('This response should not happen: ' . json_encode($foo)); + } + public function index(): Response { $this->sentry->captureMessage('Hello there'); diff --git a/test/End2End/App/config.yml b/test/End2End/App/config.yml index 3fb121a0..a2b3f542 100644 --- a/test/End2End/App/config.yml +++ b/test/End2End/App/config.yml @@ -1,6 +1,7 @@ sentry: options: capture_silenced_errors: true + error_types: E_ALL framework: router: { resource: "%routing_config_dir%/routing.yml" } @@ -14,6 +15,8 @@ services: Sentry\ClientBuilderInterface: class: Sentry\ClientBuilder + arguments: + - '@Sentry\Options' calls: - method: setTransportFactory arguments: diff --git a/test/End2End/App/routing.yml b/test/End2End/App/routing.yml index 3f2a9c43..fd0fd0ac 100644 --- a/test/End2End/App/routing.yml +++ b/test/End2End/App/routing.yml @@ -2,6 +2,10 @@ exception: path: /exception defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::exception' } +fatal: + path: /fatal + defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::fatal' } + 200: path: /200 defaults: { _controller: 'Sentry\SentryBundle\Test\End2End\App\Controller\MainController::index' } diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index deaab058..10be6295 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -3,6 +3,7 @@ namespace Sentry\SentryBundle\Test\End2End; use PHPUnit\Framework\TestCase; +use Sentry\SentryBundle\Test\End2End\App\Controller\MainController; use Sentry\SentryBundle\Test\End2End\App\Kernel; use Sentry\State\HubInterface; use Symfony\Bundle\FrameworkBundle\Client; @@ -127,6 +128,32 @@ public function testGet500(): void $this->assertEventCount(1); } + public function testGetFatal(): void + { + $client = static::createClient(); + + try { + $client->insulate(true); + $client->request('GET', '/fatal'); + + $response = $client->getResponse(); + + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(500, $response->getStatusCode()); + $this->assertStringNotContainsString('not happen', $response->getContent() ?: ''); + } catch (\Throwable $exception) { + if (! $exception instanceof \RuntimeException) { + throw $exception; + } + + $this->assertStringContainsStringIgnoringCase('error', $exception->getMessage()); + $this->assertStringContainsStringIgnoringCase('contains 2 abstract methods', $exception->getMessage()); + $this->assertStringContainsStringIgnoringCase(MainController::class, $exception->getMessage()); + } + + $this->assertEventCount(1); + } + public function testNotice(): void { $client = static::createClient(); @@ -156,6 +183,7 @@ private function assertEventCount(int $expectedCount): void { $events = file_get_contents(self::SENT_EVENTS_LOG); $this->assertNotFalse($events, 'Cannot read sent events log'); - $this->assertCount($expectedCount, explode(PHP_EOL, trim($events)), 'Wrong number of events sent: ' . PHP_EOL . $events); + $listOfEvents = array_filter(explode(StubTransportFactory::SEPARATOR, $events), 'trim'); + $this->assertCount($expectedCount, $listOfEvents, 'Wrong number of events sent: ' . PHP_EOL . $events); } } diff --git a/test/End2End/StubTransportFactory.php b/test/End2End/StubTransportFactory.php index bea31ef6..e44bdfa5 100644 --- a/test/End2End/StubTransportFactory.php +++ b/test/End2End/StubTransportFactory.php @@ -9,16 +9,27 @@ class StubTransportFactory implements TransportFactoryInterface { + public const SEPARATOR = '###'; + public function create(Options $options): TransportInterface { return new class() implements TransportInterface { + public function send(Event $event): ?string { touch(End2EndTest::SENT_EVENTS_LOG); + if ($event->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() . ': ' . $event->getExceptions()[0]['value'] . PHP_EOL, + End2EndTest::SENT_EVENTS_LOG, + $event->getId() . ': ' . $message . PHP_EOL . StubTransportFactory::SEPARATOR . PHP_EOL, FILE_APPEND ); From c29244f1df6b747b6184dea99f335fc6b0cbc7f8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 18:46:52 +0100 Subject: [PATCH 05/16] Try to revert the integration disabling to have the full error reporting back --- src/DependencyInjection/SentryExtension.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/DependencyInjection/SentryExtension.php b/src/DependencyInjection/SentryExtension.php index 5cb92616..56098f40 100644 --- a/src/DependencyInjection/SentryExtension.php +++ b/src/DependencyInjection/SentryExtension.php @@ -134,10 +134,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $ $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); } - $integrationsCallable = new Definition('callable', [$integrations]); - $integrationsCallable->setFactory([IntegrationFilterFactory::class, 'create']); - - $options->addMethodCall('setIntegrations', [$integrationsCallable]); + $options->addMethodCall('setIntegrations', [$integrations]); } private function valueToCallable($value) From 7c40efc38fcb887458e3b5f3be6b45a9fe9e0071 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 18:54:59 +0100 Subject: [PATCH 06/16] Fix test after last modification --- test/DependencyInjection/SentryExtensionTest.php | 8 -------- test/SentryBundleTest.php | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/test/DependencyInjection/SentryExtensionTest.php b/test/DependencyInjection/SentryExtensionTest.php index c8233e29..aaebba07 100644 --- a/test/DependencyInjection/SentryExtensionTest.php +++ b/test/DependencyInjection/SentryExtensionTest.php @@ -337,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/SentryBundleTest.php b/test/SentryBundleTest.php index a8d6ada4..9c65bb73 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(array $configuration = []): ContainerBuilder From 9eee9918be8eda383ea7896526ecd3c5659bd9d5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 19:00:59 +0100 Subject: [PATCH 07/16] Require --dev symfony/process for client isolation --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index f907e6dc..636fb87a 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "symfony/framework-bundle": "^3.4||^4.0||^5.0", "symfony/monolog-bundle": "^3.4", "symfony/phpunit-bridge": "^5.0", + "symfony/process": "^3.4||^4.0||^5.0", "symfony/yaml": "^3.4||^4.0||^5.0" }, "suggest": { From a01ea13e5c70e8bd20a2b7bd3a47a0217f16e5d9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 19:01:30 +0100 Subject: [PATCH 08/16] Do not capture deprecations in E2E tests --- test/End2End/App/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/End2End/App/config.yml b/test/End2End/App/config.yml index a2b3f542..684c93cc 100644 --- a/test/End2End/App/config.yml +++ b/test/End2End/App/config.yml @@ -1,7 +1,7 @@ sentry: options: capture_silenced_errors: true - error_types: E_ALL + error_types: E_ALL & ~E_USER_DEPRECATED framework: router: { resource: "%routing_config_dir%/routing.yml" } From ecd8d883fad38342ccbcf38f2f447afa313a571d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 19:13:05 +0100 Subject: [PATCH 09/16] Fix CS --- test/DependencyInjection/SentryExtensionTest.php | 2 -- test/End2End/App/Controller/MainController.php | 5 +++-- test/End2End/StubTransportFactory.php | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/DependencyInjection/SentryExtensionTest.php b/test/DependencyInjection/SentryExtensionTest.php index aaebba07..22c696e8 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; diff --git a/test/End2End/App/Controller/MainController.php b/test/End2End/App/Controller/MainController.php index 3ea8a2f0..cf6f377d 100644 --- a/test/End2End/App/Controller/MainController.php +++ b/test/End2End/App/Controller/MainController.php @@ -33,8 +33,9 @@ public function exception(): Response public function fatal(): Response { - $foo = new class() implements \Serializable {}; - + $foo = new class() implements \Serializable { + }; + return new Response('This response should not happen: ' . json_encode($foo)); } diff --git a/test/End2End/StubTransportFactory.php b/test/End2End/StubTransportFactory.php index e44bdfa5..0e375505 100644 --- a/test/End2End/StubTransportFactory.php +++ b/test/End2End/StubTransportFactory.php @@ -14,7 +14,6 @@ class StubTransportFactory implements TransportFactoryInterface public function create(Options $options): TransportInterface { return new class() implements TransportInterface { - public function send(Event $event): ?string { touch(End2EndTest::SENT_EVENTS_LOG); @@ -29,7 +28,7 @@ public function send(Event $event): ?string file_put_contents( End2EndTest::SENT_EVENTS_LOG, - $event->getId() . ': ' . $message . PHP_EOL . StubTransportFactory::SEPARATOR . PHP_EOL, + $event->getId() . ': ' . $message . PHP_EOL . StubTransportFactory::SEPARATOR . PHP_EOL, FILE_APPEND ); From 17dde7a1c32d082c82938512bf9000dc4ff8601f Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 28 Feb 2020 19:15:31 +0100 Subject: [PATCH 10/16] Fix PHPStan --- phpstan.neon | 40 +++++++++++++++++++----------------- test/End2End/End2EndTest.php | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ea1b0e4b..99c1db3f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,26 +3,28 @@ parameters: paths: - src/ - test/ + excludes_analyse: + - test/End2End/App/Controller/MainController.php 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./" - - '/Class PHPUnit_Framework_TestCase not found/' - - '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/' - - - message: '/Symfony\\Bundle\\FrameworkBundle\\Client/' - path: test/End2End/End2EndTest.php - - - message: '/^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root...$/' - path: src/DependencyInjection/Configuration.php - - - message: '/Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent.$/' - path: src/EventListener/ErrorListener.php - - - message: '/Sentry\\SentryBundle\\EventListener\\RequestListener(Request|Controller)Event( not found)?.$/' - path: src/EventListener/RequestListener.php - - - message: '/Sentry\\SentryBundle\\EventListener\\SubRequestListenerRequestEvent( not found)?.$/' - path: src/EventListener/SubRequestListener.php + - "/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./" + - '/Class PHPUnit_Framework_TestCase not found/' + - '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/' + - + message: '/Symfony\\Bundle\\FrameworkBundle\\Client/' + path: test/End2End/End2EndTest.php + - + message: '/^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root...$/' + path: src/DependencyInjection/Configuration.php + - + message: '/Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent.$/' + path: src/EventListener/ErrorListener.php + - + message: '/Sentry\\SentryBundle\\EventListener\\RequestListener(Request|Controller)Event( not found)?.$/' + path: src/EventListener/RequestListener.php + - + message: '/Sentry\\SentryBundle\\EventListener\\SubRequestListenerRequestEvent( not found)?.$/' + path: src/EventListener/SubRequestListener.php includes: - vendor/jangregor/phpstan-prophecy/src/extension.neon diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index 10be6295..7897c3c8 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -183,7 +183,7 @@ private function assertEventCount(int $expectedCount): void { $events = file_get_contents(self::SENT_EVENTS_LOG); $this->assertNotFalse($events, 'Cannot read sent events log'); - $listOfEvents = array_filter(explode(StubTransportFactory::SEPARATOR, $events), 'trim'); + $listOfEvents = array_filter(explode(StubTransportFactory::SEPARATOR, trim($events))); $this->assertCount($expectedCount, $listOfEvents, 'Wrong number of events sent: ' . PHP_EOL . $events); } } From dc66c80e2be9ac032dd365a79488d73a40c122dd Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 29 Feb 2020 22:02:55 +0100 Subject: [PATCH 11/16] Fix last PHPStan error --- phpstan.neon | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 99c1db3f..8c571be4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,7 +8,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./" - - '/Class PHPUnit_Framework_TestCase not found/' - '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/' - message: '/Symfony\\Bundle\\FrameworkBundle\\Client/' From 3a5df248ac10fab543b45b1b4f04652a72965ec0 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 16 Mar 2020 09:36:44 +0100 Subject: [PATCH 12/16] Remove unneeded alias --- test/End2End/End2EndTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index 7897c3c8..bfc88c98 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -2,7 +2,6 @@ namespace Sentry\SentryBundle\Test\End2End; -use PHPUnit\Framework\TestCase; use Sentry\SentryBundle\Test\End2End\App\Controller\MainController; use Sentry\SentryBundle\Test\End2End\App\Kernel; use Sentry\State\HubInterface; @@ -12,7 +11,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -class_alias(TestCase::class, \PHPUnit_Framework_TestCase::class); if (! class_exists(KernelBrowser::class)) { class_alias(Client::class, KernelBrowser::class); } From 029c42b27515de6178de6b5262f435ea8aec4e08 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 16 Mar 2020 09:36:51 +0100 Subject: [PATCH 13/16] Remove unused class --- .../IntegrationFilterFactory.php | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/DependencyInjection/IntegrationFilterFactory.php diff --git a/src/DependencyInjection/IntegrationFilterFactory.php b/src/DependencyInjection/IntegrationFilterFactory.php deleted file mode 100644 index f74138d1..00000000 --- a/src/DependencyInjection/IntegrationFilterFactory.php +++ /dev/null @@ -1,32 +0,0 @@ - Date: Mon, 16 Mar 2020 10:06:56 +0100 Subject: [PATCH 14/16] Try to avoid double reporting of fatal errors --- src/DependencyInjection/SentryExtension.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DependencyInjection/SentryExtension.php b/src/DependencyInjection/SentryExtension.php index 56098f40..ec5961f6 100644 --- a/src/DependencyInjection/SentryExtension.php +++ b/src/DependencyInjection/SentryExtension.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\ErrorHandler\Error\FatalError; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -126,13 +127,13 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $ } } - if (\array_key_exists('excluded_exceptions', $processedOptions) && $processedOptions['excluded_exceptions']) { - $ignoreOptions = [ - 'ignore_exceptions' => $processedOptions['excluded_exceptions'], - ]; + // we ignore fatal errors wrapped by Symfony because they produce double event reporting + $processedOptions['excluded_exceptions'][] = FatalError::class; + $ignoreOptions = [ + 'ignore_exceptions' => $processedOptions['excluded_exceptions'], + ]; - $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); - } + $integrations[] = new Definition(IgnoreErrorsIntegration::class, [$ignoreOptions]); $options->addMethodCall('setIntegrations', [$integrations]); } From b46341ad537332adbdab9eb637d23d33a2237d68 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 23 Mar 2020 10:31:45 +0100 Subject: [PATCH 15/16] Add changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 801d43df..fbe951ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased - - ... + - Enable back all error listeners from base SDK integration (#322) ## 3.4.3 (2020-02-03) - Change default of `in_app_include` to empty, due to getsentry/sentry-php#958 (#311) From 53f92b0e8c90034388bc6ea9a7a59e9cee34b136 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 15 May 2020 11:29:38 +0200 Subject: [PATCH 16/16] Fix after-merge issues --- phpstan-baseline.neon | 5 ----- test/End2End/App/Controller/MainController.php | 3 +-- test/End2End/End2EndTest.php | 10 +++------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 00067d1e..4bc8e729 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -235,11 +235,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/test/End2End/App/Controller/MainController.php b/test/End2End/App/Controller/MainController.php index cf6f377d..500cccd1 100644 --- a/test/End2End/App/Controller/MainController.php +++ b/test/End2End/App/Controller/MainController.php @@ -33,8 +33,7 @@ public function exception(): Response public function fatal(): Response { - $foo = new class() implements \Serializable { - }; + $foo = eval("return new class() implements \Serializable {};"); return new Response('This response should not happen: ' . json_encode($foo)); } diff --git a/test/End2End/End2EndTest.php b/test/End2End/End2EndTest.php index bfc88c98..bc78da3a 100644 --- a/test/End2End/End2EndTest.php +++ b/test/End2End/End2EndTest.php @@ -2,7 +2,6 @@ namespace Sentry\SentryBundle\Test\End2End; -use Sentry\SentryBundle\Test\End2End\App\Controller\MainController; use Sentry\SentryBundle\Test\End2End\App\Kernel; use Sentry\State\HubInterface; use Symfony\Bundle\FrameworkBundle\Client; @@ -139,14 +138,11 @@ public function testGetFatal(): void $this->assertInstanceOf(Response::class, $response); $this->assertSame(500, $response->getStatusCode()); $this->assertStringNotContainsString('not happen', $response->getContent() ?: ''); - } catch (\Throwable $exception) { - if (! $exception instanceof \RuntimeException) { - throw $exception; - } - + } catch (\RuntimeException $exception) { $this->assertStringContainsStringIgnoringCase('error', $exception->getMessage()); $this->assertStringContainsStringIgnoringCase('contains 2 abstract methods', $exception->getMessage()); - $this->assertStringContainsStringIgnoringCase(MainController::class, $exception->getMessage()); + $this->assertStringContainsStringIgnoringCase('MainController.php', $exception->getMessage()); + $this->assertStringContainsStringIgnoringCase('eval()\'d code on line', $exception->getMessage()); } $this->assertEventCount(1);