0

I am using Laravel to build my own website, and I want to know the coverage for my source code during a user interaction event instead of writing testing cases using PHPUnit.

From my perspective, PHPUnit only generate reports that the unit tests touch, but if I want to get the code coverage during the execution, meaning generate the code coverage report after php artisan serve

What should I do to achieve this feature? For instance:

$filter = new Filter;
$filter->includeDirectory('/path/to/directory');

$coverage = new CodeCoverage(
    (new Selector)->forLineCoverage($filter),
    $filter
);

$coverage->start();

// Some User Interactions to the Web Service

$coverage->stop();

// Generating reports during the interactions
(new HtmlReport)->process($coverage, '/tmp/code-coverage-report');

All comments, answers, and bits of advice are welcome.

Thank you.

Tverous
  • 113
  • 6
  • The answer to https://stackoverflow.com/questions/348850/code-coverage-tools-for-php may be what you are after? – Nigel Ren Apr 29 '21 at 07:41
  • I think it might be better if you use some static code analysis via e.g. [psalm](https://psalm.dev/) to try and detect unreachable or dead code. I don't think there's much point in figuring out what an average user request covers because in most cases it won't cover exceptions but you really want the exception branches to be there regardless. Also your tags are wrong because this has nothing to do with formal testing. – apokryfos Apr 29 '21 at 07:51

0 Answers0