Skip to content

Commit 85ba4ca

Browse files
Remove calls to onConsecutiveCalls()
1 parent 93543ff commit 85ba4ca

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

Tests/Transport/FailoverTransportTest.php

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

Tests/Transport/RoundRobinTransportTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
120120
{
121121
$t1 = $this->createMock(TransportInterface::class);
122122
$t1->expects($this->exactly(3))->method('send');
123+
124+
$matcher = $this->exactly(2);
123125
$t2 = $this->createMock(TransportInterface::class);
124-
$t2->expects($this->exactly(2))
126+
$t2->expects($matcher)
125127
->method('send')
126-
->willReturnOnConsecutiveCalls($this->throwException(new TransportException()));
128+
->willReturnCallback(function () use ($matcher) {
129+
if (1 === $matcher->getInvocationCount()) {
130+
throw new TransportException();
131+
}
132+
133+
return null;
134+
});
127135
$t = new RoundRobinTransport([$t1, $t2], 3);
128136
$p = new \ReflectionProperty($t, 'cursor');
129137
$p->setAccessible(true);

0 commit comments

Comments
 (0)