如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中的Old Stable Release部分说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集成。我想使用phing的PHPUnitTask提供的基本实用程序。所以,我想它需要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.de网站下载了您提供的旧PHPUnit文件,并成功地应用了您编写的命令。在我的情况下,运行phpunit就像一种魅力。
也许你的PHP版本和你下载的PHPUnit版本不兼容?
我无法重现您描述的问题:
$ wget https://phar.phpunit.de/phpunit-old.phar
--2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-old.phar
Resolving phar.phpunit.de (phar.phpunit.de)... 188.94.27.25
Connecting to phar.phpunit.de (phar.phpunit.de)|188.94.27.25|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://phar.phpunit.de/phpunit-4.8.24.phar [following]
--2016-04-07 09:47:35-- https://phar.phpunit.de/phpunit-4.8.24.phar
Reusing existing connection to phar.phpunit.de:443.
HTTP request sent, awaiting response... 200 OK
Length: 3086772 (2.9M) [application/octet-stream]
Saving to: ‘phpunit-old.phar’
phpunit-old.phar 100%[=====================================================================================================================================>] 2.94M 3.97MB/s in 0.7s
2016-04-07 09:47:36 (3.97 MB/s) - ‘phpunit-old.phar’ saved [3086772/3086772]
$ php phpunit-old.phar --version
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.
对我有效的解决方案是使用PHPUnit 3.7.35。看来phing与PHPUnit 4.8之间存在一些兼容性问题。
来源-钓鱼可以';t参见PHPUnit