5
5
use Sentry \FlushableClientInterface ;
6
6
use Sentry \SentryBundle \EventListener \MessengerListener ;
7
7
use Sentry \SentryBundle \Test \BaseTestCase ;
8
+ use Sentry \State \HubInterface ;
8
9
use Symfony \Component \Messenger \Envelope ;
9
10
use Symfony \Component \Messenger \Event \WorkerMessageFailedEvent ;
10
11
use Symfony \Component \Messenger \Event \WorkerMessageHandledEvent ;
13
14
14
15
class MessengerListenerTest extends BaseTestCase
15
16
{
17
+ /** @var \Prophecy\Prophecy\ObjectProphecy|FlushableClientInterface */
16
18
private $ client ;
19
+ /** @var \Prophecy\Prophecy\ObjectProphecy|HubInterface */
20
+ private $ hub ;
17
21
18
22
protected function setUp (): void
19
23
{
20
24
parent ::setUp ();
21
25
22
26
$ this ->client = $ this ->prophesize (FlushableClientInterface::class);
27
+ $ this ->hub = $ this ->prophesize (HubInterface::class);
28
+ $ this ->hub ->getClient ()->willReturn ($ this ->client );
23
29
}
24
30
25
31
public function testSoftFailsAreRecorded (): void
@@ -34,10 +40,10 @@ public function testSoftFailsAreRecorded(): void
34
40
$ error = new \RuntimeException ();
35
41
$ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
36
42
37
- $ this ->client ->captureException ($ error )->shouldBeCalled ();
43
+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
38
44
$ this ->client ->flush ()->shouldBeCalled ();
39
45
40
- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
46
+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
41
47
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , true );
42
48
43
49
$ listener ->onWorkerMessageFailed ($ event );
@@ -54,10 +60,10 @@ public function testNonMessengerErrorsAreRecorded(): void
54
60
55
61
$ error = new \RuntimeException ();
56
62
57
- $ this ->client ->captureException ($ error )->shouldBeCalled ();
63
+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
58
64
$ this ->client ->flush ()->shouldBeCalled ();
59
65
60
- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
66
+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
61
67
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ error , false );
62
68
63
69
$ listener ->onWorkerMessageFailed ($ event );
@@ -75,10 +81,10 @@ public function testHardFailsAreRecorded(): void
75
81
$ error = new \RuntimeException ();
76
82
$ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
77
83
78
- $ this ->client ->captureException ($ error )->shouldBeCalled ();
84
+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
79
85
$ this ->client ->flush ()->shouldBeCalled ();
80
86
81
- $ listener = new MessengerListener ($ this ->client ->reveal (), true );
87
+ $ listener = new MessengerListener ($ this ->hub ->reveal (), true );
82
88
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
83
89
84
90
$ listener ->onWorkerMessageFailed ($ event );
@@ -96,10 +102,10 @@ public function testSoftFailsAreNotRecorded(): void
96
102
$ error = new \RuntimeException ();
97
103
$ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
98
104
99
- $ this ->client ->captureException ($ error )->shouldNotBeCalled ();
105
+ $ this ->hub ->captureException ($ error )->shouldNotBeCalled ();
100
106
$ this ->client ->flush ()->shouldNotBeCalled ();
101
107
102
- $ listener = new MessengerListener ($ this ->client ->reveal (), false );
108
+ $ listener = new MessengerListener ($ this ->hub ->reveal (), false );
103
109
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , true );
104
110
105
111
$ listener ->onWorkerMessageFailed ($ event );
@@ -117,10 +123,10 @@ public function testHardFailsAreRecordedWithCaptureSoftDisabled(): void
117
123
$ error = new \RuntimeException ();
118
124
$ wrappedError = new HandlerFailedException ($ envelope , [$ error ]);
119
125
120
- $ this ->client ->captureException ($ error )->shouldBeCalled ();
126
+ $ this ->hub ->captureException ($ error )->shouldBeCalled ();
121
127
$ this ->client ->flush ()->shouldBeCalled ();
122
128
123
- $ listener = new MessengerListener ($ this ->client ->reveal (), false );
129
+ $ listener = new MessengerListener ($ this ->hub ->reveal (), false );
124
130
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
125
131
126
132
$ listener ->onWorkerMessageFailed ($ event );
@@ -140,11 +146,11 @@ public function testHandlerFailedExceptionIsUnwrapped(): void
140
146
141
147
$ event = $ this ->getMessageFailedEvent ($ envelope , 'receiver ' , $ wrappedError , false );
142
148
143
- $ this ->client ->captureException ($ error1 )->shouldBeCalled ();
144
- $ this ->client ->captureException ($ error2 )->shouldBeCalled ();
149
+ $ this ->hub ->captureException ($ error1 )->shouldBeCalled ();
150
+ $ this ->hub ->captureException ($ error2 )->shouldBeCalled ();
145
151
$ this ->client ->flush ()->shouldBeCalled ();
146
152
147
- $ listener = new MessengerListener ($ this ->client ->reveal ());
153
+ $ listener = new MessengerListener ($ this ->hub ->reveal ());
148
154
$ listener ->onWorkerMessageFailed ($ event );
149
155
}
150
156
@@ -155,7 +161,7 @@ public function testClientIsFlushedWhenMessageHandled(): void
155
161
}
156
162
157
163
$ this ->client ->flush ()->shouldBeCalled ();
158
- $ listener = new MessengerListener ($ this ->client ->reveal ());
164
+ $ listener = new MessengerListener ($ this ->hub ->reveal ());
159
165
160
166
$ message = (object ) ['foo ' => 'bar ' ];
161
167
$ envelope = Envelope::wrap ($ message );
0 commit comments