Skip to content

Commit d1623b7

Browse files
committed
fix: bug that can't verify method invoked when creating mock without method name
PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException: Trying to configure method "xxx" which cannot be configured because it does not exist, has not been specified, is final, or is static
1 parent 1bdd278 commit d1623b7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/TestDouble.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public function getDouble(
6767
}
6868
}
6969

70-
$mock = $mockBuilder->onlyMethods($methods)->getMock();
70+
if ($methods === []) {
71+
$mock = $mockBuilder->getMock();
72+
} else {
73+
$mock = $mockBuilder->onlyMethods($methods)->getMock();
74+
}
7175

7276
foreach ($onConsecutiveCalls as $method => $returns) {
7377
$mock->expects($this->any())->method($method)

tests/Fake/Email.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public function to(string $to): Email
1010
{
1111
return $this;
1212
}
13+
14+
public function batch_bcc_send(): void
15+
{
16+
}
1317
}

tests/TestDoubleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,12 @@ public function test_verifyNeverInvoked(): void
168168

169169
$this->verifyNeverInvoked($mock, 'method');
170170
}
171+
172+
public function test_create_mock_with_no_params_and_verifyInvokedOnce(): void
173+
{
174+
$mock = $this->getDouble(Email::class, []);
175+
$this->verifyInvokedOnce($mock, 'batch_bcc_send');
176+
177+
$mock->batch_bcc_send();
178+
}
171179
}

0 commit comments

Comments
 (0)