Skip to content
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

Allow a test to identify whether it runs in isolation #1360

Merged
merged 1 commit into from
Jul 27, 2014

Conversation

sun
Copy link
Contributor

@sun sun commented Jul 27, 2014

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:

  protected function isTestInIsolation() {
    return function_exists('__phpunit_run_isolated_test');
  }

In light of #950, I named the new method isTestInIsolation() instead of isInIsolation().

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)

A custom setup of test fixtures may use this indicator to skip additional performance optimizations that only make sense if multiple tests are executed in the same process.
@whatthejeff
Copy link
Contributor

@sun This will go into 4.3 (which is still available for download, just not considered stable for a few more months).

whatthejeff added a commit that referenced this pull request Jul 27, 2014
Allow a test to identify whether it runs in isolation
@whatthejeff whatthejeff merged commit 2608a34 into sebastianbergmann:master Jul 27, 2014
@whatthejeff
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants