【问题标题】:Why phpUnit test does not work? ZF2为什么phpUnit测试不起作用? ZF2
【发布时间】:2015-03-15 23:13:30
【问题描述】:

我正在阅读 Slavey Karadzhov 的《Learn ZF2: Learning By Example》一书。现在我在第 103-107 页。我正在尝试按照描述运行 PHPUnit 测试,但没有任何反应... 问题出在哪里以及如何解决?

要进入相同的情况,您必须:

git clone https://github.com/slaff/learnzf2.git .

composer.phar self-update
composer.phar install

git stash
git checkout 'ch-unittest'

这应该会为您带来与我相同的文件(= 与书中一样)。

现在,我尝试运行这个命令:

ZF2_PATH=`pwd`/vendor/zendframework/zendframework/library \php vendor/bin/phpunit -c module/User/tests/

并且该命令无法按预期工作... 我希望有一些测试结果输出,但我得到的只是输出女巫类似于我在vendor/bin/phpunit 文件中的内容。它是:

#!/usr/bin/env sh
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../phpunit/phpunit/composer/bin"
BIN_TARGET="`pwd`/phpunit"
cd "$SRC_DIR"
"$BIN_TARGET" "$@"

更准确地说,第一行 (#!/usr/bin/env sh) 不会出现在输出中。其余的都会出现。

**

我正在使用 Git Bash(git 版本 1.9.4.msysgit.1)在 Windows 8.1 Pro OS 上运行代码。 php 关键字似乎工作得很好,因为编写 php -v 工作正常(输出 PHP 5.5.12 (cli) (built: Apr 30 2014 11:20:58) ...

我自己的猜测是 Git bash 无法解析它在 vendor/bin/phpunit 中找到的代码,所以它在那里失败了......但这只是猜测......

编辑#1: 刚刚尝试使用 LAMP 设置共享主机。一切都很顺利。 Zend Framework 2 和 Windows 似乎在某些方面不是那么友好(例如,在刚刚提到的单元测试用例中)。看起来这本非常好的书(没有讽刺,它确实是一本好书)如果它有更多关于 VirtualBox + Vagrant + PuPHPet(或类似的东西)的章节会更好。

【问题讨论】:

    标签: php bash zend-framework zend-framework2 phpunit


    【解决方案1】:

    书中使用的composer.json文件行:phpunit/phpunit" : "3.7.*

    我已将 phpunit/phpunit" : "3.7.* 更改为 phpunit/phpunit" : "4.5.*,因为 PHPUnit 的 4.5 版本是当前稳定版。 然后,当然:php composer.phar update 然后这个会很好地工作:

    ZF2_PATH=`pwd`/vendor/zendframework/zendframework/library \php vendor/phpunit/phpunit/phpunit -c module/User/tests/
    

    上面的命令和书中的不一样

    在 Windows 8.1、Ubuntu Trusty 14.04 LTS x64 上测试,隔离开发环境提供here。效果很好。

    还有一种方法可以让 PHPUnit 3.7.* 在所有系统(我测试的相同系统)上工作,但命令必须更改为:

    ZF2_PATH=`pwd`/vendor/zendframework/zendframework/library \php vendor/phpunit/phpunit/composer/bin/phpunit -c module/User/tests/
    

    上面的命令和书中的不一样

    所以...这里我们提到了两种使用 PHPUnit 测试的方法来使它们工作。由我们决定两个女巫更好。目前我更喜欢将 PHPUnit 版本增加到 4.5 的版本。

    非常感谢 Slavey Karadzhov - 这本书的作者,他为使用 Zend Framework 2(ZF2) 进行编程提供了独立的开发环境。
    另外,感谢@jamaldo、@steeler 和@malte,他们的活动(post、cmets)让我走上了正轨。我说的帖子在这里:https://stackoverflow.com/questions/23881289/php-vendor-bin-phpunit-is-printing-in-console-a-text

    【讨论】:

      猜你喜欢
      • 2012-07-20
      • 2013-11-05
      • 2015-07-08
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2018-05-12
      • 1970-01-01
      相关资源
      最近更新 更多