Reputation: 227
I use phpunit's testsuites feature to organize my tests. I do so to have the ability to run tests in parallel later on.
This is relatively straight forward for different directories. So i could split up testsuites by bundle for example.
<testsuite name="bundle-one">
<directory>tests/BundleOne</directory>
</testsuite>
<testsuite name="bundle-two">
<directory>tests/BundleTwo</directory>
</testsuite>
<testsuite name="bundle-three">
<directory>tests/BundleThree</directory>
</testsuite>
But now i have one single directory (services) which contains dozens of sub-folders. I could manually make several testsuites our of this folder. But this would be a weak solution in my opinions. Because the testsuites could break easily if i mention every sub-folder in them and the folders get renamed or removed.
My idea was to use some kind of regular expression to select a range of sub-folders to include in one testsuite and another range of folders for another testsuite.
<testsuite name="services-AM">
<directory>tests/services/{A-M}</directory>
</testsuite>
<testsuite name="services-NZ">
<directory>tests/services/{A-M}</directory>
</testsuite>
I could not find any documentation on my idea. Does anybody might have an idea for this ? :-)
Upvotes: 3
Views: 1828
Reputation: 1715
An easier solution may be to filter your tests:
# Only include test classes beginning with the letter A-M
phpunit --filter '/^[A-M]/'
and
# Only include test classes beginning with the letter N-Z
phpunit --filter '/^[N-Z]/'
Assuming all your test classes start with a capital letter.
You will need to experiment to get an even split. i.e. if all your tests start with characters between A-M
then this won't work.
Tested with PHPUnit 5.4.6
Upvotes: 7
Reputation: 1210
Im not sure if there's a way to do this "on-the-fly" but you could automate the process of creating these bundles from reg-ex:
In composer.json:
"scripts": {
"make-phpunit-bundles": "php path/to/myscript.php"
},
before running tests:
php composer.phar make-phpunit-bundles
myscript.php:
//Iterate/scan your directories, build and write the phpunit.xml file
//based on the regular expressions you want
Upvotes: 1