【问题标题】:How to fix the "unrecognized option --run" on NetBeans running PHPUnit如何修复运行 PHPUnit 的 NetBeans 上的“无法识别的选项 --run”
【发布时间】:2015-11-01 11:30:55
【问题描述】:

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

如果我在我的文件夹中运行 # 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。

无法识别的选项 --run

完成。

也许“--run message”是对的,因为这个命令在 PHPUnit 手册中不存在。但如果是这样,如何为 NetBeans 创建另一个脚本来执行测试?

【问题讨论】:

    标签: php netbeans phpunit


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我也遇到了这个错误,导致最新版本的 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

      【讨论】:

      • NB Nightly 中的错误现已修复。
      【解决方案3】:

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

      可能的解决方案:

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          【解决方案5】:

          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.

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-01-09
            • 1970-01-01
            • 2011-04-18
            • 2020-08-30
            • 2022-07-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多