【发布时间】:2014-09-27 19:57:16
【问题描述】:
我正在尝试使用 xdebug 来计算超薄应用程序的代码覆盖率。结果似乎是错误的,因为它告诉我路由处理程序中的所有代码都没有执行(我做了一些请求......)
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$app->get('/data', function () use ($app) {
echo "data";
});
$app->get('/STOP', function () use ($app) {
$data = xdebug_get_code_coverage();
var_dump($data);
});
$app->run();
我使用以下方式运行服务器:
php -S localhost:8080 -t . test.php
然后执行两个请求:
curl http://localhost:8080/server.php/data
curl http://localhost:8080/server.php/STOP > result.html
result.html 中的覆盖率输出告诉我:
'.../test.php' =>
array (size=11)
0 => int 1
5 => int 1
6 => int -1
7 => int 1
8 => int 1
9 => int 1
10 => int -1
11 => int 1
12 => int 1
473 => int 1
1267 => int 1
第 6 行应该是int 1,因为它已经被执行了。我错过了什么?
【问题讨论】: