collision icon indicating copy to clipboard operation
collision copied to clipboard

TestCommand > Passing on ini settings to phpunit/paratest

Open JeroenVanOort opened this issue 1 year ago • 1 comments

We use PCOV to collect code coverage. However, we only enable PCOV when we are running tests(using -d pcov.enabled=1), so that it doesn't slow down any other running of the code. This has worked fine with collision 6 / phpunit 9, but it doesn't work any more for collision 7 / phpunit 10. This seems to have to do with the -d argument not being passed on to the phpunit/paratest command.

This works fine:

php -d pcov.enabled=1 vendor/bin/phpunit --coverage-text

but

php -d pcov.enabled=1 artisan test --coverage

starts it's output with

WARN No code coverage driver available.

Apparently, this check passed and it is PHPUnit itself that is giving the warning.

When I change return array_merge([PHP_BINARY], $command); to return array_merge([PHP_BINARY, '-d pcov.enabled=1'], $command); (https://github.com/nunomaduro/collision/blob/v7.x/src/Adapters/Laravel/Commands/TestCommand.php#L179), coverage works just fine.

The challenge here seems to be to find an elegant way to set options like this. I think this would be the easiest way:

php -d pcov.enabled=1 artisan test --coverage -d pcov.enabled=1

All -d arguments would be passed directly to PHP.

What are your thoughts on this? I'd be willing to make a PR.

JeroenVanOort avatar Sep 08 '23 08:09 JeroenVanOort

Btw, you can workaround this without a fork by using an environment variable:

// docker-php-ext-pcov.ini

pcov.enabled=${PCOV_ENABLED}

and then

PCOV_ENABLED=true php artisan test -p --coverage-text
PCOV_ENABLED=false php artisan test -p --coverage-text
php artisan test -p --coverage-text

all work as expected.

It's not to say that this issue is irrelevant; I still believe it should be fixed so we don't have to do workarounds :)

oprypkhantc avatar Nov 22 '23 13:11 oprypkhantc