@@ -42,21 +42,24 @@ class ExceptionListenerTest extends TestCase
42
42
43
43
private $ mockEventDispatcher ;
44
44
45
- private $ mockRequestStack ;
45
+ /**
46
+ * @var RequestStack
47
+ */
48
+ private $ requestStack ;
46
49
47
50
public function setUp ()
48
51
{
49
52
$ this ->mockTokenStorage = $ this ->createMock (TokenStorageInterface::class);
50
53
$ this ->mockAuthorizationChecker = $ this ->createMock (AuthorizationCheckerInterface::class);
51
54
$ this ->mockSentryClient = $ this ->createMock (\Raven_Client::class);
52
55
$ this ->mockEventDispatcher = $ this ->createMock (EventDispatcherInterface::class);
53
- $ this ->mockRequestStack = $ this -> createMock ( RequestStack::class );
56
+ $ this ->requestStack = new RequestStack ( );
54
57
55
58
$ containerBuilder = new ContainerBuilder ();
56
59
$ containerBuilder ->setParameter ('kernel.root_dir ' , 'kernel/root ' );
57
60
$ containerBuilder ->setParameter ('kernel.environment ' , 'test ' );
58
61
59
- $ containerBuilder ->set ('request_stack ' , $ this ->mockRequestStack );
62
+ $ containerBuilder ->set ('request_stack ' , $ this ->requestStack );
60
63
$ containerBuilder ->set ('security.token_storage ' , $ this ->mockTokenStorage );
61
64
$ containerBuilder ->set ('security.authorization_checker ' , $ this ->mockAuthorizationChecker );
62
65
$ containerBuilder ->set ('sentry.client ' , $ this ->mockSentryClient );
@@ -404,15 +407,9 @@ public function test_that_ip_is_set_from_request_stack()
404
407
405
408
$ mockEvent = $ this ->createMock (GetResponseEvent::class);
406
409
407
- $ mockRequest = $ this ->createMock (Request::class);
408
-
409
- $ mockRequest
410
- ->method ('getClientIp ' )
411
- ->willReturn ('1.2.3.4 ' );
412
-
413
- $ this ->mockRequestStack
414
- ->method ('getCurrentRequest ' )
415
- ->willReturn ($ mockRequest );
410
+ $ this ->requestStack ->push (new Request ([], [], [], [], [], [
411
+ 'REMOTE_ADDR ' => '1.2.3.4 ' ,
412
+ ]));
416
413
417
414
$ mockEvent
418
415
->expects ($ this ->once ())
@@ -510,6 +507,39 @@ public function test_that_it_captures_exception()
510
507
$ listener ->onKernelException ($ mockEvent );
511
508
}
512
509
510
+ public function test_that_it_captures_exception_with_route ()
511
+ {
512
+ $ reportableException = new \Exception ();
513
+
514
+ $ mockEvent = $ this ->createMock (GetResponseForExceptionEvent::class);
515
+ $ mockEvent
516
+ ->expects ($ this ->once ())
517
+ ->method ('getException ' )
518
+ ->willReturn ($ reportableException );
519
+
520
+ $ this ->mockEventDispatcher
521
+ ->expects ($ this ->once ())
522
+ ->method ('dispatch ' )
523
+ ->with ($ this ->identicalTo (SentrySymfonyEvents::PRE_CAPTURE ), $ this ->identicalTo ($ mockEvent ));
524
+
525
+ $ data = [
526
+ 'tags ' => [
527
+ 'route ' => 'homepage ' ,
528
+ ],
529
+ ];
530
+
531
+ $ this ->requestStack ->push (new Request ([], [], ['_route ' => 'homepage ' ]));
532
+
533
+ $ this ->mockSentryClient
534
+ ->expects ($ this ->once ())
535
+ ->method ('captureException ' )
536
+ ->with ($ this ->identicalTo ($ reportableException ), $ data );
537
+
538
+ $ this ->containerBuilder ->compile ();
539
+ $ listener = $ this ->getListener ();
540
+ $ listener ->onKernelException ($ mockEvent );
541
+ }
542
+
513
543
/**
514
544
* @dataProvider mockCommandProvider
515
545
*/
0 commit comments