如何在运行PHPUnit的NetBeans上修复“无法识别的选项 - 运行”

时间:2015-08-09 13:04:02

标签: php netbeans phpunit

我正在尝试将PHPUnit运行到NetBeans 8.0.2中。

如果我在我的文件夹中运行#phpunit测试所有测试运行。所以看起来似乎已经做好了。

但是在NetBeans输出中我总是得到:

"C:\nginx\php\5.6.12\php.exe" "C:\nginx\php\5.6.12\phpunit.phar" "--colors" "--log-junit" "C:\Users\...\AppData\Local\Temp\nb-phpunit-log.xml" "--bootstrap" "E:\var\www\...\tests\TestHelper.php" "--configuration" "E:\var\www\...\tests\phpunit.xml" "C:\Program Files\NetBeans 8.0.2\php\phpunit\NetBeansSuite.php" "--run=E:\var\www\...\tests\app\utils\FormatUtilTest.php"

Sebastian Bergmann和贡献者的PHPUnit 4.8.2。

无法识别的选项 - 运行

完成。

也许“ - 运行消息”是正确的,因为PHPUnit手册中不存在此命令。但如果是这样,那么如何为NetBeans创建另一个脚本来执行测试?

5 个答案:

答案 0 :(得分:5)

我在PHPUnit更新后昨天遇到了同样的问题。所以我现在恢复到PHPUnit 4.7.7,直到在NB中修复。

答案 1 :(得分:3)

我也遇到过这个错误,导致最新版本的PHPUnit无法与NetBeans v8.0.2一起使用。

进一步调查此问题导致确定NetBeansSuite.php与最新版本的PHPUnit之间存在不兼容。

错误'无法识别的选项--run'由phpunit.phar抛出,而不是被NetBeansSuite.php抛出。我也不相信NetBeansSuite.php甚至被执行。

phpunit.phar,第63816行 63894,是抛出异常的地方。

在修复此问题之前,PHPUnit将无法在NetBeans v8.0.2中运行。

@Pablo:我感谢您提出问题并对您的问题发表了评论。

PHPUnit v4.7.7正常工作。

打开错误报告:https://netbeans.org/bugzilla/show_bug.cgi?id=254276

答案 2 :(得分:3)

答案是:This was indeed a bug in NB and is now fixed in nightly

可能的解决方案:

答案 3 :(得分:1)

“ - run”选项在NetBeansSuite.php中用于运行测试。因此,如果你想避免这种情况,你应该将它提交给NetBeans bugzilla [1]。

[1] https://netbeans.org/community/issues.html(PHP / PHPUnit)

答案 4 :(得分:0)

2019,问题仍然存在。如今,不再可以降级PHPUnit。因此,作为变通办法,我为phpunit创建了一个包装器脚本,该脚本负责删除不良参数。

它还完全删除了NetBeansSuite.php文件,因为它直接对phpunit脚本进行了相同的调用。

我的设置是Windows Netbeans 11,Windows PHP 7.3和cygwin包装器(因为它是bash代码)。如果有人想将其移植到本机Windows,请在此处发表评论。

#!/usr/bin/env sh
# modified phpunit script originally from vendors dir
# 1. cygwin default search path is bad in my installation...
PATH="$PATH:/bin:/usr/bin"
# original code, only adjust the ../../ to match your installation.
# the directory this is run in is where the wrapper script resides
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../../vendor/phpunit/phpunit" && pwd)
if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
   # We are in Cgywin using Windows php, so the path must be translated
   dir=$(cygpath -m "$dir");
fi
# fix netbeans parameters
while [ $# -gt 0 ]; do
  case "$1" in
    *NetBeansSuite.php) shift;;
    --run=*) PARAMS="$PARAMS ${1#--run=}"; shift;;
    --) shift ;;
    *) PARAMS="$PARAMS $1"; shift;;
  esac
done

"${dir}/phpunit" $PARAMS

您必须根据文件夹结构调整两次出现的“ ../”。

此解决方案适用于ALT-F6(运行所有测试),右键单击测试文件夹“运行测试”,还单击单个测试文件,右键单击“运行”。

“ Netbeans:工具/选项/框架和工具/ PHPUnit”的设置如下:

C:\cygwin\bin\bash.exe /cygdrive/c/workspace/Project/src/cli/phpunit

再次根据您的需要调整这些路径名。

HTH,

M。