@@ -85,16 +85,30 @@ public function testSendOneDead()
85
85
public function testSendOneDeadAndRecoveryWithinRetryPeriod ()
86
86
{
87
87
$ t1 = $ this ->createMock (TransportInterface::class);
88
- $ t1 ->method ('send ' )->willReturnOnConsecutiveCalls ($ this ->throwException (new TransportException ()));
88
+
89
+ $ t1Matcher = $ this ->any ();
90
+ $ t1 ->expects ($ t1Matcher )
91
+ ->method ('send ' )
92
+ ->willReturnCallback (function () use ($ t1Matcher ) {
93
+ if (1 === $ t1Matcher ->getInvocationCount ()) {
94
+ throw new TransportException ();
95
+ }
96
+
97
+ return null ;
98
+ });
99
+
89
100
$ t2 = $ this ->createMock (TransportInterface::class);
90
- $ t2 ->expects ($ this ->exactly (4 ))
101
+ $ t2Matcher = $ this ->exactly (4 );
102
+ $ t2 ->expects ($ t2Matcher )
91
103
->method ('send ' )
92
- ->willReturnOnConsecutiveCalls (
93
- null ,
94
- null ,
95
- null ,
96
- $ this ->throwException (new TransportException ())
97
- );
104
+ ->willReturnCallback (function () use ($ t2Matcher ) {
105
+ if (4 === $ t2Matcher ->getInvocationCount ()) {
106
+ throw new TransportException ();
107
+ }
108
+
109
+ return null ;
110
+ });
111
+
98
112
$ t = new FailoverTransport ([$ t1 , $ t2 ], 6 );
99
113
$ t ->send (new RawMessage ('' )); // t1>fail - t2>sent
100
114
$ this ->assertTransports ($ t , 0 , [$ t1 ]);
@@ -115,16 +129,19 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
115
129
public function testSendAllDeadWithinRetryPeriod ()
116
130
{
117
131
$ t1 = $ this ->createMock (TransportInterface::class);
118
- $ t1 ->method ('send ' )->will ( $ this -> throwException ( new TransportException () ));
132
+ $ t1 ->method ('send ' )->willThrowException ( new TransportException ());
119
133
$ t1 ->expects ($ this ->once ())->method ('send ' );
120
134
$ t2 = $ this ->createMock (TransportInterface::class);
121
- $ t2 ->expects ($ this ->exactly (3 ))
135
+ $ matcher = $ this ->exactly (3 );
136
+ $ t2 ->expects ($ matcher )
122
137
->method ('send ' )
123
- ->willReturnOnConsecutiveCalls (
124
- null ,
125
- null ,
126
- $ this ->throwException (new TransportException ())
127
- );
138
+ ->willReturnCallback (function () use ($ matcher ) {
139
+ if (3 === $ matcher ->getInvocationCount ()) {
140
+ throw new TransportException ();
141
+ }
142
+
143
+ return null ;
144
+ });
128
145
$ t = new FailoverTransport ([$ t1 , $ t2 ], 40 );
129
146
$ t ->send (new RawMessage ('' ));
130
147
sleep (4 );
@@ -137,15 +154,27 @@ public function testSendAllDeadWithinRetryPeriod()
137
154
138
155
public function testSendOneDeadButRecover ()
139
156
{
157
+ $ t1Matcher = $ this ->any ();
140
158
$ t1 = $ this ->createMock (TransportInterface::class);
141
- $ t1 ->method ('send ' )->willReturnOnConsecutiveCalls ($ this ->throwException (new TransportException ()));
159
+ $ t1 ->expects ($ t1Matcher )->method ('send ' )->willReturnCallback (function () use ($ t1Matcher ) {
160
+ if (1 === $ t1Matcher ->getInvocationCount ()) {
161
+ throw new TransportException ();
162
+ }
163
+
164
+ return null ;
165
+ });
166
+
142
167
$ t2 = $ this ->createMock (TransportInterface::class);
143
- $ t2 ->expects ($ this ->exactly (3 ))
144
- ->method ('send ' )->willReturnOnConsecutiveCalls (
145
- null ,
146
- null ,
147
- $ this ->throwException (new TransportException ())
148
- );
168
+ $ matcher = $ this ->exactly (3 );
169
+ $ t2 ->expects ($ matcher )
170
+ ->method ('send ' )
171
+ ->willReturnCallback (function () use ($ matcher ) {
172
+ if (3 === $ matcher ->getInvocationCount ()) {
173
+ throw new TransportException ();
174
+ }
175
+
176
+ return null ;
177
+ });
149
178
$ t = new FailoverTransport ([$ t1 , $ t2 ], 1 );
150
179
$ t ->send (new RawMessage ('' ));
151
180
sleep (1 );
0 commit comments