1

I can not figure out how to reliably configure the parts of my project to get code coverage displayed in PhpStorm.

I am using PhpStorm (EAP), docker (19.03.5-rc1) and docker-compose (1.24.1). I set up my project with a docker-compose.yml that includes a php service (Docker image in2code/php-dev:7.3-fpm which includes xdebug and is based on the official php:7.3-fpm image) I created a new project with composer and required codeception (3.1.2). I ran the codecption bootstrap, added the coverage settings, created a unit test and ran the while tests suite with coverage. The coverage does not appear in PhpStorm or it does show 0% everywhere. I can not figure out how to configure PhpStorm/Codeception to show the coverage. There are Projects where this works but they are configured to use a Docker image instead of a running docker-compose container.

I tried following remote PHP interpreters:

  • Remote PHP Interpreter -> Docker -> Image (in2code/php-dev:7.3-fpm)
  • Remote PHP Interpreter -> Docker -> Image built by docker-compose for this project (cct_php:latest)
  • Remote PHP Interpreter -> Docker Compose -> service php -> docker-compose exec
  • Remote PHP Interpreter -> Docker Compose -> service php -> docker-compose run

I created a PHP Test Framework for each interpreter i created above. I created a Codeception run confgiguration for each Test Framework configuration. I executed all Codeception run configurations with any combination of (Project Default) PHP CLI Interpreter and other remote interpreters.

The Testing Framework is configured with the correct path to codeception (codeception version is detected by phpstorm) and it holds the path to the codeception.yml file as default configuration file. All run configurations are using the default configuration file from the test framework configuration.

I also tried to enable coverage in the root codeception.yml file, tried work_dir: /app and remote: false.

None of these attempts generated a code coverage that was displayed in PhpStorm.

Projects where code coverage works are configured with PHP Remote Interpreter Docker Image (docker-compose built image for that project) Edit: The CLI Interpreter for the project must be the image built by docker-compose build. Setting different Command Line interpreters in the Codeception run configuration does not have any effects

docker-compose.yml

version: '3.7'

services:
  php:
    image: in2code/php-dev:7.3-fpm
    volumes:
      - ./:/app/
      - $HOME/.composer/auth.json:/tmp/composer/auth.json
      - $HOME/.composer/cache/:/tmp/composer/cache/

tests/unit.suite.yml

actor: UnitTester
modules:
    enabled:
        - Asserts
        - \App\Tests\Helper\Unit
    step_decorators: ~

coverage:
    enable: true
    remote: true
    include:
        - src/*

tests/unit/App/Controller/AirplaneControllerTest.php

<?php
declare(strict_types=1);
namespace App\Tests\App\Controller;

use App\Controller\AirplaneController;

class AirplaneControllerTest extends \Codeception\Test\Unit
{
    /**
     * @covers \App\Controller\AirplaneController::start
     */
    public function testSomeFeature()
    {
        $airplaneController = new AirplaneController();
        $airplaneController->start();
    }
}

Did i miss something in my configuration? The best solution would be a valid configuration using docker-compose exec for the remote interpreter, so other services like mysql or ldap are available for functional tests.

1

2 Answers 2

2

Unfortunately, it's hopelessly broken at the moment: https://youtrack.jetbrains.com/issue/WI-32625

1

I've noticed that PHPStorm calls codeception with this option

--coverage-xml /opt/phpstorm-coverage/admin_service$unit_tests.xml

but when testing is done I get this message

XML report generated in /opt/phpstorm-coverage/admin_service$$unit_tests.xml

Notice the filename is different. So I've created a link using this command

ln admin_service\$\$unit_tests.xml admin_service\$unit_tests.xml

and restarted the test coverage. The coverage window showed up.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.