From bb4d7c2a4b3f3109807d2243811a5a44ce980260 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Fri, 26 Apr 2024 13:35:27 +0200 Subject: [PATCH] Remove calls to `onConsecutiveCalls()` --- Tests/Transport/FailoverTransportTest.php | 43 +++++++++++++++-------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Tests/Transport/FailoverTransportTest.php b/Tests/Transport/FailoverTransportTest.php index 2b48c20..07d4720 100644 --- a/Tests/Transport/FailoverTransportTest.php +++ b/Tests/Transport/FailoverTransportTest.php @@ -121,13 +121,17 @@ public function testSendAllDeadWithinRetryPeriod() $t1->expects($this->once())->method('send'); $t2 = $this->createMock(TransportInterface::class); $t2->method('supports')->with($message)->willReturn(true); - $t2->expects($this->exactly(3)) + + $matcher = $this->exactly(3); + $t2->expects($matcher) ->method('send') - ->willReturnOnConsecutiveCalls( - new SentMessage($message, 't2'), - new SentMessage($message, 't2'), - $this->throwException($this->createMock(TransportExceptionInterface::class)) - ); + ->willReturnCallback(function () use ($matcher, $message) { + if (3 === $matcher->getInvocationCount()) { + throw $this->createMock(TransportExceptionInterface::class); + } + + return new SentMessage($message, 't2'); + }); $t = new FailoverTransport([$t1, $t2], 40); $t->send($message); sleep(4); @@ -146,16 +150,27 @@ public function testSendOneDeadButRecover() $t1 = $this->createMock(TransportInterface::class); $t1->method('supports')->with($message)->willReturn(true); - $t1->expects($this->exactly(2))->method('send')->willReturnOnConsecutiveCalls( - $this->throwException($this->createMock(TransportExceptionInterface::class)), - new SentMessage($message, 't1') - ); + + $t1Matcher = $this->exactly(2); + $t1->expects($t1Matcher)->method('send') + ->willReturnCallback(function () use ($t1Matcher, $message) { + if (1 === $t1Matcher->getInvocationCount()) { + throw $this->createMock(TransportExceptionInterface::class); + } + + return new SentMessage($message, 't1'); + }); $t2 = $this->createMock(TransportInterface::class); $t2->method('supports')->with($message)->willReturn(true); - $t2->expects($this->exactly(2))->method('send')->willReturnOnConsecutiveCalls( - new SentMessage($message, 't2'), - $this->throwException($this->createMock(TransportExceptionInterface::class)) - ); + + $t2Matcher = $this->exactly(2); + $t2->expects($t2Matcher)->method('send')->willReturnCallback(function () use ($t2Matcher, $message) { + if (1 === $t2Matcher->getInvocationCount()) { + return new SentMessage($message, 't1'); + } + + throw $this->createMock(TransportExceptionInterface::class); + }); $t = new FailoverTransport([$t1, $t2], 1);