Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to run codecoverage with PhpStorm

Tags:

php

phpstorm

I am trying to run unit test in PhpStorm with codecoverage. It throws me a error msg saying interpreter is missing. How to install the interpreter!

Also how to configure in order to run my tests with code coverage.

Edit Configuration

like image 505
user2995833 Avatar asked Mar 15 '26 00:03

user2995833


1 Answers

Steps to do:

1. Set interpreter and language level.

File -> Settings -> Languages & Frameworks -> PHP

Select your PHP version. Then click button with ... (three dotes), then add interpreter.

https://www.jetbrains.com/phpstorm/help/interpreters.html

2. Add PHPUnit to project.

File -> Settings -> Languages & Frameworks -> PHPUnit

a) Load form include path

To add this you must set where PHPUnit library is installed. Then add using External Libraries in Project.

adding include paths

To specify path use green + button.

b) Use custom autoloader

Use this option when you install PHPUnit via composer. In Path to script field specify autoload file.

https://www.jetbrains.com/phpstorm/help/phpunit.html

3. Configure tests

In the top right corner use Select Run/Debug Configuration menu

run debug configration

And click Edit Configurations. Select green + button to add PHPUnit.

add phpunit

Define name of the configuration and directory with tests. Additionally you can add some PHPUnit arguments in Test Runner options field.

https://www.jetbrains.com/phpstorm/help/run-debug-configuration-phpunit.html

Annotation 1 - Configure bootstrap

Tests sometimes needs to use a bootstrap file which set environments, loads configs etc. To set this file go to:

File -> Settings -> Languages & Frameworks -> PHPUnit

and select the bootstrap file in Default bootstrap file field.

bootstrap file

https://www.jetbrains.com/phpstorm/help/phpunit.html - in Bootstrap file section.

Annotation 2 - Run tests with code coverage

To run with coverage you must install Xdebug PHP extension. You should read the Xdebug installation guide.

After this actions use a icon

coverage

to run with coverage.

https://www.jetbrains.com/phpstorm/help/code-coverage.html

like image 112
Piotr Olaszewski Avatar answered Mar 16 '26 14:03

Piotr Olaszewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!