Travis-CI: Class not found even when using autoloader

891 views Asked by At

Im kind of new with Travis, and I am expreimenting with it right now. I uploaded have my PHP Project on Github and when I let it test via Travis it fails and gives me this error.

PHP Fatal error:  Class 'controllers\Welcome' not found in /home/travis/build/ezylot/PHPSkeleton/tests/controllers/welcomeTest.php on line 4

I use a autoloader to load the classes, and it is no problem on my local machine. I include the autoloader in bootsrap.php with the bootstrap in the PHPUnit Konfiguration-XML File.

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

There are 2 answers

0
Mika Tuupola On BEST ANSWER

You are most likely developing on OSX which has case insensitive filesystem and tests pass. Travis uses case sensitive file system. Try renaming app/controllers/welcome.php to app/controllers/Welcome.php.

In general it is good idea to follow PSR-1 standard to avoid autoloading issues.

1
piersb On

I had a short php open tag at the top of the class file.

<? 

as opposed to

<?php

This broke it on the remote, but not on my local. Which is weird, because I would've expected it to break locally too.

Putting this out there in case someone else is in the same odd situation.