Prevent doubling of __destruct() #4656
Labels
feature/test-doubles
Test Stubs and Mock Objects
type/backward-compatibility
Something will be/is intentionally broken
type/enhancement
A new idea that should be implemented
Milestone
Summary
If a test uses
$this->mock->expects( $this->never() )->method( '__destruct' );
, under certain circumstances (unsure which ones exactly), if the garbage collector kicks in and __destruct is called, the test suite will abort immediately.Current behavior
If you run the faulty test class, PHPUnit runs the test as normal, but then the following message is printed:
and PHPUnit will exit with exit code 2 without any additional output.
I'm not entirely sure about the cause of this error, as it might be PHPUnit or PHP itself (e.g. a GC bug), so I am providing a complete reproduction environment below.
How to reproduce
Here is all you need to reproduce this bug. The test case is derived from MediaWiki, where I've seen the issue happen in the wild.
composer.json
phpunit.xml.dist
src/GarbageCollectExtension.php
src/MockedClass.php
src/MockWrapper.php
tests/CrashTest.php
Once you've created all the above, run the following from the project root.
Expected behavior
The soft assertion (of __destruct never being called) should fail as it currently does [1], but then the execution should continue, and the final summary should be printed (i.e. runtime, memory, failures, assertions etc.).
[1] - Although this is not necessary for my use case.
The text was updated successfully, but these errors were encountered: