-
-
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
Test Stub generated by return value generator for doubled method with static
return type declaration is not properly initialized
#5874
Comments
Are you using the latest version of PHPUnit 11.2? |
I am sorry to say, but https://github.com/frenchcomp/test_phpunit_11_2_process is not a minimal, self-contained, reproducing test case. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
Yes :
|
Yes, you are (according to https://github.com/frenchcomp/test_phpunit_11_2_process/blob/main/composer.lock#L570). |
What is a "minimal, self-contained, reproducing test case" ? |
Something that does not depend on a third-party library such as Symfony Process. |
Typed property MockObject_Process_be57136f::$__phpunit_state must not be accessed before initialization
error when doubling Symfony\Component\Process\Process
This is the full stack trace:
|
I updated my repo with a selfcontained class and removed process. |
class IssueTest extends TestCase
{
/**
* @var Process
*/
private $process;
public function getProcessMock(): MockObject&Process
{
if (!$this->process instanceof Process) {
$this->process = $this->createMock(Process::class);
}
return $this->process;
}
public function testBug()
{
$p = $this->getProcessMock();
self::assertInstanceOf(
Process::class,
$p->setWorkingDirectory("foo"),
);
}
} Here is what I understand to be happening:
I was not able to reproduce in a minimal test case (without If this really is the case, then yes: you have a found a bug. However, I suspect that you assume in your test that class IssueTest extends TestCase
{
public function testBug()
{
$p = $this->createMock(Issue::class);
$p
->method('setWorkingDirectory')
->willReturnSelf();
self::assertInstanceOf(
Issue::class,
$p->setWorkingDirectory("foo"),
);
}
} (#5874 (comment) happened in the middle of me debugging the issue and writing this comment) |
My repo, you have an example without Process, only with PHPUnit and a sample code reproducing the error, and I have always the issue.
/home/richard/Bureau/test_phpunit_11_2_process/src/Issue.php:11 |
I got it.
With "self" as return type, i have no error, but with static i have an error |
Typed property MockObject_Process_be57136f::$__phpunit_state must not be accessed before initialization
error when doubling Symfony\Component\Process\Process
Interestingly, the return value generator has a special case for |
Thank you, @frenchcomp, for bringing this to my attention. I hope to be able to look into this more closely soon. |
You' re welcome. Thank you for you works. :) |
I got the same issue while mocking the interface https://github.com/symfony/symfony/blob/7.2/src/Symfony/Component/Validator/Violation/ConstraintViolationBuilderInterface.php#L46 and I can confirm than changing |
Note to self: the |
static
return type declaration is not properly initialized
Summary
Hi,
Since PHPUnit 11.2, I have issue when I want mock Symfony Process. I have no issue with PHPUnit 11.1 and priors versions.
Current behavior
When a mock the Symfony Process class, when I call a method on an instance of this mock, I have the error :
_Typed property MockObject_Process_XXXX::$_phpunit_state must not be accessed before initialization
I had test with define an expects() on the mock, but I had always the error.
There was 1 error:
Error: Typed property MockObject_Process_62f16cad::$__phpunit_state must not be accessed before initialization
How to reproduce
I have reproducted the issue in this repository https://github.com/frenchcomp/test_phpunit_11_2_process
You can run the test case in the src folder :
vendor/bin/phpunit src/IssueTest.php
The text was updated successfully, but these errors were encountered: