|
10 | 10 | use Sentry\SentryBundle\SentrySymfonyEvents; |
11 | 11 | use Symfony\Component\Console\Command\Command; |
12 | 12 | use Symfony\Component\Console\Event\ConsoleErrorEvent; |
| 13 | +use Symfony\Component\Console\Event\ConsoleExceptionEvent; |
13 | 14 | use Symfony\Component\Console\Input\InputInterface; |
14 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
15 | 16 | use Symfony\Component\DependencyInjection\Alias; |
@@ -459,6 +460,47 @@ public function test_that_it_captures_exception() |
459 | 460 | * @dataProvider mockCommandProvider |
460 | 461 | */ |
461 | 462 | public function test_that_it_captures_console_exception(?Command $mockCommand, string $expectedCommandName) |
| 463 | + { |
| 464 | + if (null === $mockCommand) { |
| 465 | + $this->markTestSkipped('Command missing is not possibile with ConsoleExceptionEvent'); |
| 466 | + } |
| 467 | + |
| 468 | + $exception = $this->createMock(\Exception::class); |
| 469 | + /** @var InputInterface $input */ |
| 470 | + $input = $this->createMock(InputInterface::class); |
| 471 | + /** @var OutputInterface $output */ |
| 472 | + $output = $this->createMock(OutputInterface::class); |
| 473 | + |
| 474 | + $event = new ConsoleExceptionEvent($mockCommand, $input, $output, $exception, 10); |
| 475 | + |
| 476 | + $this->mockEventDispatcher |
| 477 | + ->expects($this->once()) |
| 478 | + ->method('dispatch') |
| 479 | + ->with($this->identicalTo(SentrySymfonyEvents::PRE_CAPTURE), $this->identicalTo($event)); |
| 480 | + |
| 481 | + $this->mockSentryClient |
| 482 | + ->expects($this->once()) |
| 483 | + ->method('captureException') |
| 484 | + ->with( |
| 485 | + $this->identicalTo($exception), |
| 486 | + $this->identicalTo([ |
| 487 | + 'tags' => [ |
| 488 | + 'command' => $expectedCommandName, |
| 489 | + 'status_code' => 10, |
| 490 | + ], |
| 491 | + ]) |
| 492 | + ); |
| 493 | + |
| 494 | + $this->containerBuilder->compile(); |
| 495 | + /** @var SentryExceptionListenerInterface $listener */ |
| 496 | + $listener = $this->getListener(); |
| 497 | + $listener->onConsoleException($event); |
| 498 | + } |
| 499 | + |
| 500 | + /** |
| 501 | + * @dataProvider mockCommandProvider |
| 502 | + */ |
| 503 | + public function test_that_it_captures_console_error(?Command $mockCommand, string $expectedCommandName) |
462 | 504 | { |
463 | 505 | $error = $this->createMock(\Error::class); |
464 | 506 | /** @var InputInterface $input */ |
@@ -490,7 +532,7 @@ public function test_that_it_captures_console_exception(?Command $mockCommand, s |
490 | 532 | $this->containerBuilder->compile(); |
491 | 533 | /** @var SentryExceptionListenerInterface $listener */ |
492 | 534 | $listener = $this->getListener(); |
493 | | - $listener->onConsoleException($event); |
| 535 | + $listener->onConsoleError($event); |
494 | 536 | } |
495 | 537 |
|
496 | 538 | public function mockCommandProvider() |
|
0 commit comments