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.

2
  • The answer to stackoverflow.com/questions/348850/code-coverage-tools-for-php may be what you are after? Commented Apr 29, 2021 at 7:41
  • I think it might be better if you use some static code analysis via e.g. psalm 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. Commented Apr 29, 2021 at 7:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.