0

I'm having a problem with FuelPHP failing to autoload classes. On my staging server (Ubuntu, PHP 5.3.10) it is unable to find custom classes in the fuel/app/classes directory, and it also can't run oil test (I get the error message sh: 1: phpunit: not found). Oddly, it works fine on my local development version (Windows, PHP 5.3.6).

I suspected it might have something to do with Composer, which I'm using for the first time on this project, but the problem is not fixed when I comment out the line require APPPATH.'vendor/autoload.php'; from bootstrap.php (the app still fails to load custom classes from fuel/app/classes)

I'm stumped: I've used FuelPHP on lots of projects and have never had any problems with the Autoloader. What's particularly puzzling is that the same code seems to work fine in one place and not in another. I'd be very grateful for any suggestions about how to fix this.

Nick F
  • 9,781
  • 7
  • 75
  • 90
  • Can you find and post the autoloader code? – Machavity Oct 10 '13 at 16:48
  • I haven't touched the autoloader code, apart from adding that single line (requiring Composer's autoloader) to bootstrap.php. The autoloader is just FuelPHP 1.6's `core/classes/autoloader.php` (it's a big file, so I can't really post it here). – Nick F Oct 10 '13 at 16:52
  • Just for kicks, try putting your own autoloader in and see what happens. Be sure that FuelPHP isn't using the older __autoload() http://php.net/manual/en/function.spl-autoload-register.php – Machavity Oct 10 '13 at 18:01
  • No point posting it here, the repo is online on github. And your own autoloader won't work, unless you write a compatible one. Since it works locally, for all your other projects, and for thousands of others, the first question is: what is different on this server? – WanWizard Oct 10 '13 at 18:38
  • Since your local server is Windows: are all your filenames lowercase? Are the permissions on the files set correctly? – WanWizard Oct 10 '13 at 18:38
  • @WanWizard: good points. The filenames are not all lowercase, but: 1) some classes (eg. PHPUnit) are 3rd party, installed via Composer so filename casing is out of my hands; 2) another one is a file uploader (qqFileUploader) that I've used with no problem in other FuelPHP projects. As for permissions, I have the same problem if I `sudo php oil test` on the command line. – Nick F Oct 11 '13 at 10:18
  • Ok, follow up: I think it is to do with filename casing. I've changed the filenames of my custom classes to lower case and they seem to be working (d'oh!) However, Composer / PHPUnit's filenames are out of my hands, so I'm still not sure what to do there. – Nick F Oct 11 '13 at 10:46

1 Answers1

1

I realize this question was asked a long time ago, but I had the same problem, so for the benefit of anyone else with this problem, here is what worked for me:

create a new php file called oil.php in the app/config directory with the following code:

<?php

// Unit tests will get shell error 'phpunit: command not found' unless
//  the path to php unit is specified.
 return array (
     'phpunit' => array (
         'binary_path' => 'fuel/vendor/bin/phpunit',
     ),
 );

I am using fuel 1.7.2. More information can be found here.

Although the above code fixed the specific PHPunit problems, I still had issues with Fuel and autoloaders not working. Fuel PHP does not follow psr-4 (many of the core fuel files have multiple class definitions in the same file), which can cause problems with certain autoloaders.

turtlechief
  • 100
  • 1
  • 7