20

so I would like to exclude a directoy from my Testsuite just like this:

<testsuite name="PHPUnitWillKillMe">   
    <directory>src/*/Bundle/*/*Bundle/Tests</directory>
    <exclude>src/*/Bundle/*/*Bundle/Tests/Controller/</exclude>
</testsuite>   

Everything except for the Controllers should be tested.

The thing is, it does not work. PHPUnit still runs all the tests in src//Bundle//*Bundle/Tests/Controller/ when I run

 phpunit --testsuite PHPUnitWillKillMe

Any idea?

Best Regards!

PHPUnit Version I tested this were 3.7.21 and 3.7.28.

Tim Joseph
  • 847
  • 2
  • 14
  • 28
  • How about this previous "solution" http://stackoverflow.com/questions/2736343/how-to-exclude-file-from-phpunit-test-suite-in-xml-config ? – achedeuzot Mar 25 '14 at 21:12
  • I don't think so, see http://phpunit.de/manual/3.7/en/appendixes.configuration.html -> Test Suites – Tim Joseph Mar 25 '14 at 21:12

2 Answers2

19

I tested it on my Symfony demo project (the Bundles suggests that this is what you are using) and I have the same issue. It seems to be a combination of two problems. First, there is a known bug with running PHPUnit (PHPUnit 3.7.19) with the -c or --config option:

https://github.com/sebastianbergmann/phpunit/issues/928

When running it elsewhere and specifying the config file using --config, the exclude would however stop working.

Second, the exclude directive seems to ignore / fail when there is any globbing (*) in the path, so by removing the globbing, it worked for me:

<testsuites>
    <testsuite name="Project Test Suite">
        <directory>../src/*/*Bundle/Tests</directory>
        <directory>../src/*/Bundle/*Bundle/Tests</directory>
        <exclude>../src/Blah/MyBundle/Tests/Controller/</exclude>
    </testsuite>
</testsuites>

It's the only way I found to exclude the Tests in MyBundle as required. The globbing did not work for the exclude. But then, it means you have to add as many exclude directives as there are folders you want to ignore.

Probable related gihub issue: https://github.com/sebastianbergmann/phpunit/pull/573

[...] this fix lands in the 4.0 release as it breaks backwards compatibility.

  • Solution #1: remove any globbing in your paths
  • Solution #2: Upgrade to PHPUnit v4.* (not tested by myself, see comments, doesn't solve the problem of exclude paths with globbing)
achedeuzot
  • 4,164
  • 4
  • 41
  • 56
  • I don't see how. I can even try the following and it will still run all tests in the directory ../src/*/Bundle/*/*Bundle/Tests ../src/*/Bundle/*/*Bundle/Tests Are you experiencing the same issue? For PHPUnit Version see the updated question – Tim Joseph Mar 25 '14 at 21:27
  • I just tested and I have the *exact* same issue. See answer for more details – achedeuzot Mar 25 '14 at 21:30
  • Thank you very much. I already found this issue on github, but maybe I am stupid or my english is bad, but what's the solution now? I have no clue... or maybe the solution is to update to 4.0.*? – Tim Joseph Mar 25 '14 at 21:43
  • I updated my answer some more, the only solution I found was to remove all globbing form the `exclude` directive... It's not a very efficient solution if you can't upgrade to version 4.0.* but I don't see any better solution for now. – achedeuzot Mar 25 '14 at 21:46
  • I removed the accepted answer tag as this is still not working with version 4.0.12 for me – Tim Joseph Mar 26 '14 at 08:29
  • Well, I've searched some more and I couldn't find anything on exclude and globbing. So the last idea I have would be to patch the PHPUnit files if you really want/need globbing. – achedeuzot Mar 26 '14 at 10:03
8

Just had similar issue, phpunit has quite nice support for groups:

...
--filter <pattern>       Filter which tests to run.
--group ...              Only runs tests from the specified group(s).
--exclude-group ...      Exclude tests from the specified group(s).
--list-groups            List available test groups.
...

What you do is

/**
 * @group nonRunnableGroupName
 */
public function testSomething()
{ /* test here */ }

And run test like

$ phpunit -c /src --exclude-group nonRunnableGroupName
lchachurski
  • 1,770
  • 16
  • 21