PHPUnit and a single file containing multiple classes with test methods


I have a single php file contaning multiple classes each with their own respective test methods. In my phpunit.xml config, I have defined the following section:

        <testsuite name="Specs">
            <directory suffix="Specs.php">specs</directory>

When running phpunit from the command line, it detects each of the classes and executes their test methods. I have configured PHPStorm to use the same phpunit.xml config file however when I right click on the root directory of the project and click Run specs it reports that no tests have been run.

Does PHPStorm use the directory element of phpunit.xml config to identify directories containing tests?

Comment actions Permalink

Hi Kasi,

Please show your Run/Debug Configuration for this (Run | Edit Configurations...) and what do you see in console when tests get executed by PhpStorm.

Generally speaking it's not a great idea to have multiple test cases in single file -- having one case per file helps avoiding many problems...

Comment actions Permalink
Andriy Bazanov sometimes there is strong need for having multiple test classes for single class. Example would be a command class with multiple side effects.
Comment actions Permalink

Konrad, could you please provide us with the data Andriy has requested?

Comment actions Permalink

Eugene, it was not me who asked the question and I realized my situation is quite different :)


In case you want to know the details: I have multiple test classes for my model class. But PHPStorm is not detecting them (via Ctrl+Shift+T) if test class name is not following a pattern {$className}Test. Is there any way to inform PhpStorm of all test classes for given model class, so they can be shown in Ctrl+Shift+T?

Comment actions Permalink

Hi Eugene,


As it's been quite a while since I posted this question and I was unable to find a solution I've abandoned the approach and just postfixed the word Test at the end of each of my class names in order to get them to run but as I explained in my previous post, I want to be able to use an alternate naming convention for classes which contain phpunit tests. I created a phpunit.xml accordingly and am able to get phpunit to detect and execute my tests correctly from the command line. In PHPStorm, I created a run/debug configuration explicitly utilizing the phpunit.xml configuration file but when I try to run tests via the PHPStorm phpunit test runner, no tests are detected.

I was expecting the PHPStorm phpunit test runner to honor these settings, detect and execute the tests using the naming convention defined in the configuration file and produce a result equivalent to the command line runner. It seems like this might be a bug.

In addition, it would be great if when executing a test in response to a users context based execution (for instance, right clicking on a file or directory and then clicking Run Test(s)), PHPStorm could check if there is a phpunit.xml file available in the project and use its settings by default. This would really help to eliminate the need to define explicit Run/Debug settings for each execution context making it easier to run a single test or group of tests on the fly.

Comment actions Permalink

Konrad, it's not possible right now, here's a usability issue:

Comment actions Permalink


I've tried to reproduce issue and did not succeed. Here's what I have:

1. A phpunit.xml file similar to yours, a test file with multiple test classes:

2. A Run Configuration that uses the phpunit.xml file:

As you can see on the first screenshot, the tests are run just as they could be run from Terminal.


Please sign in to leave a comment.