Search code examples
yii2phpstormcodeception

Running unit tests with Codeception in Yii2 project


Trying to setup remote Codeception Unit Tests in PhpStorm in a Yii2 project.

Using SSH I can log into the server go to the root directory of my Yii2 project and run :

> vendor/bin/codecept run unit

and the tests run.

I'm trying run these remote tests via PhpStorm, I've setup a Remote PHP CLI interpreter and I'm pointing to the Codeception library in my Yii2 project folder:

/var/www/vhosts/mydomain.com/httpdocs/yii2/vendor/bin/codecept

Test Runner points to:

/var/www/vhosts/mydomain.com/httpdocs/yii2/codeception.yml

Trying to run the tests the following command is executed:

> ssh://[email protected]:22/opt/plesk/php/5.6/bin/php /root/.phpstorm_helpers/phpunit.php --no-configuration /var/www/vhosts/mydomain.com/httpdocs/yii2/tests

The process fails at it complains that it cannot find PHPUnit:

Process finished with exit code 1
Cannot find PHPUnit in include path (.:/opt/plesk/php/5.6/share/pear)

How do I get PhpStorm to look for PHPUnit in the yii2/vendor folder? Can I just tell PhpStorm to run a different command instead of this phpstorm_helpers? It seems that the documentation is out of date and the screenshots JetBrains provides are from a different version of PhpStorm, I'm running PhpStorm 2017.3


Solution

  • So after a LOT of digging, the issue was with the Run/Debug Configuration. Despite adding Codeception to the Test Frameworks section, clicking the run button still tried to execute a pure PHPUnit test.

    To switch to run the test as Codeception, look at the top toolbar above the file tabs: Edit Run/Debug Configuration

    There you will be able to define various options:

    Configuration Dialog

    Now under run you'll have additional options:

    Run Menu

    Choose the blue Codeception icon to run the test using Codeception instead of PHPUnit