php xdebug_get_code_coverage()返回空数组

k5hmc34c  于 2023-05-16  发布在  PHP
关注(0)|答案(1)|浏览(87)

我在脚本的开头有以下内容:

if ($jsonFile = $_REQUEST['saveCoverageJson']??'')
{
    xdebug_start_code_coverage();
    register_shutdown_function(function() use ($jsonFile)
    {
        // wrapped to make pretty sure it's the very last thing executed
        register_shutdown_function(function() use ($jsonFile)
        {
            xdebug_stop_code_coverage();
            $dir = __DIR__.'/../misc/coverage-reports';
            $coverageData = xdebug_get_code_coverage();
            var_dump($coverageData);
            file_put_contents(
                $dir."/$jsonFile.json",
                json_encode($coverageData, JSON_PRETTY_PRINT)
            );
        });
    });
}

但是xdebug_get_code_coverage()返回一个空数组。出什么事了?我将xdebug.mode设置为coverage。谢谢

bkkx9g8r

bkkx9g8r1#

因为我叫了xdebug_stop_code_coverage()根据文档,它会破坏收集的信息!

相关问题