正如给出的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
to /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 之 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
Update
参考stackoverflow.com/a/23410676/351903,我尝试使用旧版本的Phpunit,即PHPUnit-3.7.35。现在,phpunit --version
命令有效。但是我使用Phing的PHPUnitTask仍然没有成功。还在得到PHPUnitTask requires PHPUnit to be installed
error.
Update 2
对我有用的解决方案是使用 PHPUnit 3.7.35。 phing 与 PHPUnit 4.8 似乎存在一些兼容性问题。