0

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

2
  • This depends on how exactly the testing is performed. Does Selenium send the request to a webserver where coverage reporting is enabled? Keep in mind that this can be a completely different process Commented Dec 16, 2024 at 14:18
  • @NicoHaase Yes.. Selenium is sending the request to the webserver. ` Keep in mind that this can be a completely different process` didn't understood this Commented Dec 17, 2024 at 4:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.