phpunit merge two or more clover.xml reports

前端 未结 3 1637
粉色の甜心
粉色の甜心 2021-02-10 06:02

I have several clover.xml reports of different extensions of a projects. I want to combine them into one clover.xml and then create it into a clover html. But i see no way with

3条回答
  •  不思量自难忘°
    2021-02-10 06:36

    As jkrnak commented above you cannot simply merge the XML files as there are computed values such as lines covered etc.. that are computed at output time. You need to "merge" while still working with native PHP code. In my case I wanted to capture the coverage of a series of web service calls executed by newman. To do this I set a flag at the beginning of execution which persists across invocations (using a cache) and then also save the PHP_CodeCoverage object in the cache as well. My implementation (in Laravel) looks something like this:

    if ( isset($_GET['initCoverage']) )
    {
        Cache::put( 'recordCoverage', true, 1440 );
    }
    
    if ( Cache::has('recordCoverage') )
    {
        if ( Cache::has('coverage') )
        {
            $coverage = Cache::get('coverage');
        }
        else
        {
            $filter = new PHP_CodeCoverage_Filter;
            $filter->addDirectoryToBlacklist( base_path() . '/vendor' );
    
            $coverage = new PHP_CodeCoverage( null, $filter );
        }
    
        $coverage->start( Request::method() . " " . Request::path() );
    
        if ( isset($_GET['dumpCoverage']) )
        {
            if ( Cache::has('coverage') ) 
            {
                // Prevent timeout as writing coverage reports takes a long time
                set_time_limit( 0 );
    
                $coverage = Cache::get( 'coverage' );
                $writer = new PHP_CodeCoverage_Report_Clover;
                $writer->process($coverage, 'results/coverage/clover.xml');
            }
    
            Cache::forget('recordCoverage');
            Cache::forget('coverage');
        }
        else
        {
            register_shutdown_function( function($coverage) 
            {
                $coverage->stop();
    
                Cache::put( 'coverage', $coverage, 1440);
            }, $coverage);
        }
    }
    

    This captures the series of tests in a single coverage object which is then output when I make a call with the "dumpCoverage" flag.

提交回复
热议问题