@@ -85,16 +85,30 @@ public function testSendOneDead()
8585 public function testSendOneDeadAndRecoveryWithinRetryPeriod ()
8686 {
8787 $ 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+
89100 $ t2 = $ this ->createMock (TransportInterface::class);
90- $ t2 ->expects ($ this ->exactly (4 ))
101+ $ t2Matcher = $ this ->exactly (4 );
102+ $ t2 ->expects ($ t2Matcher )
91103 ->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+
98112 $ t = new FailoverTransport ([$ t1 , $ t2 ], 6 );
99113 $ t ->send (new RawMessage ('' )); // t1>fail - t2>sent
100114 $ this ->assertTransports ($ t , 0 , [$ t1 ]);
@@ -115,16 +129,19 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
115129 public function testSendAllDeadWithinRetryPeriod ()
116130 {
117131 $ t1 = $ this ->createMock (TransportInterface::class);
118- $ t1 ->method ('send ' )->will ( $ this -> throwException ( new TransportException () ));
132+ $ t1 ->method ('send ' )->willThrowException ( new TransportException ());
119133 $ t1 ->expects ($ this ->once ())->method ('send ' );
120134 $ t2 = $ this ->createMock (TransportInterface::class);
121- $ t2 ->expects ($ this ->exactly (3 ))
135+ $ matcher = $ this ->exactly (3 );
136+ $ t2 ->expects ($ matcher )
122137 ->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+ });
128145 $ t = new FailoverTransport ([$ t1 , $ t2 ], 40 );
129146 $ t ->send (new RawMessage ('' ));
130147 sleep (4 );
@@ -137,15 +154,27 @@ public function testSendAllDeadWithinRetryPeriod()
137154
138155 public function testSendOneDeadButRecover ()
139156 {
157+ $ t1Matcher = $ this ->any ();
140158 $ 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+
142167 $ 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+ });
149178 $ t = new FailoverTransport ([$ t1 , $ t2 ], 1 );
150179 $ t ->send (new RawMessage ('' ));
151180 sleep (1 );
0 commit comments