Test coverage on PHPUnit 6.5.5 and PHP 7.2

前端 未结 3 1801
名媛妹妹
名媛妹妹 2021-01-27 02:23

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

Tested on windows

相关标签:
3条回答
  • 2021-01-27 02:51

    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.

    0 讨论(0)
  • 2021-01-27 02:58

    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.

    0 讨论(0)
  • 2021-01-27 02:59

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

    0 讨论(0)
提交回复
热议问题