PHP单元 6.5.5 和 PHP 7.2 的测试覆盖率
Test coverage on PHPUnit 6.5.5 and PHP 7.2
问题是带有 switch case 的行没有被覆盖,switch case 本身正在被执行。
测试于 windows
这(可能)在 https://github.com/sebastianbergmann/phpunit/issues/2953 中得到了回答。
输出在技术上是正确的,因为 PHP 7.2 现在很聪明,不再需要 运行 case 语句。我在 https://derickrethans.nl/php7.2-switch.html
上写了这些优化
尽管如此,这是不需要的行为,因此 Xdebug 已将此 "bug" 修复为 https://github.com/xdebug/xdebug/commit/0690bf83109228a67dfe14a9a312045435b7b774 — 这是 Xdebug 在 GitHub 上的代码的一部分,但尚未进入一个释放。它将进入 Xdebug 2.6.0beta2。
最佳选择:pcov
这比 XDebug 更快。更多信息 https://github.com/krakjoe/pcov.
另一种选择:XDebug
XDebuyg 永远是最佳选择,因为它拥有最多的社区和时间。不好的是,与其他道路相比,它通常很慢。不要忘记更新到最新版本 ;)。
phpdbg的临时解决方案
选项 1。使用 CONSTANTS 代替魔术字符串。例如:
class SectionTypes
{
public const APP = 'app';
public const SHARE = 'share';
}
/* ... */
case ($type) {
case SectionTypes::APP:
/* do something */
break;
}
选项 2. 使用串联。例如:
case ($type) {
case 'app'.'':
/* do something */
break;
}
当然,最后一个选项很丑,不是很推荐,但它可以帮助你很快。
问题是带有 switch case 的行没有被覆盖,switch case 本身正在被执行。
测试于 windows
这(可能)在 https://github.com/sebastianbergmann/phpunit/issues/2953 中得到了回答。
输出在技术上是正确的,因为 PHP 7.2 现在很聪明,不再需要 运行 case 语句。我在 https://derickrethans.nl/php7.2-switch.html
上写了这些优化尽管如此,这是不需要的行为,因此 Xdebug 已将此 "bug" 修复为 https://github.com/xdebug/xdebug/commit/0690bf83109228a67dfe14a9a312045435b7b774 — 这是 Xdebug 在 GitHub 上的代码的一部分,但尚未进入一个释放。它将进入 Xdebug 2.6.0beta2。
最佳选择:pcov
这比 XDebug 更快。更多信息 https://github.com/krakjoe/pcov.
另一种选择:XDebug
XDebuyg 永远是最佳选择,因为它拥有最多的社区和时间。不好的是,与其他道路相比,它通常很慢。不要忘记更新到最新版本 ;)。
phpdbg的临时解决方案
选项 1。使用 CONSTANTS 代替魔术字符串。例如:
class SectionTypes
{
public const APP = 'app';
public const SHARE = 'share';
}
/* ... */
case ($type) {
case SectionTypes::APP:
/* do something */
break;
}
选项 2. 使用串联。例如:
case ($type) {
case 'app'.'':
/* do something */
break;
}
当然,最后一个选项很丑,不是很推荐,但它可以帮助你很快。