|
9 | 9 | use Sentry\SentryBundle\EventListener\SentryExceptionListenerInterface;
|
10 | 10 | use Sentry\SentryBundle\SentrySymfonyEvents;
|
11 | 11 | use Symfony\Component\Console\Command\Command;
|
| 12 | +use Symfony\Component\Console\Event\ConsoleCommandEvent; |
12 | 13 | use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
13 | 14 | use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
| 15 | +use Symfony\Component\Console\Event\ConsoleTerminateEvent; |
14 | 16 | use Symfony\Component\Console\Input\InputInterface;
|
15 | 17 | use Symfony\Component\Console\Output\OutputInterface;
|
16 | 18 | use Symfony\Component\DependencyInjection\Alias;
|
17 | 19 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
18 | 20 | use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
19 | 21 | use Symfony\Component\HttpFoundation\Request;
|
20 | 22 | use Symfony\Component\HttpFoundation\RequestStack;
|
| 23 | +use Symfony\Component\HttpKernel\Event\FinishRequestEvent; |
21 | 24 | use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
22 | 25 | use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
23 | 26 | use Symfony\Component\HttpKernel\Exception\HttpException;
|
@@ -438,6 +441,58 @@ public function test_that_ip_is_set_from_request_stack()
|
438 | 441 | $listener->onKernelRequest($mockEvent);
|
439 | 442 | }
|
440 | 443 |
|
| 444 | + public function test_that_it_sets_transaction_from_route() |
| 445 | + { |
| 446 | + $mockEvent = $this->createMock(GetResponseEvent::class); |
| 447 | + |
| 448 | + $request = new Request(); |
| 449 | + $request->attributes->set('_route', 'my_route'); |
| 450 | + $mockEvent |
| 451 | + ->expects($this->once()) |
| 452 | + ->method('getRequest') |
| 453 | + ->willReturn($request); |
| 454 | + |
| 455 | + $mockEvent |
| 456 | + ->method('getRequestType') |
| 457 | + ->willReturn(HttpKernelInterface::SUB_REQUEST); |
| 458 | + |
| 459 | + $mockTransactionStack = $this->createMock(\Raven_TransactionStack::class); |
| 460 | + $this->mockSentryClient->transaction = $mockTransactionStack; |
| 461 | + |
| 462 | + $mockTransactionStack |
| 463 | + ->expects($this->once()) |
| 464 | + ->method('push') |
| 465 | + ->with('my_route'); |
| 466 | + |
| 467 | + $this->containerBuilder->compile(); |
| 468 | + $listener = $this->getListener(); |
| 469 | + $listener->onKernelRequest($mockEvent); |
| 470 | + } |
| 471 | + |
| 472 | + public function test_that_it_pops_transaction_from_route() |
| 473 | + { |
| 474 | + $mockEvent = $this->createMock(FinishRequestEvent::class); |
| 475 | + |
| 476 | + $request = new Request(); |
| 477 | + $request->attributes->set('_route', 'my_route'); |
| 478 | + $mockEvent |
| 479 | + ->expects($this->once()) |
| 480 | + ->method('getRequest') |
| 481 | + ->willReturn($request); |
| 482 | + |
| 483 | + $mockTransactionStack = $this->createMock(\Raven_TransactionStack::class); |
| 484 | + $this->mockSentryClient->transaction = $mockTransactionStack; |
| 485 | + |
| 486 | + $mockTransactionStack |
| 487 | + ->expects($this->once()) |
| 488 | + ->method('pop') |
| 489 | + ->with('my_route'); |
| 490 | + |
| 491 | + $this->containerBuilder->compile(); |
| 492 | + $listener = $this->getListener(); |
| 493 | + $listener->onFinishRequest($mockEvent); |
| 494 | + } |
| 495 | + |
441 | 496 | public function test_regression_with_unauthenticated_user_token_PR_78()
|
442 | 497 | {
|
443 | 498 | $mockToken = $this->createMock(TokenInterface::class);
|
@@ -510,6 +565,29 @@ public function test_that_it_captures_exception()
|
510 | 565 | $listener->onKernelException($mockEvent);
|
511 | 566 | }
|
512 | 567 |
|
| 568 | + public function test_that_it_sets_transaction_from_command() |
| 569 | + { |
| 570 | + $mockEvent = $this->createMock(ConsoleCommandEvent::class); |
| 571 | + |
| 572 | + $command = new Command('my_command'); |
| 573 | + $mockEvent |
| 574 | + ->expects($this->once()) |
| 575 | + ->method('getCommand') |
| 576 | + ->willReturn($command); |
| 577 | + |
| 578 | + $mockTransactionStack = $this->createMock(\Raven_TransactionStack::class); |
| 579 | + $this->mockSentryClient->transaction = $mockTransactionStack; |
| 580 | + |
| 581 | + $mockTransactionStack |
| 582 | + ->expects($this->once()) |
| 583 | + ->method('push') |
| 584 | + ->with('my_command'); |
| 585 | + |
| 586 | + $this->containerBuilder->compile(); |
| 587 | + $listener = $this->getListener(); |
| 588 | + $listener->onConsoleCommand($mockEvent); |
| 589 | + } |
| 590 | + |
513 | 591 | /**
|
514 | 592 | * @dataProvider mockCommandProvider
|
515 | 593 | */
|
@@ -593,6 +671,29 @@ public function test_that_it_captures_console_error(?Command $mockCommand, strin
|
593 | 671 | $listener->onConsoleError($event);
|
594 | 672 | }
|
595 | 673 |
|
| 674 | + public function test_that_it_pops_transaction_from_command() |
| 675 | + { |
| 676 | + $mockEvent = $this->createMock(ConsoleTerminateEvent::class); |
| 677 | + |
| 678 | + $command = new Command('my_command'); |
| 679 | + $mockEvent |
| 680 | + ->expects($this->once()) |
| 681 | + ->method('getCommand') |
| 682 | + ->willReturn($command); |
| 683 | + |
| 684 | + $mockTransactionStack = $this->createMock(\Raven_TransactionStack::class); |
| 685 | + $this->mockSentryClient->transaction = $mockTransactionStack; |
| 686 | + |
| 687 | + $mockTransactionStack |
| 688 | + ->expects($this->once()) |
| 689 | + ->method('pop') |
| 690 | + ->with('my_command'); |
| 691 | + |
| 692 | + $this->containerBuilder->compile(); |
| 693 | + $listener = $this->getListener(); |
| 694 | + $listener->onFinishCommand($mockEvent); |
| 695 | + } |
| 696 | + |
596 | 697 | public function mockCommandProvider()
|
597 | 698 | {
|
598 | 699 | $mockCommand = $this->createMock(Command::class);
|
|
0 commit comments