-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return Value Generator fails to correctly create test stub for method with static
return type declaration when used recursively
#5593
Comments
Thank you for your report. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
<?php
require __DIR__ .'/vendor/autoload.php';
interface CacheItemInterface
{
public function expiresAfter(int|\DateInterval|null $time): static;
}
interface CacheItemPoolInterface
{
public function getItem(string $key): CacheItemInterface;
}
class MockTestCase extends \PHPUnit\Framework\TestCase
{
public function testMock(): void
{
$p = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
$i = $p->getItem('aa');
$i->expiresAfter(1);
}
}
Same issue with PHP 8.3.0 and PHPUnit 10.5.0 |
Your reproducing test case can be simplified to this: <?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
interface AnInterface
{
public function doSomething(): AnotherInterface;
}
interface AnotherInterface
{
public function doSomethingElse(): static;
}
final class Issue5593Test extends TestCase
{
public function testOne(): void
{
$a = $this->createStub(AnInterface::class);
$b = $a->doSomething();
$b->doSomethingElse();
}
}
|
static
return type declaration when used recursively
Why not add the simplified version as a test case? |
Rest assured, there will be a test case. But that one does not fit and I do not have the time right now to write the test I have in mind. |
Summary
Given this code
running
yields
Changing
static
toself
fixes it.Current behavior
See above.
How to reproduce
See above.
Expected behavior
Mocking works.
The text was updated successfully, but these errors were encountered: