无法全局安装旧版本的phpunit phar

时间:2016-04-04 14:34:42

标签: php phpunit phing

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部分表示PHP 5.3,PHP 5.4,PHP 5.5和PHP 5.6支持PHPUnit 4.8。

看起来很好,直到这里。但是,运行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。看来PHP与PHPUnit 4.8有一些兼容性问题。

3 个答案:

答案 0 :(得分:0)

我刚刚下载了您从phpunit.de网站提供的旧PHPUnit文件,并成功应用了您编写的命令。在我的案例中,运行phpunit就像一个魅力。

您的PHP版本与下载的PHPUnit版本之间可能存在不兼容性吗?

答案 1 :(得分:0)

我无法重现您描述的问题:

textureFilename

答案 2 :(得分:-1)

对我有用的解决方案是使用PHPUnit 3.7.35。看来PHP与PHPUnit 4.8有一些兼容性问题。

来源 - Phing can't see PHPUnit