4

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ロードする を変更してみましたrequire_once '../../src/OAuth2/Authentication/Server.php';(つまり、実行中のファイルから 2 つ下のディレクトリ) が、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

server_test.php/tests のディレクトリの下で呼び出された両方のファイルが、それぞれServer.phpDatabase.phpファイルと /src の下のディレクトリからのファイルをロードしようとしています。

4

1 に答える 1

4

あなたのリポジトリから見たように、現在のディレクトリから関連リンクを使用してファイルが必要です。そのため、PHPUnit は、テストを配置したディレクトリと同じディレクトリで必要なファイルを見つけようとしますが、ファイルは見つかりません。PHPUnit 用の bootstrap.php ファイルの使用方法を変更または追加require_onceする必要があります。../../src/OAuth2/Resource/Server.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.h​​tml を参照してください

于 2013-01-02T21:54:55.933 に答える