PHPUnit“无法读取phpunit.xml”在Travis CI上
问题描述:
我在尝试在Travis CI上运行PHP单元测试时遇到一个奇怪的问题。PHPUnit“无法读取phpunit.xml”在Travis CI上
.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
模块/ VuFind /测试/ phpunit.xml是第三方框架
模块/ Swissbib /测试/ phpunit.xml是我们自己的代码
模块/ Swissbib /测试/ 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)所有测试都运行完毕。奇怪的是,模块/ Swissbib/tests/phpunit.xml中定义的Bootstrap.php完全通过Travis CI运行,我使用echo语句验证了这一点。尽管如此,phpunit告诉我们它无法读取phpunit.xml。
特拉维斯:https://travis-ci.org/swissbib/vufind
回购:https://github.com/swissbib/vufind(开发分支)
任何想法可能是想错了?
答
我通过下载phpunit源代码并用它进行调试,找到了解决方案。
我们将Bootstrap.php文件中的目录更改为不同的位置,然后运行phpunit命令。我们从项目根文件夹运行phpunit命令,然后将工作目录更改为tests文件夹,因为我们使用的是相对路径。我将所有内容都改为绝对路径,因此我们不必再更改工作目录。
底线:不要更改引导文件中的目录,因为它会导致phpunit失败,并显示以下错误消息:无法读取phpunit.xml。