PHPUnit stumps…

PHPUnit 3.0.6 (with PHP 5.2.2) can’t even load a file!

$ phpunit UnitTest
X-Powered-By: PHP/5.2.2
Content-type: text/html

PHPUnit 3.0.6 by Sebastian Bergmann.

File “UnitTest.php” could not be found or is not readable.

Let’s see where it looks for my (definitely existing and readable) UnitTest.php. Add a quick debug printout starting with KS: into /usr/local/lib/php/PHPUnit/Util/Fileloader.php:

$ phpunit UnitTest
X-Powered-By: PHP/5.2.2
Content-type: text/html

KS: wd=/usr/local/bin, filename=UnitTest.php
PHPUnit 3.0.6 by Sebastian Bergmann.

File “UnitTest.php” could not be found or is not readable.

What’s that?… I don’t believe my eyes. Does it really look for input ini /usr/local/bin?

$ sudo touch /usr/local/bin/UnitTest
$ phpunit UnitTest
X-Powered-By: PHP/5.2.2
Content-type: text/html

KS: wd=/usr/local/bin, filename=UnitTest.php
PHPUnit 3.0.6 by Sebastian Bergmann.

Class UnitTest could not be found in UnitTest.php.

I’m not absolutely alone with this, there is a recent post (18.6.2007) complaining about the same issue. Maybe this is a new bug in PHPUnit? Let’s try the latest beta release of phpunit from http://pear.phpunit.de/get/, installing manually as said in phpunit manual section:

$ phpunit UnitTest
X-Powered-By: PHP/5.2.2
Content-type: text/html

PHPUnit 3.1.0beta4 by Sebastian Bergmann.

File "UnitTest.php" could not be found or is not readable.

OK, quotes are replaced with ", but the file is still not found. What else could be done? Rollback to a previous version, phpinit 3.0.5. Alas - result is the same!

Update: This misfortune is experienced on RedHat Enterprise Linux 5. On Ubuntu Feisty, PHPUnit works out of the box. So this is likely an installation problem, not a problem of PHPUnit. Aha! I had some old PHP on RHEL machine, and installed newer version in /usr/local. Let’s revert back to the stock PHP:

$ phpunit UnitTest
PHP Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 40
PHP Fatal error: require_once(): Failed opening required ‘PHPUnit/Util/Filter.php’ (include_path=’.:/usr/share/pear’) in /usr/local/bin/phpunit on line 40

Now even PHPUnit is not found; let’s see with strace where the PHP is looking for it:

$ strace -f phpunit UnitTest | grep Filter.php
4471 open(”/my/current/work/dir/PHPUnit/Util/Filter.php”, O_RDONLY) = -1 ENOENT (No such file or directory)
4471 open(”/usr/share/pear/PHPUnit/Util/Filter.php”, O_RDONLY) = -1 ENOENT (No such file or directory)
4471 open(”/usr/local/bin/PHPUnit/Util/Filter.php”, O_RDONLY) = -1 ENOENT (No such file or directory)

But my PHPUnit was installed by pear in /usr/local/lib/php. This directory is not searched by default. We have to add include_path = /usr/local/lib/php statement into the php.ini, used by the PHP installation. After that, the script subject to test is not any longer searched in /usr/local/bin, and my long-awaited test finally works.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
OpenID URL
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.