Adding Code Coverage

install in ubuntu

sudo apt-get install php-xdebug

trouble

No code coverage driver is available
-> dont forget to install php-xdebug

Install in intel mac

pecl install xdebug

Install in mac M1

file `which php` #mine is Mach-O 64-bit executable arm64
arch -arm64 pecl install xdebug
#cd /opt/homebrew/etc/php/8.1/conf.d/
#echo "xdebug.mode=debug" > xdebug.ini

To run it

vendor/bin/phpunit

XDEBUG_MODE=coverage php artisan test --coverage #pest

Uninstalling xdebug

arch -arm64 pecl uninstall xdebug

Excluding Framework files

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
        <exclude>
            <directory suffix=".php">./app/Macros</directory>
            <file>./app/Http/Middleware/Authenticate.php</file>
            <file>./app/Http/Middleware/RedirectIfAuthenticated.php</file>
            <file>./app/Http/Middleware/TrustHosts.php</file>
            <file>./app/Http/Middleware/TrustProxies.php</file>
            <file>./app/Providers/BroadcastServiceProvider.php</file>
            <file>./app/Providers/HorizonServiceProvider.php</file>
            <file>./app/Providers/TelescopeServiceProvider.php</file>
        </exclude>
    </coverage>

To make a report to HTML

<logging>
    <log type="coverage-html" target="./report" charset="UTF-8"
        yui="true" highlight="true"
        lowUpperBound="50" highLowerBound="80" />
</logging>

Subscribe to You Live What You Learn

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe