PHP Classes

Laravel Route Coverage: Report the coverage of Laravel project tests

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 16 All time: 11,423 This week: 488Up
Version License PHP version Categories
laravel-route-covera 1.0MIT/X Consortium ...7HTML, Libraries, Console, Design Patt..., T..., P...
Description 

Author

This package can report the coverage of Laravel project tests.

It can scan the current project tests to check which routes those tests cover.

The package can generate reports in the current terminal console or as HTML to show the number of project routes, the number of routes covered by tests, the percentage of the total number of routes covered, and listings of routes, controllers, methods, and actions.

Innovation Award
PHP Programming Innovation award nominee
August 2023
Number 6
One way to measure the quality of a software project is to measure the ability of the project code to test itself and verify that the code works as intended.

The projects with the best quality often provide tests that cover a significant part of the code.

This package provides means to measure the extension of the tests provided by a Laravel package to test its features implemented by routes.

This way, developers can understand how much of their project code is covered by tests. Therefore they can also have an idea of how many tests need to be added to improve the coverage of the project tests.

Manuel Lemos
Picture of Andrey Iatsenko
  Performance   Level  
Innovation award
Innovation award
Nominee: 7x

 

Documentation

LaravelRouteCoverage

Packagist Version GitHub Workflow Status Coverage License Packagist Downloads Packagist Downloads

Laravel route coverage report.

With this package you can see the percentage of test coverage of your routes. Unless of course you do it through Laravel or PHPUnit tests.

How it works?

The package will scan all your tests collecting all the http queries that are called in them. After that, it will compare the results with the routes of your application. Routes are taken only by the App prefix to exclude vendor routes.

:scroll: Installation

The package can be installed via composer:

composer require yzen.dev/laravel-route-coverage --dev

:scroll: Usage

Generate report:

php artisan route:coverage

After executing the command, the result of the report will be displayed in the console in the following form:

<img width="1148" alt="console-all-routes" src="https://user-images.githubusercontent.com/24630195/157137803-d73fe73e-a0fc-49a1-8eb3-aeb3daf43b30.png">

Possible options:

php artisan route:coverage --group-by-controller

In this case, all the results will be grouped by controllers, displaying how many actions there are in the controller, and how many of them are covered by tests.

<img width="448" alt="console-group-by-controller" src="https://user-images.githubusercontent.com/24630195/157138734-03639864-ea6c-45eb-8819-6dc732da9e3c.png">

php artisan route:coverage --html

Due to the --html option, you will also receive a generated report in the html page. The report will be located in the public directory public/route-coverage

<img width="1721" alt="html-report" src="https://user-images.githubusercontent.com/24630195/157138963-a6a0d24c-2020-4546-845a-130897cc9545.png">


  Files folder image Files (39)  
File Role Description
Files folder image.github (1 directory)
Files folder imagepublic (1 file)
Files folder imagesrc (4 files, 4 directories)
Files folder imagetests (5 files, 2 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file coverage.xml Data Auxiliary data
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:16
This week:0
All time:11,423
This week:488Up