Skip to content

Commit bb4d7c2

Browse files
Remove calls to onConsecutiveCalls()
1 parent b15630d commit bb4d7c2

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

Tests/Transport/FailoverTransportTest.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,17 @@ public function testSendAllDeadWithinRetryPeriod()
121121
$t1->expects($this->once())->method('send');
122122
$t2 = $this->createMock(TransportInterface::class);
123123
$t2->method('supports')->with($message)->willReturn(true);
124-
$t2->expects($this->exactly(3))
124+
125+
$matcher = $this->exactly(3);
126+
$t2->expects($matcher)
125127
->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+
});
131135
$t = new FailoverTransport([$t1, $t2], 40);
132136
$t->send($message);
133137
sleep(4);
@@ -146,16 +150,27 @@ public function testSendOneDeadButRecover()
146150

147151
$t1 = $this->createMock(TransportInterface::class);
148152
$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+
});
153163
$t2 = $this->createMock(TransportInterface::class);
154164
$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+
});
159174

160175
$t = new FailoverTransport([$t1, $t2], 1);
161176

0 commit comments

Comments
 (0)