![]() ![]() Xdebug is a mature and actively developed PHP extension with a profiler, step debugger, and a code coverage tool. phpdbg is implemented as a server API, which limits its usefulness, but it provides an easy approach to code coverage without having to install PECL extensions. It has features similar to Xdebug, albeit relatively less adoption in community and IDEs. Phpdbg is a PHP Debugger shipped with PHP itself. PCOV, a recent PHP extension by Joe Watkins aims to be a minimal and fast solution for code coverage, which solves the often slow Xdebug version 2 series. Xdebug, a PHP extension project started back in 2002 by Derick Rethans is the de-facto tool that helps in step debugging, profiling, and of code in code coverage. PHP Code Coverage feature is often provided as part of a bigger tooling the PHP developers would use otherwise. If path coverage is desired, that can be specified from the XML configuration file as well:. Using code coverage data from the tool used (such as PCOV or Xdebug), PHPUnit can generate code coverage reports in various formats that are human-readable and machine-readable for further processing. In PHPUnit 9.x series, Code Coverage can be enabled from the phpunit.xml(.dist) configuration file, with a setup similar to this: It's possible to use this library as an abstraction layer for various code coverage tools. sebastianbergmann/php-code-coverage is the package used by PHPUnit for its code coverage functionality. PHPUnit, the popular PHP Unit Testing framework supports Xdebug, PCOV, and phpdbg for code coverage reports. Some tools can report specific lines that were executed, and some tools can go as far as showing which specific branches of code were executed. PHPUnit has support various formats to report code coverage, including a simple CLI output option.Ĭode Coverage tools are not perfect. While 100% of code coverage during a test does not mean the application will be bug-free, it is a measurable indication on how thorough the unit tests are.Ĭode Coverage reports can reveal how effective those tests are, and tools such as PHPUnit can generate meaningful reports using the code coverage data. ![]() The most common use case is to measure how much of the code base gets executed, and thus "covered" and "tested" during a test. Example
0 Comments
Leave a Reply. |