1

I have a problem with Xdebug, this is my Docker configuration:

Dockerfile:

FROM php:8.1.10-fpm-alpine
RUN apk update
RUN apk add php81-dev gcc make g++ zlib-dev icu-dev bash git openssl yaml-dev

RUN pecl channel-update pecl.php.net

# For YAML
RUN apk add --update --no-cache \
          yaml && \
      # Build dependancy for YAML \
      apk add --update --no-cache --virtual .yaml-build \
          yaml-dev && \
      pecl install yaml && \
      docker-php-ext-enable yaml; \
      apk del .yaml-build

# For Xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# For code coverage
RUN echo "memory_limit=-1" >> /usr/local/etc/php/conf.d/docker-php-memory-limit.ini

COPY --from=composer /usr/bin/composer /usr/bin/composer

SHELL ["/bin/bash", "-c"]

WORKDIR /var/www/html

docker-compose.yml:

version: '3'

services:
  php:
    build:
      context: ./
      dockerfile: Dockerfile
    volumes:
      - "./:/var/www/html"
      - "~/.composer:/root/.composer"

When I check the PHP information of my Docker image, everything seems correct:

PHP 8.1.10 (cli) (built: Sep  1 2022 21:43:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans

In PhpStorm, I setup correctly my remote PHP Interpreter with Docker Compose option.

The problem is here:

enter image description here

The displayed error:

Cannot parse PHPUnit version output: Xdebug: [Config] The setting 'xdebug.remote_enable' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_enable (See: https://xdebug.org/docs/errors#CFG-C-CHANGED) PHPUnit 9.5.25 #StandWithUkraine

Because of this error, I can't run PHPUnit in coverage mode with PhpStorm.

The error comes from this line in my Dockerfile:

RUN docker-php-ext-enable xdebug

If I remove it, my PHP configuration doesn't have Xdebug:

PHP 8.1.10 (cli) (built: Sep  1 2022 21:39:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies

With this, from PHPStorm, I can launch my unit tests without errors but, I don't have access to the coverage of my unit tests.

If I remove RUN docker-php-ext-enable xdebug from my Dockerfile, Xdebug is not activated and so I cannot with PHPStorm see the files covered by my tests.

When I try to run unit tests with coverage on PHPStorm:

enter image description here

Can you help me, please?

Mitsukk
  • 314
  • 2
  • 13

1 Answers1

3

If I remove it, Xdebug is not activated and so I cannot with PHPStorm see the files covered by my tests.

That's not right, if you want to have both coverage and the step debugger in with Xdebug 3, you need to change:

RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

To:

RUN echo "xdebug.mode=coverage,debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

And remove the xdebug.remote_enable setting from wherever you set it.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • Thanks for your answer: I don't know where I put "xdebug.remote_enable". I didn't write it in my Dockerfile. When I remove "docker-php-ext-enable xdebug" from the Dockerfile, I can run my unit tests from PHPStorm but, without Xdebug (so I cannot see the coverage). – Mitsukk Sep 26 '22 at 11:07
  • I'm still looking. I don't know when I have xdebug.remote_enable. Do you think it could be in my phpstorm config? – Mitsukk Sep 26 '22 at 15:11
  • It's possible. Check with `phpinfo()` whether there are any other `ini` files loaded as well, as each of them could have it. – Derick Sep 27 '22 at 08:00
  • You are right. I had a problem with my PHPStorm configuration. Thanks a lot! – Mitsukk Sep 30 '22 at 07:32