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 results cannot be serialized if closures appear in exception traces #2713
Comments
@bartfeenstra Could you give me some example implementation? But from your presentation it seems to be the same issue described in #2739. |
I have encountered #2739 in the past, but this is a different issue. A relatively quick way to reproduce this should be to create a test case that's run in isolation, and put the following in a test method: $closure = function() {
$this->assertTrue(false);
}
$closure(); This is because |
I am not sure that I follow: <?php
class Test extends PHPUnit\Framework\TestCase
{
public function testOne()
{
$closure = function() {
$this->assertTrue(false);
};
$closure();
}
}
As you linked to this template, I assume that you use process isolation (which uses serialization for passing data between processes). However, as you can see above, I do not see an issue with regard to the serialization of the closure that invokes the assertion. |
No feedback, closing. |
Asserts are not currently allowed to be closures, because when they fail, their calls become part of the failure's backtrace. The failure is stored in the test result, which is serialized.
The specific reason we are using closure asserts, is that some of our asserts are higher-order, and take callables to perform some caller-specific asserts after the higher-order assert is done. These callables are one-off, so it makes little sense to put them in their own named (and needlessly reusable) functions.
Since some parts of the code are 8-9 years old, I assume that closures aren't unsupported here on purpose, but that this is merely a legacy limitation. Unfortunately, I'm not familiar enough with PHPUnit's internals to propose a concrete solution at this point. I'd love to hear other developers' opinions on this :)
The text was updated successfully, but these errors were encountered: