2013-01-02 53 views
4

我在使用Travis-CI時遇到了一些麻煩,當它在我的本地計算機上正常工作時。我正在使用相同的PHP版本和PHPUnit版本。PHPUnit在Travis-CI上失敗,但在本地通過

我的代碼庫是https://github.com/lncd/OAuth2
特拉維斯-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';(即兩個目錄的執行文件下)玩耍了,但這並不對特拉維斯或我的地方工作建立。

我在做什麼錯?或者它是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下的目錄要加載相應的來自/ src下目錄的Server.phpDatabase.php文件

+0

'的var_dump(GETCWD(),get_include_path());'' – zerkms

+0

getcwd':/家庭/特拉維斯/建立/ lncd/OAuth2用戶 '包括path':/家庭/特拉維斯/ .phpenv /版本/ 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/authentication – alexbilbie

+0

看起來您並未安裝所有要求。 –

回答

4

正如我從您的存儲庫中看到的,您需要通過當前目錄中相關鏈接使用的文件。因此,PHPUnit會嘗試在放置測試的相同目錄中查找所需的文件,並且找不到任何文件。您需要將require_once的使用更改爲../../src/OAuth2/Resource/Server.php或爲PHPUnit添加bootstrap.php文件。

下面我複製粘貼,我使用PHPUnit和作曲家用我的bootstrap.php文件:http://www.phpunit.de/manual/current/en/textui.html:約bootstrap.php中的文件,你可以在這裏找到

<?php 
if ([email protected] __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'); 
} 

更多信息。

+0

我已經嘗試過 - https://travis-ci.org/lncd/OAuth2/jobs/3922238 - 仍然損壞在Travis上,現在在本地破解 – alexbilbie

+0

嘗試添加bootstrap.php文件。在測試中使用'require'不是一個好方法。 –

+0

謝謝,我誤解了你的建議。現在正在工作。 – alexbilbie

相關問題