【问题标题】:Phing can't see PHPUnitPhing 看不到 PHPUnit
【发布时间】:2014-08-12 15:16:08
【问题描述】:

我正在尝试设置一个新的持续集成服务器,该服务器利用 Phing 和 PHPUnit 自动运行测试用例。

我已经用 Pear 安装了 Phing:

pear channel-discover pear.phing.info
pear install phing/phing

我已经使用新的 PHAR 方法安装了 PHPUnit:

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

然后我转到我的 build.xml 文件所在的目录,运行 phing,看起来 Phing 不知道 PHPUnit 在哪里。

[jenkins@leroy workspace]$ phing
Buildfile: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml

Framework > test:

 [echo] Running Tests
Execution of target "test" failed for the following reason: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: /home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: PHPUnitTask requires PHPUnit to be installed

BUILD FAILED
/home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37:
/home/jenkins/.jenkins/jobs/Framework/workspace/build.xml:9:37: PHPUnitTask requires PHPUnit to be installed
Total time: 0.0764 seconds

[jenkins@leroy workspace]$

检查了 Phing 和 PHPUnit 的位置:

[jenkins@leroy workspace]$ which phing
/usr/bin/phing
[jenkins@leroy workspace]$ which phpunit
/usr/local/bin/phpunit

并且,确保 PHP 足够新:

[jenkins@leroy workspace]$ php -v
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57) 

我正在做这一切,因为我们正在用这个新服务器替换旧的 Jenkins 服务器。尝试使用最新的软件,但我不知道如何告诉 Phing 在哪里可以找到 PHPUnit。

提前感谢您的帮助!

大卫

【问题讨论】:

    标签: php jenkins phpunit phing


    【解决方案1】:

    似乎将pharlocation 属性添加到phpunit 任务元素,指向您本地的phpunit 可执行文件,就可以完成这项工作:

    <phpunit haltonfailure="true" haltonerror="true" 
        bootstrap="./fw_init.php" 
        pharlocation="/usr/local/bin/phpunit">
            <formatter type="plain" usefile="false" />
            ...
    </phpunit>
    

    【讨论】:

    • 我的测试在尝试require 'PHPUnit/Framework/TestCase.php' 时失败,因为此文件不在包含路径中。你是怎么解决的?
    • 我试过了,但还是不行。我的问题有一个悬赏stackoverflow.com/questions/36405597/…
    【解决方案2】:

    phing 和 PHPUnit 的最新 4.x 版本似乎存在一些实际问题:http://www.phing.info/trac/ticket/1091

    为了解决这个问题,我删除了 PHPUnit 4 并指定了一个旧版本:

    pear install phpunit/PHPUnit-3.7.35
    

    Phing 和 PHPUnit 在这一点上立即工作。

    【讨论】:

    • 我很好奇,如果他们一年前暂停了这个频道,你是如何通过 PEAR 安装 PHPUnit 的:pear.phpunit.de 请分享你所知道的 :)
    • 你能帮帮我吗?我的问题有一个悬赏stackoverflow.com/questions/36405597/…
    • 正如yegor256所指出的,pear安装将不起作用。可以完成phar的安装。您可以在 phar.phpunit.de 上找到所有以 PHAR 形式发布的 PHPUnit。例如,PHPUnit 3.7.35 位于 phar.phpunit.de/phpunit-3.7.35.phar。
    【解决方案3】:

    这是一个有着完全相同问题的人:How do I tell Phing where PHPUnit is installed?

    他的理论是:

    这台机器上的 PHP 版本可能太旧,无法处理 PHAR 档案

    我无法评论他是否正确,但该问题没有收到除作者以外的任何人的回复

    【讨论】:

    • 是的,我读过这个问题,这就是为什么我在原始问题中包含我的 PHP 版本。 PHAR 要求最低版本为 5.3.3,所以我认为这不是我的问题。
    • 你能帮帮我吗?我的问题有一个悬赏stackoverflow.com/questions/36405597/…
    【解决方案4】:

    也许是一个愚蠢的评论,但你的 PHP 包含路径中有 /usr/local/bin/phpunit 吗?

    当我从包含路径中删除 phpunit.phar 的位置时,我得到了同样的错误。

    【讨论】:

    猜你喜欢
    • 2016-04-08
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2013-05-24
    • 2020-08-10
    • 2017-08-05
    相关资源
    最近更新 更多