Since PhpUnit has a custom implementation for running PHPT files that occurs in a separate process, getting code coverage integrated with PhpUnit can be quite difficult.
However, if all you need is coverage (or you are ready to do some post-processing yourself), it becomes pretty trivial.
In its simplest form, all you have to do is make xDebug calls from your PHPT files. Using PHP_CodeCoverage (and Composer to autoload classes), your --FILE-- section might look like this:
--FILE-- <?php require __DIR__ . '/../../../vendor/autoload.php'; $coverage = new \PHP_CodeCoverage; $coverage->start('test'); $prFiles = prFiles::getInstance()->transfer( $_FILES, __DIR__ . '/../_data/', 'test.txt' ); var_dump($prFiles); $coverage->stop(); $writer = new \PHP_CodeCoverage_Report_PHP; $writer->process($coverage, __DIR__ . '/../../../build/log/coverage-data.php'); ?>
All collected coverage data will be placed in the coverage-data.php .
You can download this information and combine it with other coverage information (for example, from PhpUnit) to create an output in any format.
Coverage logic can be placed in a separate class, leaving you only two lines to add to each test that you want to cover:
--FILE-- <?php require __DIR__ . '/../../../vendor/autoload.php'; cover::start; $prFiles = prFiles::getInstance()->transfer( $_FILES, __DIR__ . '/../_data/', 'test.txt' ); var_dump($prFiles); cover::stop; ?>
And cover class:
<?php class cover { private static $coverage; public static function start() { self::$coverage = new \PHP_CodeCoverage; $filter = self::$coverage->filter(); $filter->addFileToBlacklist(__FILE__); self::$coverage->start('test'); } public static function stop() { self::$coverage->stop(); $writer = new \PHP_CodeCoverage_Report_PHP; $writer->process(self::$coverage, __DIR__ . '/../build/log/coverage-data.php'); } }
Since the coverage logic lives outside of the PHPT file, you can easily access the configuration files or add other logic.