Skip to content

Commit 7b16156

Browse files
committed
get rid of getInvocationCount() calls in tests
1 parent 166c2af commit 7b16156

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

Tests/Transport/FailoverTransportTest.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,25 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
8686
{
8787
$t1 = $this->createMock(TransportInterface::class);
8888

89-
$t1Matcher = $this->any();
90-
$t1->expects($t1Matcher)
89+
$t1->expects($this->any())
9190
->method('send')
92-
->willReturnCallback(function () use ($t1Matcher) {
93-
if (1 === $t1Matcher->getInvocationCount()) {
91+
->willReturnCallback(function () {
92+
static $call = 0;
93+
94+
if (1 === ++$call) {
9495
throw new TransportException();
9596
}
9697

9798
return null;
9899
});
99100

100101
$t2 = $this->createMock(TransportInterface::class);
101-
$t2Matcher = $this->exactly(4);
102-
$t2->expects($t2Matcher)
102+
$t2->expects($this->exactly(4))
103103
->method('send')
104-
->willReturnCallback(function () use ($t2Matcher) {
105-
if (4 === $t2Matcher->getInvocationCount()) {
104+
->willReturnCallback(function () {
105+
static $call = 0;
106+
107+
if (4 === ++$call) {
106108
throw new TransportException();
107109
}
108110

@@ -132,11 +134,12 @@ public function testSendAllDeadWithinRetryPeriod()
132134
$t1->method('send')->willThrowException(new TransportException());
133135
$t1->expects($this->once())->method('send');
134136
$t2 = $this->createMock(TransportInterface::class);
135-
$matcher = $this->exactly(3);
136-
$t2->expects($matcher)
137+
$t2->expects($this->exactly(3))
137138
->method('send')
138-
->willReturnCallback(function () use ($matcher) {
139-
if (3 === $matcher->getInvocationCount()) {
139+
->willReturnCallback(function () {
140+
static $call = 0;
141+
142+
if (3 === ++$call) {
140143
throw new TransportException();
141144
}
142145

@@ -154,22 +157,24 @@ public function testSendAllDeadWithinRetryPeriod()
154157

155158
public function testSendOneDeadButRecover()
156159
{
157-
$t1Matcher = $this->any();
158160
$t1 = $this->createMock(TransportInterface::class);
159-
$t1->expects($t1Matcher)->method('send')->willReturnCallback(function () use ($t1Matcher) {
160-
if (1 === $t1Matcher->getInvocationCount()) {
161+
$t1->expects($this->any())->method('send')->willReturnCallback(function () {
162+
static $call = 0;
163+
164+
if (1 === ++$call) {
161165
throw new TransportException();
162166
}
163167

164168
return null;
165169
});
166170

167171
$t2 = $this->createMock(TransportInterface::class);
168-
$matcher = $this->exactly(3);
169-
$t2->expects($matcher)
172+
$t2->expects($this->exactly(3))
170173
->method('send')
171-
->willReturnCallback(function () use ($matcher) {
172-
if (3 === $matcher->getInvocationCount()) {
174+
->willReturnCallback(function () {
175+
static $call = 0;
176+
177+
if (3 === ++$call) {
173178
throw new TransportException();
174179
}
175180

Tests/Transport/RoundRobinTransportTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
118118
$t1 = $this->createMock(TransportInterface::class);
119119
$t1->expects($this->exactly(3))->method('send');
120120

121-
$matcher = $this->exactly(2);
122121
$t2 = $this->createMock(TransportInterface::class);
123-
$t2->expects($matcher)
122+
$t2->expects($this->exactly(2))
124123
->method('send')
125-
->willReturnCallback(function () use ($matcher) {
126-
if (1 === $matcher->getInvocationCount()) {
124+
->willReturnCallback(function () {
125+
static $call = 0;
126+
127+
if (1 === ++$call) {
127128
throw new TransportException();
128129
}
129130

0 commit comments

Comments
 (0)