@@ -121,13 +121,17 @@ public function testSendAllDeadWithinRetryPeriod()
121
121
$ t1 ->expects ($ this ->once ())->method ('send ' );
122
122
$ t2 = $ this ->createMock (TransportInterface::class);
123
123
$ t2 ->method ('supports ' )->with ($ message )->willReturn (true );
124
- $ t2 ->expects ($ this ->exactly (3 ))
124
+
125
+ $ matcher = $ this ->exactly (3 );
126
+ $ t2 ->expects ($ matcher )
125
127
->method ('send ' )
126
- ->willReturnOnConsecutiveCalls (
127
- new SentMessage ($ message , 't2 ' ),
128
- new SentMessage ($ message , 't2 ' ),
129
- $ this ->throwException ($ this ->createMock (TransportExceptionInterface::class))
130
- );
128
+ ->willReturnCallback (function () use ($ matcher , $ message ) {
129
+ if (3 === $ matcher ->getInvocationCount ()) {
130
+ throw $ this ->createMock (TransportExceptionInterface::class);
131
+ }
132
+
133
+ return new SentMessage ($ message , 't2 ' );
134
+ });
131
135
$ t = new FailoverTransport ([$ t1 , $ t2 ], 40 );
132
136
$ t ->send ($ message );
133
137
sleep (4 );
@@ -146,16 +150,27 @@ public function testSendOneDeadButRecover()
146
150
147
151
$ t1 = $ this ->createMock (TransportInterface::class);
148
152
$ t1 ->method ('supports ' )->with ($ message )->willReturn (true );
149
- $ t1 ->expects ($ this ->exactly (2 ))->method ('send ' )->willReturnOnConsecutiveCalls (
150
- $ this ->throwException ($ this ->createMock (TransportExceptionInterface::class)),
151
- new SentMessage ($ message , 't1 ' )
152
- );
153
+
154
+ $ t1Matcher = $ this ->exactly (2 );
155
+ $ t1 ->expects ($ t1Matcher )->method ('send ' )
156
+ ->willReturnCallback (function () use ($ t1Matcher , $ message ) {
157
+ if (1 === $ t1Matcher ->getInvocationCount ()) {
158
+ throw $ this ->createMock (TransportExceptionInterface::class);
159
+ }
160
+
161
+ return new SentMessage ($ message , 't1 ' );
162
+ });
153
163
$ t2 = $ this ->createMock (TransportInterface::class);
154
164
$ t2 ->method ('supports ' )->with ($ message )->willReturn (true );
155
- $ t2 ->expects ($ this ->exactly (2 ))->method ('send ' )->willReturnOnConsecutiveCalls (
156
- new SentMessage ($ message , 't2 ' ),
157
- $ this ->throwException ($ this ->createMock (TransportExceptionInterface::class))
158
- );
165
+
166
+ $ t2Matcher = $ this ->exactly (2 );
167
+ $ t2 ->expects ($ t2Matcher )->method ('send ' )->willReturnCallback (function () use ($ t2Matcher , $ message ) {
168
+ if (1 === $ t2Matcher ->getInvocationCount ()) {
169
+ return new SentMessage ($ message , 't1 ' );
170
+ }
171
+
172
+ throw $ this ->createMock (TransportExceptionInterface::class);
173
+ });
159
174
160
175
$ t = new FailoverTransport ([$ t1 , $ t2 ], 1 );
161
176
0 commit comments