PHPUnit Code Coverage Analysis
In this tutorial, I will demonstrate on my existing Laravel package called Ekko how to configure code coverage on PHPUnit, analyze given results and improve tests to achieve maximum code coverage.
Code coverage helps you detect which areas of your application are not covered with tests. Imagine if you have a number of classes in your domain and you have tests for them. In order to determine which method has tests written for it, you would have to manually check the tests to see if it has any tests that cover that method. Also, you would have to check if the test for that method covers all possibilities inside that method; This refers to if statements and branching.
As is turns out, a package I wrote called Ekko that helps you detect which menu item is active based on current URL and apply an appropriate CSS class to that item, already has tests written for it in PHPUnit. This is the perfect scenario for demonstrating what code coverage is, how to achieve maximum code coverage and why.
- Cover image Hydrogen Remixed created by Kevin Nasto
To continue reading, choose a subscription plan: