4

I'm having some trouble getting PHPUnit to work on Travis-CI when it works fine on my local machine. I'm using the same PHP version and PHPUnit version.

My codebase is at https://github.com/lncd/OAuth2
Travis-CI output is at https://travis-ci.org/lncd/OAuth2

Executing phpunit -c build/phpunit.xml from the root of the repository works fine locally and tests execute as expected.

The log for Travis is:

$ 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

I've played around with altering the require_once to loadrequire_once '../../src/OAuth2/Authentication/Server.php'; (i.e. two directories down from the executing file) but that doesn't work on Travis or my local setup.

What am I doing wrong? Or is it a bug with Travis?

Thank you


EDIT:

To clarify this is the directory structure:

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

Both files called server_test.php under directories in /tests are trying to load respective Server.php and Database.php files from directories under /src

7
  • var_dump(getcwd(), get_include_path()); Commented Jan 2, 2013 at 21:28
  • 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/authentication Commented Jan 2, 2013 at 21:29
  • It looks like you are not installed all requirements. Commented Jan 2, 2013 at 21:29
  • 1
    Although this was written with ruby in mind, it is applicable for php: ruby-journal.com/debug-your-failed-test-in-travis-ci Commented Jan 2, 2013 at 21:31
  • @IgorTimoshenko I've just noticed I wasn't running composer install so I've added that to the .travis.yml file, regardless none of the tests rely on code from that - latest build still failed travis-ci.org/lncd/OAuth2/builds/3923096 Commented Jan 2, 2013 at 21:33

1 Answer 1

4

As I saw from your repository, you are required files using by related link from the current directory. So, PHPUnit tries to find required files in the same directory where you put tests and does not find any files. You need to change usage of require_once to ../../src/OAuth2/Resource/Server.php or add bootstrap.php file for PHPUnit.

Below I copy-pasted my bootstrap.php file that I use with PHPUnit and Composer:

<?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');
}

More information about bootstrap.php file you can find here: http://www.phpunit.de/manual/current/en/textui.html.

Sign up to request clarification or add additional context in comments.

3 Comments

I've tried that already - travis-ci.org/lncd/OAuth2/jobs/3922238 - still broken on Travis and now broken locally
Try to add bootstrap.php file. Using require in tests is not a good approach.
Thank you, I misunderstood what you were proposing. It's working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.