Codeception: Spread the word about fast code coverage via "pcov" extension

Created on 31 May 2019  路  9Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Let users know that Codeception 3 brings not only PHPUnit 8.x support, but also blazing-fast code coverage via krakjoe/pcov thanks to this bad boy https://github.com/sebastianbergmann/php-code-coverage/pull/663

What do you get instead?

pcov is not mentioned anywhere :disappointed:

Details

The setup is so simple, even your grandma can do it:

  • install pcov extension following these instructions
  • change defaults in your php.ini

    • disable xdebug by commenting out the line zend_extension=xdebug.so

    • enable pcov by adding extension=pcov.so and pcov.enabled = 1

Now, if you want code coverage, run vendor/bin/codecept --coverage-html
And if you need to debug some stuff, run php -d zend_extension=xdebug.so vendor/bin/codecept

This will help #1446, #4524, and also make lots of people really happy!

The running time of my tests with enabled code coverage went from 11 minutes down to 20 seconds.

Docs

Most helpful comment

I'm currently using this dockerfile:

FROM codeception/codeception:3.1.0

RUN pecl install \
        pcov && \
    docker-php-ext-enable \
        pcov && \
    rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
    echo "pcov.directory = /project" >> /usr/local/etc/php/php.ini

This makes a big unit test suite running time go from 131 seconds to 13 seconds!

All 9 comments

What are the advantages of pcov over phpdbg?

No overhead related to debugger functionality makes pcov faster than phpdbg.
It is also more precise because it properly handles implicit return statements (just like xdebug does, which is accurate but slow), see https://blog.krakjoe.ninja/2019/01/running-for-coverage.html

One small step which could be done is mentioning pcov in https://github.com/Codeception/Codeception/blob/3.0/docs/11-Codecoverage.md#remote-codecoverage
which currently says that To collect coverage information xdebug is required.

What are the advantages of pcov over phpdbg?

Given how old this thread is you probably either already are using PCov or have decided not to use it, but the main advantage over PHPDbg in my experiences is not the speed (it is faster) but memory usage. PCov uses less memory than Xdebug or PHPDbg, the latter by a significant margin, and also happens to be faster than both (the former by a significant margin)

I've just tested this with the .phar based setup. It didn't work for me. I guess it's the included phpunit which is still version 6.5.14. So it either phpunit in the phar should be updated or it should be mentioned that pcov doesn't work with the phar setup.

I've just tested this with the .phar based setup. It didn't work for me. I guess it's the included phpunit which is still version 6.5.14. So it either phpunit in the phar should be updated or it should be mentioned that pcov doesn't work with the phar setup.

I'm not familiar with the .phar install, do you mean the install for php 5.6 or the current .phar release for 7.x? I agree a note should/could be added able PCOV not working with PHP 5.6, it requires PHPUnit 8.0+ which doesn't support < 7.2.

I refer to the 7.x release (the one you get with wget https://codeception.com/codecept.phar or curl -LsS https://codeception.com/codecept.phar -o /usr/local/bin/codecept). I wonder why it doesn't include a newer version of phpunit and opened an issue for it here: #5676

On a sidenote: If you install with curl -LsS https://codeception.com/codecept.phar -o /usr/local/bin/codecept you will get version 3.0.3. If you then run codecept self-update, it will upgrade to 3.1.0 (which again includes an old version of phpunit). Made me wonder why it didn't download 3.1.0 directly.

Huh, that's odd but understandable I suppose. The .phar install can't exactly upgrade it's dependencies so using the most compatible version of PHPUnit is probably the safe route.

I'm currently using this dockerfile:

FROM codeception/codeception:3.1.0

RUN pecl install \
        pcov && \
    docker-php-ext-enable \
        pcov && \
    rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
    echo "pcov.directory = /project" >> /usr/local/etc/php/php.ini

This makes a big unit test suite running time go from 131 seconds to 13 seconds!

Was this page helpful?
0 / 5 - 0 ratings