Travis CI 上的 PHPUnit "Could not read phpunit.xml"

PHPUnit "Could not read phpunit.xml" on Travis CI

我在 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是我们自己的代码

module/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)所有测试运行通过。奇怪的是 Bootstrap.php 在 module/Swissbib/tests/phpunit.xml 运行 中定义完全通过 Travis CI,我使用 echo 语句验证了这一点。然而 phpunit 告诉我们它无法读取 phpunit.xml。

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

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

知道哪里出了问题吗?

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

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

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