【问题标题】:PHPUnit fails on Travis-CI but passes locallyPHPUnit 在 Travis-CI 上失败,但在本地通过
【发布时间】:2012-12-17 06:09:07
【问题描述】:

当 PHPUnit 在我的本地机器上正常工作时,我在让 PHPUnit 在 Travis-CI 上工作时遇到了一些麻烦。我使用的是相同的 PHP 版本和 PHPUnit 版本。

我的代码库位于https://github.com/lncd/OAuth2
Travis-CI 输出在https://travis-ci.org/lncd/OAuth2

从存储库的根目录执行phpunit -c build/phpunit.xml 可以在本地正常运行,并且测试按预期执行。

Travis 的日志是:

$ cd ~/builds
$ git clone --branch=develop --depth=100 --quiet git://github.com/lncd/OAuth2.git lncd/OAuth2
$ cd lncd/OAuth2
$ git checkout -qf 1c3b319aa6c8f5521d5123f0e6affca94ee35010
$ phpenv global 5.3
$ php --version
PHP 5.3.19 (cli) (built: Dec 20 2012 09:57:38) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
$ phpunit -c build/phpunit.xml
PHP Warning:  require_once(src/OAuth2/Authentication/Server.php): failed to open stream: No such file or directory in /home/travis/builds/lncd/OAuth2/tests/authentication/server_test.php on line 3
PHP Stack trace:
PHP   1. {main}() /home/travis/.phpenv/versions/5.3.19/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/travis/.phpenv/versions/5.3.19/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_Command->handleArguments() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/TextUI/Command.php:138
PHP   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/TextUI/Command.php:657
PHP   6. PHPUnit_Util_Configuration->getTestSuite() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Util/Configuration.php:784
PHP   7. PHPUnit_Framework_TestSuite->addTestFiles() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Util/Configuration.php:860
PHP   8. PHPUnit_Framework_TestSuite->addTestFile() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Framework/TestSuite.php:416
PHP   9. PHPUnit_Util_Fileloader::checkAndLoad() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Framework/TestSuite.php:355
PHP  10. PHPUnit_Util_Fileloader::load() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Util/Fileloader.php:76
PHP  11. include_once() /home/travis/.phpenv/versions/5.3.19/share/pyrus/.pear/php/PHPUnit/Util/Fileloader.php:92

我已经尝试将 require_once 更改为 loadrequire_once '../../src/OAuth2/Authentication/Server.php';(即执行文件的两个目录),但这不适用于 Travis 或我的本地设置。

我做错了什么?还是 Travis 的错误?

谢谢


编辑:

为了澄清这是目录结构:

build
    /phpunit.xml
src
    /OAuth2
        /Authentication
            /Database.php
            /Server.php
        /Resource
            /Database.php
            /Server.php
tests
    /authentication
        /database_mock.php
        /server_test.php
    /resource
        /database_mock.php
        /server_test.php

/tests 目录下名为 server_test.php 的两个文件都试图从 /src 目录下加载各自的 Server.phpDatabase.php 文件

【问题讨论】:

  • var_dump(getcwd(), get_include_path());
  • getcwd:/home/travis/builds/lncd/OAuth2 include path:.:/home/travis/.phpenv/versions/5.3.19/pear:/home/travis/。 phpenv/versions/5.3.19/share/pyrus/.pear/php __FILE__: /home/travis/builds/lncd/OAuth2/tests/authentication/server_test.php __DIR__: /home/travis/builds/lncd /OAuth2/tests/认证
  • 看起来你没有安装所有要求。
  • 虽然这是用 ruby​​ 编写的,但它适用于 php:ruby-journal.com/debug-your-failed-test-in-travis-ci
  • @IgorTimoshenko 我刚刚注意到我没有运行composer install,所以我已将其添加到.travis.yml 文件中,尽管没有任何测试依赖于其中的代码 - 仍然是最新版本失败travis-ci.org/lncd/OAuth2/builds/3923096

标签: php phpunit travis-ci


【解决方案1】:

正如我从您的存储库中看到的,您需要通过当前目录中的相关链接使用文件。因此,PHPUnit 尝试在您放置测试的同一目录中查找所需文件,但未找到任何文件。您需要将 require_once 的用法更改为 ../../src/OAuth2/Resource/Server.php 或为 PHPUnit 添加 bootstrap.php 文件。

下面我复制粘贴了我在 PHPUnit 和 Composer 中使用的 bootstrap.php 文件:

<?php
if (!@include __DIR__ . '/../vendor/autoload.php') {
    die('You must set up the project dependencies, run the following commands:
        wget http://getcomposer.org/composer.phar
        php composer.phar install');
}

您可以在此处找到有关 bootstrap.php 文件的更多信息:http://www.phpunit.de/manual/current/en/textui.html

【讨论】:

  • 我已经尝试过了 - travis-ci.org/lncd/OAuth2/jobs/3922238 - 在 Travis 上仍然损坏,现在在本地损坏
  • 尝试添加 bootstrap.php 文件。在测试中使用require 不是一个好方法。
  • 谢谢,我误解了你的提议。它现在正在工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-31
相关资源
最近更新 更多