Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit TestSuite Exclude

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.

like image 574
Tim Joseph Avatar asked Mar 25 '14 20:03

Tim Joseph


People also ask

How do I create a test suite in PHPUnit?

Probably the easiest way to compose a test suite is to keep all test case source files in a test directory. PHPUnit can automatically discover and run the tests by recursively traversing the test directory. Lets take a look at the test suite of the sebastianbergmann/money library.

What are the goals of PHPUnit?

One of the goals of PHPUnit is that tests should be composable: we want to be able to run any number or combination of tests together, for instance all tests for the whole project, or the tests for all classes of a component that is part of the project, or just the tests for a single class.

What are PHPUnit test helper classes in WordPress?

WordPress PHPUnit test helper classes allow us to create post, user, page, or anything in our test site to perform actual tests. Suppose, Our plugin allow user to add a meta field only for the author user role. We can programmatically create the user with author user role and perform our tests.

Can PHPUnit backup global variables before and after testing?

The XML Configuration File Possible values: true or false (default: false) PHPUnit can optionally backup all global and super-global variables before each test and restore this backup after each test.


1 Answers

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)
like image 154
achedeuzot Avatar answered Oct 11 '22 12:10

achedeuzot