如何在 Windows 服务器上使用 phpdbg 获得 PHP 代码覆盖率?
How to get the PHP Code Coverage working with phpdbg on a Windows Server?
因为我还有troubles with PHPUnit / PHP Code Coverage and Xdebug, I decided to try it another way -- with phpdbg。
我按照 hier 所示进行了操作。在CMD里试过,也在GitBash里试过,结果一样,都失败了:
$ 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" "$@"
如何在 Windows 服务器上获得组合 PHPUnit & PHP 代码覆盖率 & phpdbg?
在 Windows 下,似乎 vendor/bin
中的文件实际上是批处理文件,调用原始文件(而不是 phpdbg 可以理解的 php 文件)。
在这种情况下:
dir=$(d=${0%[/\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)
^^^^^^^^^^^^^^^^^^
"${dir}/phpunit" "$@"
^^^^^^^^^^^^^^
即../phpunit/phpunit/phpunit
(此路径是相对于vendor/bin
);因此实际文件位于 vendor/phpunit/phpunit/phpunit
.
然后您可以通过 phpdbg -qrr vendor/phpunit/phpunit/phpunit
直接调用它。
因为我还有troubles with PHPUnit / PHP Code Coverage and Xdebug, I decided to try it another way -- with phpdbg。
我按照 hier 所示进行了操作。在CMD里试过,也在GitBash里试过,结果一样,都失败了:
$ 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" "$@"
如何在 Windows 服务器上获得组合 PHPUnit & PHP 代码覆盖率 & phpdbg?
在 Windows 下,似乎 vendor/bin
中的文件实际上是批处理文件,调用原始文件(而不是 phpdbg 可以理解的 php 文件)。
在这种情况下:
dir=$(d=${0%[/\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)
^^^^^^^^^^^^^^^^^^
"${dir}/phpunit" "$@"
^^^^^^^^^^^^^^
即../phpunit/phpunit/phpunit
(此路径是相对于vendor/bin
);因此实际文件位于 vendor/phpunit/phpunit/phpunit
.
然后您可以通过 phpdbg -qrr vendor/phpunit/phpunit/phpunit
直接调用它。