unit-testinginstallationphpunitautoloadset-include-path

Dealing with PHPUnit path issues


I am getting the following error when I try to run PHPUnit from within my current MVC framework application

Fatal error: Cannot redeclare class PHPUnit_Util_FilterIterator in /usr/local/pear/PHPUnit/Util/FilterIterator.php on line 162

I've managed to trace that error to a combination of a few things.

$paths = array();
$paths[] = '../m';
$paths[] = '../v';
$paths[] = '../c';
$paths[] = '/usr/local/pear';
set_include_path(implode(PATH_SEPARATOR, $paths));

When I comment out

    set_include_path(implode(PATH_SEPARATOR, $paths));

PHPUnit runs tests

when I comment out

$paths[] = '/usr/local/pear';

I get

Fatal error: require_once(): Failed opening required 'PHPUnit/Framework/TestCase.php' 

If I comment out every other directory, save for the

$paths[] = '/usr/local/pear';

I get the "cannot redeclare" error.

The only way that I can get to run actual tests is if I run without the set_include_path statement and manually include all the class files that are called by any individual unit test.

Any ideas?

EDIT: it appears there's a conflict with the __autoload function. I'm still not quite sure how to address the issue.


Solution

  • well as it turns out, I have no idea why this actually works ... but since it does, I'll post the result.

    $paths[] = get_include_path();
    $paths[] = '../m';
    $paths[] = '../v';
    $paths[] = '../c';
    set_include_path(implode(PATH_SEPARATOR, $paths));
    

    So there you go. Well at least, there you go in the case that you've actually got this problem too :)