skip to Main Content

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
        - AppTestsHelperUnit
    step_decorators: ~

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

tests/unit/App/Controller/AirplaneControllerTest.php

<?php
declare(strict_types=1);
namespace AppTestsAppController;

use AppControllerAirplaneController;

class AirplaneControllerTest extends CodeceptionTestUnit
{
    /**
     * @covers AppControllerAirplaneController::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.

2

Answers


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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search