php-actions / phpunit

Run PHPUnit tests in Github Actions.
108 stars 24 forks source link

Code coverage #25

Closed g105b closed 3 years ago

g105b commented 3 years ago

When running with code coverage, as on this repository, a warning is raised:

Warning: XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set

This is despite having the xdebug extension enabled, and doesn't seem to be affected by passing -d XDEBUG_MODE=coverage.

Tracking this issue here to fix once the other php-actions are running happily alongside each other.

Gared commented 3 years ago

One suggestion: Just add xdebug.mode=coverage to the php.ini. Regardless it is needed or not, but this should not have any impact if xdebug is not installed

g105b commented 3 years ago

I think that might be a decent solution, @Gared , but I thought -d should work as this is used. Maybe adding to the ini on the action runner will be simple enough to resolve this.

estahn commented 3 years ago

@g105b I'm running into the same issue. How did you add -d?

lamalex commented 3 years ago

I tried putting -d xdebug.mode=coverage into args but I'm getting the same message to set xdebug.mode or XDEBUG_MODE.

g105b commented 3 years ago

Hi @lamalex , @estahn and @Gared ,

I have a solution and have documented it. This has been bugging me for a while, but despite what the phpunit documentation says, I couldn't get the -d flag to work at all.

The solution is to pass the environment variable XDEBUG_MODE to the Github Action.

With this configuration (live example):

name: CI-coverage

on: [push]

jobs:
  build-test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: php-actions/composer@v5

      - name: PHPUnit Tests
        uses: php-actions/phpunit@v2
        with:
          php_extensions: xdebug
          bootstrap: vendor/autoload.php
          configuration: test/phpunit.xml
          args: --coverage-text
        env:
          XDEBUG_MODE: coverage

I can see this test run output (live example):

image

I hope this answers everything. If you have any other questions please feel free to re-open the issue - always happy to help out, but sorry it's taken me a while to give you a response.

Cheers, Greg.