【问题标题】:Unable to globally install older version of phpunit phar无法全局安装旧版本的 phpunit phar
【发布时间】: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 存在一些兼容性问题。

【问题讨论】:

标签: php phpunit phing


【解决方案1】:

对我有用的解决方案是使用 PHPUnit 3.7.35。似乎 phing 与 PHPUnit 4.8 存在一些兼容性问题。

来源 - Phing can't see PHPUnit

【讨论】:

    【解决方案2】:

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

    $ 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.
    

    【讨论】:

    • 我也可以运行php phpunit-old.phar --version,但无法运行phpunit --version
    • 参考stackoverflow.com/a/23410676/351903,我想试试这个旧版本的Phpunit,即PHPUnit-3.7.35。它的 phar 包的下载地址是什么?
    • 您可以在phar.phpunit.de 上找到所有已发布的PHPUnit PHAR。例如,PHPUnit 3.7.35 位于 phar.phpunit.de/phpunit-3.7.35.phar
    • 谢谢。仅供参考,phpunit --version 命令适用于这个旧版本。但是我仍然没有成功使用 Phing 的 PHPUnitTask。仍然收到PHPUnitTask requires PHPUnit to be installed 错误。
    • 更正 - 使用 PHPUnit 3.7.35 解决了这个问题。上次我有一个不正确的观察 - “仍然得到 PHPUnitTask 需要安装 PHPUnit 错误”。
    【解决方案3】:

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

    可能你的 PHP 版本和你下载的 PHPUnit 版本不兼容?

    【讨论】:

    • 我的 PHP 版本是 5.3.29。 phpunit.de 中的旧稳定版本部分说 PHPUnit 4.8 在 PHP 5.3、PHP 5.4、PHP 5.5 和 PHP 5.6 上受支持。
    • 您的 loading/require 语句似乎有问题。如果有的话,能给我们看看你的 phpunit.xml 文件吗?
    猜你喜欢
    • 2016-05-31
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 2010-12-06
    • 1970-01-01
    相关资源
    最近更新 更多