Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcov not showing coverage for modules #1463

Closed
dmillerSHQ opened this issue Sep 20, 2022 · 4 comments
Closed

Pcov not showing coverage for modules #1463

dmillerSHQ opened this issue Sep 20, 2022 · 4 comments
Labels

Comments

@dmillerSHQ
Copy link

I'm running the following to execute unit tests and to also generate code coverage
php -dpcov.enabled=1 \ -dpcov.directory=. \ -dpcov.exclude="~vendor~" \ ./vendor/bin/paratest -c phpunit-codefresh.xml \ --coverage-html=ci/html

my phpunit-codefresh.xml file is:
`

<testsuites>
    <testsuite name="Api Tests">
        <directory suffix="Test.php">./tests</directory>
    </testsuite>
    <testsuite name="Modules">
        <directory suffix="Test.php">./Modules/Company/Tests</directory>
    </testsuite>
</testsuites>
<filter>
    <whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
        <directory suffix=".php">./Modules/Company</directory>
        <exclude>
            <directory suffix="blade.php">./modules</directory>
            <directory suffix=".php">./Modules/Company/Annotations</directory>
            <directory suffix=".php">./Modules/Company/Database</directory>
            <directory suffix=".php">./Modules/Company/Routes</directory>
            <directory suffix=".php">./Modules/Company/Resources</directory>
            <directory suffix=".php">./Modules/Company/Tests</directory>
            <directory suffix=".php">./Modules/Company/Config</directory>
        </exclude>
    </whitelist>
</filter>
<php>
    <server name="APP_ENV" value="codefresh"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="null"/>
    <server name="DB_CONNECTION" value="isg"/>
    <server name="DB_HOST" value="mariadb"/>
    <server name="DB_DATABASE" value="app_testing"/>
    <server name="DB_USERNAME" value="app"/>
    <server name="DB_PASSWORD" value="test"/>
    <server name="DB_PORT" value="3306"/>
    <env name="TELESCOPE_ENABLED" value="false"/>
    <env name="BROADCAST_DRIVER" value="log"/>
    <ini name="memory_limit" value="8G"/>
</php>
`

The output will show 0.00% for Modules/Company when it should be more like 65.00%. There are tests there that would show up for a previous way using xdebug to generate coverage reports.

Is there something I am missing here for proper coverage to appear in the report?

@stale
Copy link

stale bot commented Oct 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 5, 2022
@stale stale bot closed this as completed Oct 13, 2022
@bradsi
Copy link

bradsi commented Dec 12, 2022

@dmillerSHQ Did you manage to solve this?

@bradsi
Copy link

bradsi commented Dec 13, 2022

For anyone who comes across this in the future. In my case, the pcov.directory value was not being set when passed on the CLI. I had to set this value directly in the php.ini file. Code coverage is now calculated correctly for Modules.

@pedestrianlove
Copy link

pedestrianlove commented Apr 10, 2024

For anyone who comes across this in the future. In my case, the pcov.directory value was not being set when passed on the CLI. I had to set this value directly in the php.ini file. Code coverage is now calculated correctly for Modules.

Can confirm this is still working.

If you want to inject the settings in GiHub Action, it would look like:

steps:
  - uses: shivammathur/setup-php@refer-to-setup-php's-version-tag
    with:
        php-version: '8.2'
        ini-values: pcov.directory=$GITHUB_WORKSPACE
        coverage: pcov

while in CircleCI(with php cimg), it would look like like:

- run:
      name: 'Patch PHP runtime config.'
      command: |
          sudo sh -c "echo 'pcov.directory = /home/circleci/project' >> /usr/local/lib/php.ini"

# run tests with phpunit
- run:
      name: 'Run Unit Tests'
      command: |
          php artisan test --parallel --processes=2 --coverage-clover tests/coverage.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants