PHPUnit and a single file containing multiple classes with test methods

Hi,

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:

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

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?

7 comments

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.

P.S.
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...

0
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.
0

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

0

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?

1

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.

0

Konrad, it's not possible right now, here's a usability issue: https://youtrack.jetbrains.com/issue/WI-31663

0

Kasi,

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.

0

Please sign in to leave a comment.