【问题标题】:Cygwin issue when trying to run phpunit within Yii2尝试在 Yii2 中运行 phpunit 时出现 Cygwin 问题
【发布时间】:2017-03-30 12:42:19
【问题描述】:

我正在尝试在 Yii2 基本安装中运行 phpunit,但每当我从命令行运行 php vendor/bin/phpunit 时,我都会得到以下输出:

注意:我使用的是 Windows 7。

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" "$@"

谁能告诉我这里的问题是什么?我之前没有使用过phpunit,所以不确定发生了什么。

【问题讨论】:

标签: php unit-testing yii2 phpunit cygwin


【解决方案1】:

嗯,这是一个显而易见的解决方案:

文件vendor/bin/phpunit不是PHP脚本,而是shell脚本。

从一开始就删除php,然后简单地运行vendor/bin/phpunit

Source.

【讨论】:

  • 你好 Brett,我试过不带 PHP 的命令,但是没有它,PHP 扩展类在调用中找不到。这是错误:致命错误:在第 8 行的 \tests\ProgrammerControllerTest.php 中找不到类 'PHPUnit_Framework_TestCase'
  • @Jaymin 我不确定我是否 100% 关注您的问题 - 也许您可以创建一个包含更多信息的新问题?
  • 删除 php 我得到了'php' is not recognized as an internal or external command,并使用 php 打印你提到的 shell 脚本文件里面的内容。如问题中所述,它只是输出脚本
【解决方案2】:

从命令中删除 php 我得到'php' is not recognized as an internal or external command,并使用 php 打印您提到的 shell 脚本文件中的内容。如问题中所述,它只是输出脚本

解决这个问题

  • 按照here 的说明将 php 添加到路径

或者

  • 临时使用,试试这个:(使用npm或composer的好处)
    SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多