【发布时间】:2016-07-24 04:02:33
【问题描述】:
如https://phpunit.de/manual/current/en/installation.html#installation.phar.verification 中所述,全局安装 PHAR 的步骤如下:
$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.
我按照上面的方法,但使用的是旧版本的 URL,即https://phar.phpunit.de/phpunit-old.phar(因为我们的 PHP 版本较旧)。然后我运行了以下命令 -
$ chmod +x phpunit-old.phar
$ sudo mv phpunit-old.phar /usr/local/bin/phpunit
注意 - 我的 PHP 版本是 5.3.29。 phpunit.de 中的旧稳定版本部分说 PHPUnit 4.8 在 PHP 5.3、PHP 5.4、PHP 5.5 和 PHP 5.6 上受支持。
到这里为止看起来还不错。但是,运行 phpunit --version 会给出 -
PHP Fatal error: require(): Cannot redeclare class phpunit_extensions_database_constraint_tableisequal in /usr/local/bin/phpunit on line 109
zend_mm_heap corrupted
因此,到目前为止,我没有将 .phar 移动到 /usr/local/bin/(在第 3 步中),而是通过运行它来管理 -
$ php phpunit-old.phar –-version
我也能够以这种方式运行我的单元测试用例 -
php /home/sandeepan/phpunit-old.phar /var/cake_1.2.0.6311-beta/app/webroot/openx/lib/ad_agencies/unittests/Admarvel_generic_network_test.php
但是,现在我需要将 phpunit 与 phing 集成。我想使用PHPUnitTask of phing 提供的基本实用程序。所以,我想它需要全局安装 phpunit phar。
我写了以下内容来试试我的运气 -
<phpunit haltonfailure="true" haltonerror="true"
pharlocation="/home/sandeepan/phpunit-old">
<formatter type="plain" usefile="false" />
<batchtest>
<fileset dir="${dir.scratchpad}/${dir.subdir}/unittests">
<include name="**/*_test.php"/>
</fileset>
</batchtest>
</phpunit>
但我得到了这个错误 -
BUILD FAILED
...
: PHPUnitTask requires PHPUnit to be installed
更新
参考 stackoverflow.com/a/23410676/351903,我尝试使用这个旧版本的 Phpunit,即 PHPUnit-3.7.35。现在,phpunit --version 命令有效。但是我仍然没有成功使用 Phing 的 PHPUnitTask。仍然收到PHPUnitTask requires PHPUnit to be installed 错误。
更新 2
对我有用的解决方案是使用 PHPUnit 3.7.35。似乎 phing 与 PHPUnit 4.8 存在一些兼容性问题。
【问题讨论】:
-
使用 PHPUnit 3.7.35 解决了这个问题。来源 - stackoverflow.com/questions/23377750/phing-cant-see-phpunit/…