|
3 | 3 | namespace Sentry\SentryBundle\Test;
|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\TestCase;
|
| 6 | +use Sentry\Integration\ErrorListenerIntegration; |
| 7 | +use Sentry\Integration\ExceptionListenerIntegration; |
| 8 | +use Sentry\Integration\IntegrationInterface; |
| 9 | +use Sentry\Integration\RequestIntegration; |
6 | 10 | use Sentry\SentryBundle\DependencyInjection\SentryExtension;
|
7 | 11 | use Sentry\SentryBundle\EventListener\ConsoleListener;
|
| 12 | +use Sentry\SentryBundle\EventListener\ErrorListener; |
8 | 13 | use Sentry\SentryBundle\EventListener\RequestListener;
|
9 | 14 | use Sentry\SentryBundle\EventListener\SubRequestListener;
|
| 15 | +use Sentry\State\HubInterface; |
10 | 16 | use Symfony\Component\Console\ConsoleEvents;
|
11 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
12 | 18 | use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
@@ -82,10 +88,56 @@ public function testContainerHasSubRequestListenerConfiguredCorrectly(): void
|
82 | 88 | $this->assertSame($expectedTag, $consoleListener->getTags());
|
83 | 89 | }
|
84 | 90 |
|
| 91 | + public function testContainerHasErrorListenerConfiguredCorrectly(): void |
| 92 | + { |
| 93 | + $container = $this->getContainer(); |
| 94 | + |
| 95 | + $consoleListener = $container->getDefinition(ErrorListener::class); |
| 96 | + |
| 97 | + $expectedTag = [ |
| 98 | + 'kernel.event_listener' => [ |
| 99 | + [ |
| 100 | + 'event' => KernelEvents::EXCEPTION, |
| 101 | + 'method' => 'onKernelException', |
| 102 | + 'priority' => '%sentry.listener_priorities.request_error%', |
| 103 | + ], |
| 104 | + ], |
| 105 | + ]; |
| 106 | + |
| 107 | + if (class_exists('Symfony\Component\Console\Event\ConsoleErrorEvent')) { |
| 108 | + $expectedTag['kernel.event_listener'][] = [ |
| 109 | + 'event' => ConsoleEvents::ERROR, |
| 110 | + 'method' => 'onConsoleError', |
| 111 | + 'priority' => '%sentry.listener_priorities.console_error%', |
| 112 | + ]; |
| 113 | + } else { |
| 114 | + $expectedTag['kernel.event_listener'][] = [ |
| 115 | + 'event' => ConsoleEvents::EXCEPTION, |
| 116 | + 'method' => 'onConsoleException', |
| 117 | + 'priority' => '%sentry.listener_priorities.console_error%', |
| 118 | + ]; |
| 119 | + } |
| 120 | + |
| 121 | + $this->assertSame($expectedTag, $consoleListener->getTags()); |
| 122 | + } |
| 123 | + |
| 124 | + public function testIntegrationsListenersAreDisabledByDefault(): void |
| 125 | + { |
| 126 | + $container = $this->getContainer(); |
| 127 | + |
| 128 | + $hub = $container->get(HubInterface::class); |
| 129 | + |
| 130 | + $this->assertInstanceOf(HubInterface::class, $hub); |
| 131 | + $this->assertInstanceOf(IntegrationInterface::class, $hub->getIntegration(RequestIntegration::class)); |
| 132 | + $this->assertNull($hub->getIntegration(ErrorListenerIntegration::class)); |
| 133 | + $this->assertNull($hub->getIntegration(ExceptionListenerIntegration::class)); |
| 134 | + } |
| 135 | + |
85 | 136 | private function getContainer(array $configuration = []): ContainerBuilder
|
86 | 137 | {
|
87 | 138 | $containerBuilder = new ContainerBuilder();
|
88 | 139 | $containerBuilder->setParameter('kernel.root_dir', 'kernel/root');
|
| 140 | + $containerBuilder->setParameter('kernel.cache_dir', 'var/cache'); |
89 | 141 | if (method_exists(Kernel::class, 'getProjectDir')) {
|
90 | 142 | $containerBuilder->setParameter('kernel.project_dir', '/dir/project/root');
|
91 | 143 | }
|
|
0 commit comments