Skip to content

Include modules in code coverage

At the end, your application’s coverage report includes Modules/Blog/app. Prerequisites: phpunit.xml in the application root, modules_statuses.json, and a coverage driver (Xdebug or PCOV).

  1. Update phpunit.xml.

    Terminal window
    php artisan module:update-phpunit-coverage

    The command reads the statuses file configured in modules.activators.file.statuses-file (default modules_statuses.json). It adds each enabled module’s app folder to <source><include> and removes disabled or deleted modules.

    phpunit.xml
    <source>
    <include>
    <directory>app</directory>
    <directory suffix=".php">./Modules/Blog/app/</directory>
    </include>
    </source>

    See module:update-phpunit-coverage for supported <source> XML layouts and exit codes.

  2. Run the tests with coverage.

    Terminal window
    php artisan test --coverage

    With Xdebug, enable coverage mode for the run:

    Terminal window
    XDEBUG_MODE=coverage php artisan test --coverage

Re-run php artisan module:update-phpunit-coverage whenever you add, remove, enable, or disable a module. Make sure your module tests are part of a PHPUnit test suite; see Run the tests of a module.

Open phpunit.xml and confirm ./Modules/Blog/app/ appears under <source><include>. The coverage output lists files under Modules/Blog/app.

If the command exits with a non-zero status, check the exit code reference in module:update-phpunit-coverage.