sebastianbergmann / phpcov

TextUI frontend for php-code-coverage
BSD 3-Clause "New" or "Revised" License
223 stars 58 forks source link

Executing merge command outputs empty coverage #84

Closed zeroble-23 closed 5 years ago

zeroble-23 commented 5 years ago

Problem: The files I want to merge are not being merged. The resulting file is empty, but no errors are shown.

Description: I have setup my environment to run phpcov inside a docker container (named coverage-merger). I assume the setup was successful because when I run the command below, no errors are shown.

/vendor/bin/phpcov merge /app/tool/files_to_merge --clover /app/tool/result/clover.xml

output:

coverage-merger    | phpcov 5.0.0 by Sebastian Bergmann.
coverage-merger    |
coverage-merger    |
coverage-merger    | Generating code coverage report in Clover XML format ... done

However, I have 2 files in the /files_to_merge directory, and they are not being merged. A resulting file is generated, but the metrics are shown as 0 (it has no content from the original files).

Both files in the /files_to_merge directory were generated from tests using phpunit with the --coverage-php option enabled. The files are .cov and have php content inside.

I have tried generating the output in html and xml formats, but both of them generate empty results. Is there something I'm missing? I have attached the target files and the result for reference.

Target files: phpcov1.txt phpcov2.txt

Result: clover.txt

Versions PHP 7.2.10 PHPUnit 6.5.13 phpcov 5.0.0 Docker 18.03

ahocquard commented 5 years ago

Hello,

Did you configured the phpunit.xml with a whitelist? I had the same problem, and after investigation, the files .cov had no data due to this missing configuration.

https://phpunit.readthedocs.io/en/7.4/code-coverage-analysis.html#whitelisting-files

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">your_directory/</directory>
        </whitelist>
    </filter>
zeroble-23 commented 5 years ago

Hey thanks for the input. Do you mean the .cov files used for merging? Because they do have content, (I attached them in my comment as phpcov1.txt because phpcov1.cov couldn't be uploaded).

I also tried adding a phpunit.xml with the filter and whitelist nodes to my root folder, but I still get the same empty output.

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1549421579">
  <project timestamp="1549421579">
    <metrics files="0" loc="0" ncloc="0" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
  </project>
</coverage>
sebastianbergmann commented 5 years ago

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

zeroble-23 commented 5 years ago

Thank you. Actually, while trying to re-create the problem I noticed that the path values set in $filter->setWhitelistedFiles() inside the .serialized file were not matching to the actual test files. This was due to manually moving the files from another location.

$filter->setWhitelistedFiles(array (
  '/app/tool/files_to_merge/exampleTest.php' => true,
));

By keeping the files inside their directory (the one whitelisted in the phpunit.xml file) and running the command from there I could finally generate a correctly merged file.

Everything works as it should. Sorry for the trouble.