I try to use pcov
to generate code coverage reports in my Docker container.
This is my container’s dockerfile:
FROM php:8.1-fpm-alpine
WORKDIR /var/www/html
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
ENV PHP_MEMORY_LIMIT=1G
ENV PHP_UPLOAD_MAX_FILESIZE: 512M
ENV PHP_POST_MAX_SIZE: 512M
RUN docker-php-ext-install pdo
RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev
RUN apk update
&& apk upgrade
&& apk add --no-cache
freetype
libpng
libjpeg-turbo
freetype-dev
libpng-dev
jpeg-dev
libwebp-dev
libjpeg
libjpeg-turbo-dev
RUN docker-php-ext-configure gd
--with-freetype=/usr/lib/
--with-jpeg=/usr/lib/
--with-webp=/usr
RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1)
&& docker-php-ext-install -j${NUMPROC} gd
RUN apk add --no-cache sqlite-libs
RUN apk add --no-cache icu sqlite git openssh zip
RUN apk add --no-cache --virtual .build-deps icu-dev libxml2-dev sqlite-dev curl-dev
RUN docker-php-ext-install
bcmath
curl
ctype
intl
pdo
pdo_sqlite
xml
RUN apk del .build-deps
RUN docker-php-ext-enable pdo_sqlite
RUN echo memory_limit = -1 >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
RUN echo culr.cainfo="/etc/cacert.pem" >> /usr/local/etc/php/conf.d/docker-php-curl-ca-cert.ini
# install composer
RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
RUN HASH=`curl -sS https://composer.github.io/installer.sig`
RUN php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# install pcov
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS
RUN apk add --update linux-headers
RUN pecl install pcov
RUN docker-php-ext-enable pcov
RUN apk del -f .build-deps
And this is the command to run phpunit:
docker-compose run --rm phpunit ./vendor/phpunit/phpunit/phpunit
--configuration phpunit.xml --coverage-html=reports/
The reports/
folder is created, but it’s empty.
I tried with --coverage-clover=coverage.xml
options too, but this file also not created.
The runs output is this:
PHPUnit 9.5.16 by Sebastian Bergmann and contributors.
............................................................... 63 / 144 ( 43%)
............................................................... 126 / 144 ( 87%)
.................. 144 / 144 (100%)
Time: 02:09.917, Memory: 227.00 MB
OK (144 tests, 1972 assertions)
Generating code coverage report in HTML format ...
And last line if I use clover format:
Generating code coverage report in Clover XML format ...
What I miss here?