-
-
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
Infinite recursion with test doubles in combination with a destructor #5809
Comments
Thank you, @nielsdos, for investigating this. I have stripped down the reproducer:
|
Here is what happens in #5809 (comment):
There is no bug here, though. The return type declaration If you configure
|
Thanks for the great explanation! |
I am seeing this issue when running unit tests in Laravel, with my test classes extending Is it likely that the base Laravel class incorrectly handles self-references and destructors similar to #5809 (comment), and that is the cause of the segfaults I am seeing? Laravel has a ton of methods that return |
@matthewjumpsoffbuildings Please raise this question with the vendor of your framework. |
Summary
This is related to a php-src bug report: php/php-src#12373
After debugging, I found that this is not a PHP bug, but a PHPUnit bug. The segfault happens because of infinite recursion.
The reproducer (linked below) has a method
methodWithSelfReferenceReturn
with a return type ofself
. This method is called from the destructor.The class is also mocked in the test case, the mock codegen for that method contains a snippet like this:
Stepping through this the following happens:
InvocationHandler.php::invoke
which calls$invocation->generateReturnValue()
generateReturnValue()
calls(new ReturnValueGenerator)->generate(...)
$this->testDoubleFor($returnType, $className, $methodName);
because the return type is neither an intersection nor a union.$object = $this->getObject(...)
creates an object of typeTestStub_ExampleOne_019e0114
.methodWithSelfReferenceReturn
. This creates an infinite recursion, eventually crashing the PHP interpreter.If you print out a backtrace using
debug_backtrace()
from PHP, you'll see over time the number of these entries grow:"ExampleOne.php","line":14
, hinting about the infinite recursion.Current behavior
Crash due to infinite recursion.
How to reproduce
composer install
php ./vendor/bin/phpunit
Expected behavior
No crash.
The text was updated successfully, but these errors were encountered: