Allow a test to identify whether it runs in isolation #1360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A custom setup of test fixtures may use the new
PHPUnit_Framework_TestCase::isTestInIsolation()
method to determine whether to skip additional performance optimizations that only make sense if multiple tests are executed in the same process.The tests I'm currently working on need to boot up application framework objects that are very expensive to (re-)build (a full-stack Symfony Kernel/ContainerBuilder). In my case, all test methods of a single test class are always initialized in the same way, so precompiling it once and cloning it for every test method dramatically improved performance (related: symfony/symfony#11422). — However, that obviously doesn't make sense in case only one test is executed in isolation.
It is possible to identify this already, but the
$isInIsolation
property is private, so it's clunky:In light of #950, I named the new methodisTestInIsolation()
instead ofisInIsolation()
.As this is a minor addition, my hope is to get it into the next 4.1.5 stable.
Additionally necessary for #1359 (in case that solution is acceptable)