I'm trying to configure PhpStorm 2017.2 to use PhpUnit 5 for my PHP 5.6 project.
I've downloaded the
phpunit-5.7.21.pharfile from the official source and placed it in my PHP 5.6 installation dir.In PhpStorm Settings >> Languages & Frameworks >> PHP >> Test Frameworks, I've linked to the
.pharexecutable and set the default config file to aphpunit.xmlin the project root directory
- Here are the contents of
phpunit.xml:
.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<testsuites>
<testsuite name="Test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
I'm trying to structure tests in a tests/unit directory within which my source file project structure would be mirrored as described in the manual. For instance:
// project files:
ClassOne.php
vendor/
ClassTwo.php
Utility.php
// test files
tests/unit/
ClassOneTest.php
vendor/
ClassTwoTest.php
UtilityTest.php
I have two problems though:
First, I don't know how to configure PhpStorm to create tests within tests/unit/ mirroring the sructure with respect to the project root. When I create a test, by default the file is put in the same directory as the project file.
Secondly, I don't know how to get PhpStorm to index the PHPUnit source code. Even though I've linked to phpunit-5.7.21.phar file as shown above, the IDE complains when I create a test:
namespace vendor;
class UtilityTest extends \PHPUnit_Framework_TestCase{}
Undefined class PHPUnit_Framework_TestCase
Update 1
I solved the 2nd problem by adding the directory where I had saved the .phar to the PhpStorm include path, set in Settings >> Languages & Frameworks >> PHP >> Include Path tab. Alternatively, I could just put the .phar file within the project directory and it will be indexed.
I still need help with my first problem.
Update 2
Thanks to Ástþór's answer I figured out how to get PhpStorm to mirror the project structure within a dedicated tests directory. Go to PhpStorm Settings >> Directories and select the base testing directory. The click Test near the top to mark it as a Test Sources Root
The next time you create a test, it will automatically be placed in that directory.

