In a current project we are trying to always maintain 100% test coverage for our Laravel 5.3 application. The other day I noticed something weird though. For some reason in controllers any code that is not run, is not flagged as missing a test. However, if I add a function to a model and forget to write a test for it shows up as code missing testing. Here is an example code coverage report for a model:
Here is an example code coverage report for a controller:
You can see in a functional test I test an endpoint that calls the destroy()
function at the top, however I forgot to write a test for the endpoint that calls answer()
. Why does this not get flagged as code that is not covered?
Simply running:
phpunit --coverage-html ./storage/logs/phpunit
Also here is my phpunit.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>
UPDATE:
I think I may have figured out how to fix the issue. In the phpunit.xml
change processUncoveredFilesFromWhitelist="true"
to false
. Unforuntuately, the test takes about 3 times as long to run but it seems to flag everything that isn't executed.