Route coverage test for Laravel.
This package is auto-updated.
Last update: 2024-02-19 23:07:49 UTC
Tests to ensure that all routes are covered by atleast one feature test.
This is a slightly crude but effective way of checking which of your routes lack feature tests. It simply uses middleware to record all routes being hit during the feature tests, checks to ensure that matches the full route amount.
zRouteCoverageTest has a funny name for a reason - PHPUnit runs tests in alphabetical order. To most easily capture all the test coverage data first, keep it named to run last, and in your Feature directory. Also - the output relies on routes having names to give useful data. Happy Testing!
Via Composer, you can run a
composer require which will grab the latest version of this repo...
composer require --dev jrmadsen67/laravel-route-coverage-test
php artisan vendor:publish --provider="jrmadsen67\LaravelRouteCoverageTest\Providers\CoverageServiceProvider"
...to publish the required config and feature test file into your app. The middleware is automatically applied globally by this packages service provider.
Note: See version tagged
1.1 for Laravel
The following table describes which version of this packagae you will require for the given PHP & Laravel version.
|^7.4 | ^8.0
|^7.0 | ^8.0
Run your tests as normal via phpunit, or the default Laravel test suite:
php artisan test # OR vendor/bin/phpunit
There is a Docker container that is pre-built that contains an Alpine CLI release of PHP + PHPUnit + xdebug. This is setup to test the project and can be setup via the following:
This should trigger Docker Compose to build the image.
There are tests for all code written, in which can be run via:
# Using PHPUnit, with code coverage reporting, within the Docker container composer test # Using PHPUnit, with code coverage reporting, within the Docker container, specifying a direct test composer test-filtered ItGeneratesSqlFromMigrations # Using PHPUnit, with code coverage reporting, using local phpunit and xdebug composer test-local # Using PHPUnit, with code coverage reporting, using local phpunit and xdebug, specifying a direct test composer test-local-filtered ItGeneratesSqlFromMigrations
In those tests, there are Feature tests for a production ready implementation of the package. There are also Unit tests for each class written for full coverage.
You can also easily open a shell in the testing container by using the command:
Any and all project changes for releases should be documented below. Versioning follows the SEMVER standard.
Big project refactor, see the changelog sections for more info.
- Config support for defining excluded routes and route groups
- Docker container for a fixed testing environment with code coverage support via XDebug
- New global tests path helper
tests_path()that will generate a fully qualified path to the tests directory
- Various composer scripts to shortcut common testing and style fixing functionality
- GitHub actions for automated testing and style fixes as a basic CI pipeline
- Spatie Ray support for enhanced debugging
- Testing of this packages functionality
- Code coverage and getting the coverage to around ~95%
- PHP-CS-Fixer for making the project style adhere to a fixed set of code standards
- Binding the package to both PHP and Laravel version requirements for easy compatibility reference
- Refactored shared methods between the middleware and test into a new
ReportHelperobject for testing purposes and centralising of reusable code
- Refactored the package middleware to reside instead within the package and its namespace, again so it can be tested and also to not pollute the installed application
zRouteCoverageTestto better reflect what the test covers
- Complete refactor of the readme to best reflect the changes in this update
- The middleware now applies itself globally using the latest method of doing so for Laravel versions
- Manual version lock in for
^1.0to fix composer getting confused about requirement conflicts
- The package middleware is no longer published into the installed application and is instead held within the package and its namespace
Initial release. Pre-semver implementation.