nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.51k stars 956 forks source link

Pcov not showing coverage for modules #1463

Closed dmillerSHQ closed 2 years ago

dmillerSHQ commented 2 years ago

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: `<?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">

<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[bot] commented 2 years ago

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.

bradsi commented 1 year ago

@dmillerSHQ Did you manage to solve this?

bradsi commented 1 year ago

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 commented 6 months ago

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