-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
feature/test-doublesTest Stubs and Mock ObjectsTest Stubs and Mock Objectstype/bugSomething is brokenSomething is broken
Description
| Q | A |
|---|---|
| PHPUnit version | 9.4.0 |
| PHP version | 8.0.0rc1 |
| Installation Method | Composer |
Summary
The static return type isn't fully supported in mocks in PHP 8.0.
Current behavior
I get the following error when running a test:
Method getInstance may not return value of type Mock_IFoo_54e9358a, its return declaration is "static"
How to reproduce
interface IFoo
{
public function getInstance(): static;
}
class FooTest extends TestCase
{
public function testFoo(): void
{
$mockFoo = $this->createMock(Foo::class);
$mockFoo->method('getInstance')
->willReturn($mockFoo);
$this->assertSame($mockFoo, $mockFoo->getInstance());
}
}Expected behavior
The above test should pass.
Additional notes
On a related note, although I cannot create a simple repro for the following error, here's a link to the broken unit test and output for a possibly-related issue with supporting static return types. When dumping the eval'd code here, I noticed that some of my tests are resulting in code like the following being generated:
class static
{
}
class Mock_static_5832468d extends static implements PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\Api;
use \PHPUnit\Framework\MockObject\Method;
use \PHPUnit\Framework\MockObject\MockedCloneMethod;
}It looks like static is being treated like the actual name of a return type rather than a special type.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature/test-doublesTest Stubs and Mock ObjectsTest Stubs and Mock Objectstype/bugSomething is brokenSomething is broken