We are working on a legacy php solution developed in Symfony. The solution consist of around 1000 actions. We have now introduced a test automation team to automate the testing using Selenium. But we were unable to measure how far has the automation is covered.
To get an approximate coverage we are planning to use https://github.com/sebastianbergmann/php-code-coverage. So our idea was like this, we can execute the automation on a separate domain where the php code coverage is enabled (using pcov). So the coverage tool will record the coverage like it is done while doing phpUnit.
But unfortunately the tool is not recording the coverage. It is always recorded as 0% in their dashboard.
This is the code snippet I used for enabling the code coverage
<?php
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
$fileList = shell_exec('find /var/www/html/project/src -type f -name "*.php"');
$filter = new Filter;
$filter->includeFiles(preg_split("/\\r\\n|\\r|\\n/", $fileList));
$coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$filter
);
$coverage->start(md5(time()));
$kernalObj = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
$coverage->stop();
(new HtmlReport)->process($coverage, 'tmp/code-coverage-report');
return $kernalObj;
};
I have read in some documents that it is not possible to execute php-code-coverage without phpUnit and some are saying it is possible https://github.com/sebastianbergmann/php-code-coverage/issues/157