How to generate tests in the tests / phpStorm directory?

PhpStorm has some weird behavior that drives me crazy. I have setup my project with source and test . The source directory must be for productive code, and the test directory must contain all phpunit tests.

In these directories, the folder structure is mirrored - if I have the class \foo\Bar , that is, src/foo/Bar.php and test/foo/BarTest.php .

I marked src/ and test/ as the source and test directory in PhpStorm, however every time I want to create a new test package for a class, by default PhpStorm places the test class in src/ directory next to the tested class.

You can change this, however it becomes more annoying when the same directory in test/ does not exist yet. Instead of creating it, PhpStorm will simply refuse to create this test suite for me.

Perhaps I misunderstand the concept of test management in PhpStorm - because it just can't be a bad user experience.

Is there something that I am doing wrong, or something that I can adjust to make the situation less painful?

+6
source share
2 answers

You are doing nothing wrong. It just doesnโ€™t work that way - the developers encoded it to behave the way it is now.

Initially, the IDE used the ability of PHPUnit to generate test classes (then this functionality was part of the real PHPUnit). Then the creators of PHPUnit transferred this functionality to a separate package ( phpunit-skelgen ) .., and you had to install it manually / separately. Then the developers decided to completely abandon the support of phpunit-skelgen and implemented the current implementation (which also looks more like similar procedures in other IDEs built on the IDEA platform / technologies supported by these IDEs).

There are quite a few tickets for changing this behavior to the point that you described / wished .. but so far this does not look like his list of priorities ...

Sign up for these tickets (star / voice / comment) to receive notification of progress.

+2
source

Starting with version 2016.3, PHPStorm now conducts tests in the specified test directory, providing exactly what you ask in your question.

+2
source

All Articles