A few days ago I set up PHPUnit on my OS X using MAMP’s pear. Everything seemed to be set up properly except I kept getting this weird issue anytime I ran phpunit, I would get the following:

specs/ (dev) $ phpunit .
specs/ (dev) $ echo $?
255

No errors output, and phpunit is returning code 255. It took me forever to figure out what this meant and none of the search results in google were helping either. I finally realized the issue today.

PHPUnit was encountering a php error. While I thought I had error_reporting enabled in my php.ini. A few days later, I realized I had display_errors set to Off. If you want to see what’s going on you have to set display_errors to On.

Now I am getting more meaningful output (truncated):

Warning: require_once(PHPUnit/Framework.php): failed to open stream: No such file or directory

Fatal error: require_once(): Failed opening required 'PHPUnit/Framework.php' (include_path='.:/Applications/MAMP/bin/php/php5.2.17/lib/php/PHPUnit:/Applications/MAMP/bin/php/php5.2.17/lib/php:/Users/gmcquillan/Sites/ZendFramework-1.10.6/library/')

Which I thought meant it’s not finding my PHPUnit library in my php include path. I tried finagling with my include_path for quite a while.

According to the output it was searching in the right spot, but still not coming up for some reason. I eventually figured out that the cause of this issue was a require_once statement that I had at the top of my unit test code file:

require_once 'PHPUnit/Framework.php';

When I looked in my PHPUnit directory I noticed this file did not exist, so it must have been a difference between the version of PHPUnit I was using previously and the current version.

Here are some quick wins to help you solve your issue:

  1. Check display_errors in php.ini (In MAMP 2.0.5 that’s in /Applications/MAMP/bin/php/php5.2.17/conf/php.ini and of course if you’re using php 5.3 you should be editing the one in your php5.3 directory
  2. Check the error_reporting in php.ini

Once you are able to see the error message output, the problem should be very clear. When changing php.ini the cli php will see changes immediately (unlike apache where you will have to restart the server for changes to take effect)


blog comments powered by Disqus

Published

27 February 2012

Tags