Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need .cov file format for being able to merge multiple coverage reports #3245

Closed
delatbabel opened this issue Jun 20, 2016 · 3 comments
Closed
Labels

Comments

@delatbabel
Copy link

phpcov https://github.com/sebastianbergmann/phpcov requires coverage reports that are generated in PHP_CodeCoverage *.cov files. Running codeception with the --coverage-php option reports:

[RuntimeException]
The "--coverage-php" option does not exist.

See also #1679

This should just be a matter of recognising the --coverage-php option and passing it to phpunit.

@delatbabel delatbabel changed the title Need .cov file format for being able to merge mutliple coverage reportgs Need .cov file format for being able to merge mutliple coverage reports Jun 20, 2016
@delatbabel delatbabel changed the title Need .cov file format for being able to merge mutliple coverage reports Need .cov file format for being able to merge multiple coverage reports Jun 20, 2016
@DavertMik
Copy link
Member

Does simple --coverage not producing the expected result?
By default PHP report is always printed and saved in tests/_output/coverage.serialized which should be compatible with php cov format

@delatbabel
Copy link
Author

Thanks for the information. I have left the organisation where this was an issue but I will pas it on to them.

@mikkelcp1
Copy link

mikkelcp1 commented Jul 9, 2018

It would be nice to be able to work with coverage reports ( per suite and overall ), where you simply want to merge coverage after the coverage is collected per test suite.

One option: Allow the user to override the '--coverage' flag with a non-default file name, i.e. 'coverage-unit.serialized'. Alternative is to rename file in build script.

Provide a command (like the following quick code originally taken from phpcov merge) to merge and generate reports only. Might be helpful for others who also found this via google search 'merge coverage codeception'.

i.e. the following:
` /**
* Merges codeception captured Coverage files, so we can see them indiviually or overall
* i.e. pass them into SonarQube (unit, intergration, overall)
*
* @param $outfilepath - output coverage file.
* @param $infilepaths - inputs coverage file(s).
*/
public function merge(string $outfilepath, array $infilepaths)
{
$mergedCoverage = new \SebastianBergmann\CodeCoverage\CodeCoverage;

    echo "\n\n";
    
    foreach ($infilepaths as $coverageFile) {
        $contents = file_get_contents($coverageFile);
        $coverage = @unserialize($contents);
        if( $coverage == false)
        {
            $coverage = include "$coverageFile";
        };
        
        if ($coverage === false || !($coverage instanceof \SebastianBergmann\CodeCoverage\CodeCoverage)) {
            echo "'$coverageFile' is not a CodeCoverage serialized file.\n";
            continue;
        }
        else
        {
            echo "Adding Coverage from '$coverageFile'\n";
        }
        $mergedCoverage->merge($coverage);
        unset($coverage);
    }
  
    echo "Writing merged CloverReport to $outfilepath\n";
    $writer = new \SebastianBergmann\CodeCoverage\Report\Clover;
    $writer->process($mergedCoverage, $outfilepath);
    echo "Finished Writing merged CloverReport to $outfilepath\n";
    
    echo "Writing merged Text to $outfilepath.txt\n";
    $writer = new \SebastianBergmann\CodeCoverage\Report\Text(
        //$this->settings['low_limit'],
        //$this->settings['high_limit'],
        //$this->settings['show_uncovered'],
        //false
        );
    file_put_contents(
        "${outfilepath}.txt",
        $writer->process($mergedCoverage, false)
        );
    echo "Finished Writing Text CloverReport to $outfilepath.txt\n";

}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants