This is an example to show how to run PHPUnit using phpctl.
It is also a short tutorial on how to configure PhpStorm to run PHPUnit tests using the phpctl image.
First we need to setup a Remote Interpreter to use opencodeco/phpctl.
At the Settings, go to Languages & Frameworks and select PHP.
Click on the 3 dots menus (...) on the right side of the window, at the CLI Interpreter option.
Then click on the plus sign (+) button and choose From Docker, Vagrant....
Now choose the Docker option, select your corresponding Docker server, the opencodeco/phpctl image and at the PHP interpreter path just type php.
Click OK to get the configured interpreter.
Then just hit OK again. We are done.
At the Settings, go to Languages & Frameworks, open the PHP toggle and select Test Frameworks.
Click on the plus sign button (+) and chosse PHPUnit by Remote Interpreter.
Select the remote interpreter we just created.
And click OK.
Then click OK again.
Inside a project, go to Settings, then Languages & Frameworks, open the PHP toggle and select Test Frameworks again.
At the PHPUnit library we just need to configure the Path to script option.
You should point it to your vendor/autoload.php, but keep in main that the path starts at /opt/project directory, that is the container's directory, not you host directory.
In this case, the phpctl project root is at /opt/project then to point to the vendor/autoload.php from this example, we need to add the examples/phpunit directory.
Note
Your configuration will probably be something simpler like /opt/project/vendor/autoload.php.
Click Apply and OK.
Now click on the top level menu Run.
And select Edit Configurations...
Click on the plus sign button (+) or Add new...
And choose the PHPUnit configuration.
Give it a good name, I'm calling this one as PHPUnit Example then:
- At the Test Runner section, choose the Defined in the configuration file option.
- Then enable the Use alternative configuration file option and point it to your
phpunit.xmlfile. - At the Command Line section, in the Interpreter option, select the previus created interpreter
opencodeco/phpctl:php82.
Click Apply and OK.
Now you can run the PHPUnit configuration we just created.
And everything should ok fine.
The command PhpStorm should be using will be something similar to:
[docker://opencodeco/phpctl:php84/]:php /opt/project/examples/phpunit/vendor/phpunit/phpunit/phpunit --configuration /opt/project/examples/phpunit/phpunit.xml --teamcity
Feel free to open any issues if any of these steps didn't worked well for you.