Getting phpunit to work on Mac OS X macport installation


Background:
Mac OS X 10.9.1
macports 2.2.1

While I was setting up my PHP dev setup, i encountered a problem with phpunit

I was installing PHP 5.4 (php54)

$ port install php54 +pear
$ port install php54-unit

After installation I ran  php -v and shows php 5.4.17
running “whereis php” shows /usr/bin/php
which is the php comes with Mac OS X 10.9.1
so i created a symlink in /opt/local/bin called php and points to php54 in the same directory
in order to use the macport php54 when i call php
(oh by the way, i have /opt/local/bin in my PATH, and that is in preference of /usr/bin)

Once I got php installed, I created a new Laravel 4 project


$ composer.phar create-project laravel/laravel laravel-playground --prefer-dist

Then I attempted to run phpunit and surprisingly..


[nelson@hermes laravel-playground]$ phpunit
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 64

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /opt/local/lib/php/PHPUnit/Autoload.php on line 64
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.::/opt/local/lib/php/pear') in /opt/local/lib/php/PHPUnit/Autoload.php on line 64

Apparently phpunit has trouble finding its libraries.
made some Google searches and one forum post suggests changing include_path in php.ini

so here we go, edit /opt/local/etc/php54/php.ini (i copied the development config to start with)
add /opt/local/lib/php to include_path

;include_path = ".:/php/includes"
include_path = ".:/php/includes:/opt/local/lib/php"

and bang:

[nelson@hermes laravel-playground]$ phpunit
PHPUnit 3.7.22 by Sebastian Bergmann.

Configuration read from /Users/nelson/Sites/laravel-playground/phpunit.xml

.

Time: 0 seconds, Memory: 7.25Mb

OK (1 test, 1 assertion)

Leave a comment

Your email address will not be published. Required fields are marked *