I have this in my phpunit.xml file:
<phpunit ...>
<testsuites>
<testsuite name="MyTests">
<directory>../path/to/some/tests</directory>
</testsuite>
</testsuites>
... // more settings for <filter> and <logging>
</phpunit>
And when I go to run it, I get this error:
PHP fatal error: Uncaught exception 'PHPUnit_Framework_Exception'
with message 'Neither "MyTests.php" nor "MyTests.php" could be opened.'
Why does PHPUnit give me this error, and why is it looking for “MyTests.php” if I gave it a directory in which to look for tests?
And on a related note, when I add more <testsuite> entries with other tests, PHPUnit runs without error. What’s up with that?
By default PHPUnit will add “all
*Testclasses that are found in*Test.phpfiles” (see PHPUnit docs). If it doesn’t find any files matching that description, (e.g. aSomeTest.phpfile defining aSomeTestclass), it falls back to looking for a file based on the name attribute of the test suite.The solution is to create a file matching that description so that PHPUnit doesn’t fall back to its default of searching by the testsuite name:
Now you should be able to run
phpunitwithout errors:It will work without errors when you add more
testsuiteentries if PHPUnit is able to find matching test cases to run under those other suites. If it finds tests to run in any testsuite, it won’t resort to searching by thenameattribute for the suites it couldn’t find anything for.