【问题标题】:PHPUnit "Could not read phpunit.xml" on Travis CITravis CI 上的 PHPUnit“无法读取 phpunit.xml”
【发布时间】:2015-08-28 15:41:03
【问题描述】:

我在尝试在 Travis CI 上运行 PHP 单元测试时遇到了一个奇怪的问题。

.travis.yml

sudo: false
language: php
php:
  - 5.4

env:
  - VUFIND_HOME=$PWD VUFIND_LOCAL_DIR=$PWD/local

before_script:
  - pear install pear/PHP_CodeSniffer
  - pear channel-discover pear.phing.info
  - pear install phing/phing
  - composer global require fabpot/php-cs-fixer
  - export PATH="$HOME/.composer/vendor/bin:$PATH"
  - phpenv rehash

script:
  - phpunit --stderr --configuration module/VuFind/tests/phpunit.xml
  - phpunit --stderr --configuration module/Swissbib/tests/phpunit.xml
  - phpcs --standard=PEAR --ignore=*/config/*,*/tests/* --extensions=php $PWD/module
  - phing php-cs-fixer-dryrun

module/VuFind/tests/phpunit.xml是第三方框架

module/Swissbib/tests/phpunit.xml 是我们自己的代码

模块/Swissbib/tests/phpunit.xml

<phpunit bootstrap="Bootstrap.php">
    <testsuites>
        <testsuite name="sbvfrd">
            <directory>.</directory>
        </testsuite>
    </testsuites>
</phpunit>

来自第三方框架的测试运行没有错误。我们自己的测试不起作用,我们收到错误消息:

$ phpunit --stderr --configuration module/Swissbib/tests/phpunit.xml
Could not read "module/Swissbib/tests/phpunit.xml".

在本地 (Mac OS X) 运行所有测试。奇怪的是,module/Swissbib/tests/phpunit.xml 中定义的 Bootstrap.php 在 Travis CI 上完全运行,我使用 echo 语句验证了这一点。然而 phpunit 告诉我们它无法读取 phpunit.xml。

特拉维斯:https://travis-ci.org/swissbib/vufind

回购:https://github.com/swissbib/vufind(开发分支)

有什么想法可能会出错吗?

【问题讨论】:

    标签: php phpunit travis-ci


    【解决方案1】:

    我通过下载phpunit源码并用它调试找到了解决方案。

    我们将 Bootstrap.php 文件中的目录更改为不同的位置,然后运行 ​​phpunit 命令。我们从项目根文件夹运行 phpunit 命令,然后将工作目录更改为测试文件夹,因为我们使用的是相对路径。我将所有内容都更改为绝对路径(使用__DIR__),因此我们不必再更改工作目录了。

    底线:不要更改引导文件中的目录,因为它会导致 phpunit 失败并显示以下错误消息:无法读取 phpunit.xml。

    【讨论】:

    • 在 bootstrap.php 中使用 chdir 在我的情况下也是如此,感谢您的解决方案!
    猜你喜欢
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多