Test coverage on PHPUnit 6.5.5 and PHP 7.2

随声附和 提交于 2019-12-02 17:15:01

问题


the problem is that lines with the switch case are not covered, the switch cases themselves are being executed.

Tested on windows


回答1:


The output is technically correct, as PHP 7.2 is now clever and no longer needs to run the case statements. I wrote about these optimisations at https://derickrethans.nl/php7.2-switch.html

Nevertheless, this is unwanted behaviour, and hence Xdebug has this "bug" fixed with https://github.com/xdebug/xdebug/commit/0690bf83109228a67dfe14a9a312045435b7b774 — this is part of Xdebug's code on GitHub, but has not made it yet into a release. It will make it into Xdebug 2.6.0beta2.




回答2:


This was (probably) answered in https://github.com/sebastianbergmann/phpunit/issues/2953.




回答3:


Best alternative: pcov

This is more faster than XDebug. More info https://github.com/krakjoe/pcov.

Another alternative: XDebug

XDebuyg will always be the best option as it is the one with the most community and time. The bad thing is that it is usually very slow compared to other roads. Dont forget update to last version ;).

Temporary solution for phpdbg

Option 1. Use CONSTANTS instead of magic strings. For example:

class SectionTypes
{
    public const APP = 'app';
    public const SHARE = 'share';
}

/* ... */

case ($type) {
    case SectionTypes::APP:
        /* do something */
        break;
}

Option 2. Use concatenations. For example:

case ($type) {
    case 'app'.'':
        /* do something */
        break;
}

Off course, the last option is ugly and not very recommended, but it can help you quickly.



来源:https://stackoverflow.com/questions/48128713/test-coverage-on-phpunit-6-5-5-and-php-7-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!