How to get the PHP Code Coverage working with phpdbg on a Windows Server?

我与影子孤独终老i 提交于 2019-12-12 17:09:23

问题


Since I still have troubles with PHPUnit / PHP Code Coverage and Xdebug, I decided to try it another way -- with phpdbg.

I did it as hier shown. Tried in CMD and also in Git Bash, but the result is the same, it fails:

$ composer info | grep "phpunit"
phpunit/php-code-coverage           4.0.0  Library that provides collectio...
phpunit/php-file-iterator           1.4.1  FilterIterator implementation t...
phpunit/php-text-template           1.2.1  Simple template engine.
phpunit/php-timer                   1.0.8  Utility class for timing
phpunit/php-token-stream            1.4.8  Wrapper around PHP's tokenizer ...
phpunit/phpunit                     5.4.6  The PHP Unit Testing framework.
phpunit/phpunit-mock-objects        3.2.3  Mock Object library for PHPUnit

$ phpdbg -qrr ./vendor/bin/phpunit -v

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"

How to get the combination PHPUnit & PHP Code Coverage & phpdbg working on a Windows Server?


回答1:


Under Windows it seems that files in vendor/bin are actually batch files, invoking the original file (and not php files which phpdbg will understand).

In this case:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)
                                  ^^^^^^^^^^^^^^^^^^
"${dir}/phpunit" "$@"
 ^^^^^^^^^^^^^^

i.e. ../phpunit/phpunit/phpunit (this path is relative to vendor/bin); thus the actual file is at vendor/phpunit/phpunit/phpunit.

And you can invoke it directly via phpdbg -qrr vendor/phpunit/phpunit/phpunit then.



来源:https://stackoverflow.com/questions/40398808/how-to-get-the-php-code-coverage-working-with-phpdbg-on-a-windows-server

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