55use Sentry \FlushableClientInterface ;
66use Sentry \SentryBundle \EventListener \MessengerListener ;
77use Sentry \SentryBundle \Test \BaseTestCase ;
8+ use Sentry \State \HubInterface ;
89use Symfony \Component \Messenger \Envelope ;
910use Symfony \Component \Messenger \Event \WorkerMessageFailedEvent ;
1011use Symfony \Component \Messenger \Event \WorkerMessageHandledEvent ;
1314
1415class MessengerListenerTest extends BaseTestCase
1516{
17+ /** @var \Prophecy\Prophecy\ObjectProphecy|FlushableClientInterface */
1618 private $ client ;
19+ /** @var \Prophecy\Prophecy\ObjectProphecy|HubInterface */
20+ private $ hub ;
1721
1822 protected function setUp (): void
1923 {
2024 parent ::setUp ();
2125
2226 $ this ->client = $ this ->prophesize (FlushableClientInterface::class);
27+ $ this ->hub = $ this ->prophesize (HubInterface::class);
28+ $ this ->hub ->getClient ()->willReturn ($ this ->client );
2329 }
2430
2531 public function testSoftFailsAreRecorded (): void
@@ -34,10 +40,10 @@ public function testSoftFailsAreRecorded(): void
3440 $ error = new \RuntimeException ();
3541 $ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
3642
37- $ this ->client ->captureException ($ error )->shouldBeCalled ();
43+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
3844 $ this ->client ->flush ()->shouldBeCalled ();
3945
40- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
46+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
4147 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , true );
4248
4349 $ listener ->onWorkerMessageFailed ($ event );
@@ -54,10 +60,10 @@ public function testNonMessengerErrorsAreRecorded(): void
5460
5561 $ error = new \RuntimeException ();
5662
57- $ this ->client ->captureException ($ error )->shouldBeCalled ();
63+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
5864 $ this ->client ->flush ()->shouldBeCalled ();
5965
60- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
66+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
6167 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ error , false );
6268
6369 $ listener ->onWorkerMessageFailed ($ event );
@@ -75,10 +81,10 @@ public function testHardFailsAreRecorded(): void
7581 $ error = new \RuntimeException ();
7682 $ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
7783
78- $ this ->client ->captureException ($ error )->shouldBeCalled ();
84+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
7985 $ this ->client ->flush ()->shouldBeCalled ();
8086
81- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
87+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
8288 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
8389
8490 $ listener ->onWorkerMessageFailed ($ event );
@@ -96,10 +102,10 @@ public function testSoftFailsAreNotRecorded(): void
96102 $ error = new \RuntimeException ();
97103 $ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
98104
99- $ this ->client ->captureException ($ error )->shouldNotBeCalled ();
105+ $ this ->hub ->captureException ($ error )->shouldNotBeCalled ();
100106 $ this ->client ->flush ()->shouldNotBeCalled ();
101107
102- $ listener = new MessengerListener ($ this ->client ->reveal (), false );
108+ $ listener = new MessengerListener ($ this ->hub ->reveal (), false );
103109 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , true );
104110
105111 $ listener ->onWorkerMessageFailed ($ event );
@@ -117,10 +123,10 @@ public function testHardFailsAreRecordedWithCaptureSoftDisabled(): void
117123 $ error = new \RuntimeException ();
118124 $ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
119125
120- $ this ->client ->captureException ($ error )->shouldBeCalled ();
126+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
121127 $ this ->client ->flush ()->shouldBeCalled ();
122128
123- $ listener = new MessengerListener ($ this ->client ->reveal (), false );
129+ $ listener = new MessengerListener ($ this ->hub ->reveal (), false );
124130 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
125131
126132 $ listener ->onWorkerMessageFailed ($ event );
@@ -140,11 +146,11 @@ public function testHandlerFailedExceptionIsUnwrapped(): void
140146
141147 $ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
142148
143- $ this ->client ->captureException ($ error1 )->shouldBeCalled ();
144- $ this ->client ->captureException ($ error2 )->shouldBeCalled ();
149+ $ this ->hub ->captureException ($ error1 )->shouldBeCalled ();
150+ $ this ->hub ->captureException ($ error2 )->shouldBeCalled ();
145151 $ this ->client ->flush ()->shouldBeCalled ();
146152
147- $ listener = new MessengerListener ($ this ->client ->reveal ());
153+ $ listener = new MessengerListener ($ this ->hub ->reveal ());
148154 $ listener ->onWorkerMessageFailed ($ event );
149155 }
150156
@@ -155,7 +161,7 @@ public function testClientIsFlushedWhenMessageHandled(): void
155161 }
156162
157163 $ this ->client ->flush ()->shouldBeCalled ();
158- $ listener = new MessengerListener ($ this ->client ->reveal ());
164+ $ listener = new MessengerListener ($ this ->hub ->reveal ());
159165
160166 $ message = (object ) ['foo ' => 'bar ' ];
161167 $ envelope = Envelope::wrap ($ message );
0 commit comments