PHP developer living in Worthing, UK working for D3R. Starting Android / Java development for fun.
As per the comments for this post (I haven’t had the time to verify):
Paul Mitchell submitted a patch which solves the issue in the latest versions of Virtualbox Guest Additions – so please try upgrading.
If that doesn’t work, Theodore Smith suggests that adding this attribute and value to the phpunit tag in your xml configuration will solve the issue:
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
I’ve been fighting for two evenings trying to get PHPUnit working.
I have a setup where my LAMP stack runs in VirtualBox, in which I’ve mounted a folder shared with the virtual machine via Virtualboxes “shared folders” feature.
It seems that there’s a bug with DirectoryIterator; end result is it will point-blank refuse to iterate over files in your shared folder, and when you run your unit tests in the folder “Foo” with the command “phpunit Foo”:
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "FooTests.php" nor "FooTests.php" could be opened.' in /usr/share/php/PHPUnit/Util/Skeleton/Test.php:102
So. You’re going to have to do things the old fashioned way to fix this. Find PHPUnit_Runner_IncludePathTestCollecto (which uses File_Iterator and ultimately reliest on a RecursiveDirectoryIterator) and comment out the following:
/** * @return File_Iterator */ public function collectTests() { $iterator = File_Iterator_Factory::getFileIterator( $this->paths, $this->suffixes, $this->prefixes ); if ($this->filterIterator !== NULL) { $class = new ReflectionClass($this->filterIterator); $iterator = $class->newInstance($iterator); } return $iterator; }
In its place, insert this code – which does stuff the skanky old fashioned way:
public function collectTests() { $tests = array(); foreach ($this->paths as $path) { $tests = array_merge($tests, $this->_iterate($path)); } return $tests; } protected function _iterate($path) { $a = array(); if ($h = opendir($path)) { while (false !== ($fname = readdir($h))) { $fullPath = $path . '/' . $fname; if ($fname == '.' || $fname == '..') { continue; } if (is_dir($fullPath)) { $a = array_merge($a, $this->_iterate($fullPath)); continue; } foreach ((array) $this->suffixes as $sfx) { if (substr($fname, -strlen($sfx)) == $sfx) { $a[] = $fullPath; continue; } } foreach ((array) $this->prefixes as $pfx) { if (substr($fname, 0, strlen($pfx)) == $pfx) { $a[] = $fullPath; continue; } } } closedir($h); } return $a; }
Now “phpunit Foo” will correctly iterate through your Foo directory and test your stuff.
This does need revisiting but for now this quick fix seems to get least get things running.
Comments 8 Comments
If setting the loaderclass to PHPUnit_Runner_StandardTestSuiteLoader does cause PHPUnit to use a different strategy (ie, it doesn't use the file iterators), that sounds like the best fix if people are still having the problem. But even better is if guest additions behave properly, which apparently they do, so this whole post is a bit redundant..!
I'll put a note on the top of the post regarding this though - thanks both for taking the time to comment :)