Skip to content

Latest commit

 

History

History
114 lines (61 loc) · 5.53 KB

File metadata and controls

114 lines (61 loc) · 5.53 KB

PHPUnit

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.

PhpStorm

CLI Interpreter

First we need to setup a Remote Interpreter to use opencodeco/phpctl.

At the Settings, go to Languages & Frameworks and select PHP.

Screenshot 2024-01-26 at 11 41 28

Click on the 3 dots menus (...) on the right side of the window, at the CLI Interpreter option.

Screenshot 2024-01-26 at 11 46 21

Then click on the plus sign (+) button and choose From Docker, Vagrant....

Screenshot 2024-01-26 at 11 44 26

Now choose the Docker option, select your corresponding Docker server, the opencodeco/phpctl image and at the PHP interpreter path just type php.

Screenshot 2024-01-26 at 11 47 07

Click OK to get the configured interpreter.

Screenshot 2024-01-26 at 11 49 53

Then just hit OK again. We are done.

Test Frameworks

At the Settings, go to Languages & Frameworks, open the PHP toggle and select Test Frameworks.

Screenshot 2024-01-26 at 11 52 04

Click on the plus sign button (+) and chosse PHPUnit by Remote Interpreter.

Screenshot 2024-01-26 at 11 52 15

Select the remote interpreter we just created.

Screenshot 2024-01-26 at 11 52 31

And click OK.

Screenshot 2024-01-26 at 11 57 04

Then click OK again.

Inside a project, go to Settings, then Languages & Frameworks, open the PHP toggle and select Test Frameworks again.

Screenshot 2024-01-26 at 11 57 49

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.

Screenshot 2024-01-26 at 11 59 13

Note

Your configuration will probably be something simpler like /opt/project/vendor/autoload.php.

Click Apply and OK.

Run Configurations

Now click on the top level menu Run.

Screenshot 2024-01-26 at 12 06 07

And select Edit Configurations...

Screenshot 2024-01-26 at 12 06 18

Click on the plus sign button (+) or Add new...

Screenshot 2024-01-26 at 12 08 01

And choose the PHPUnit configuration.

Screenshot 2024-01-26 at 12 09 12

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.xml file.
  • At the Command Line section, in the Interpreter option, select the previus created interpreter opencodeco/phpctl:php82.
Screenshot 2024-01-26 at 12 12 10

Click Apply and OK.

Now you can run the PHPUnit configuration we just created.

Screenshot 2024-01-26 at 12 16 47

And everything should ok fine.

Screenshot 2024-01-26 at 12 17 37

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.