I’m working on a side project which basically involves creating an extremely minimalistic MVC framework as part of a book/tutorial. I have just started, but already hit a snag with PHPUnit. Any test run that yields no errors work fine. This includes tests marked as skipped and incomplete. However, any test that fails normally (even a simple $this->fail() ) results in an exception being thrown:
PHPUnit 3.7.13 by Sebastian Bergmann.
..F
Time: 0 seconds, Memory: 2.00Mb
There was 1 failure:
1) Mfw\tests\validators\ValidatorTest::testCheckErrorSetUsingCreateMethod
Warning: require(C:\www\vendor\Mfw\tests/../../PHP\Invoker.php): failed to open stream: No such file or directory in C:\www\vendor\Mfw\Autoloader.php on line 32
Call Stack:
0.0017 124848 1. {main}() C:\xampp\php\phpunit:0
0.0182 360992 2. PHPUnit_TextUI_Command::main() C:\xampp\php\phpunit:46
0.0183 364200 3. PHPUnit_TextUI_Command->run() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
0.4605 1401976 4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
0.6824 1990912 5. PHPUnit_TextUI_ResultPrinter->printResult() C:\xampp\php\pear\PHPUnit\TextUI\TestRunner.php:352
0.6845 1991224 6. PHPUnit_TextUI_ResultPrinter->printFailures() C:\xampp\php\pear\PHPUnit\TextUI\ResultPrinter.php:163
0.6849 1991352 7. PHPUnit_TextUI_ResultPrinter->printDefects() C:\xampp\php\pear\PHPUnit\TextUI\ResultPrinter.php:307
0.6852 1991616 8. PHPUnit_TextUI_ResultPrinter->printDefect() C:\xampp\php\pear\PHPUnit\TextUI\ResultPrinter.php:225
0.6863 1991744 9. PHPUnit_TextUI_ResultPrinter->printDefectTrace() C:\xampp\php\pear\PHPUnit\TextUI\ResultPrinter.php:238
0.6957 2029296 10. PHPUnit_Util_Filter::getFilteredStacktrace() C:\xampp\php\pear\PHPUnit\TextUI\ResultPrinter.php:274
0.6964 2029560 11. PHPUnit_Util_GlobalState::phpunitFiles() C:\xampp\php\pear\PHPUnit\Util\Filter.php:76
6.1022 2205872 12. PHPUnit_Util_GlobalState::addDirectoryContainingClassToPHPUnitFilesList() C:\xampp\php\pear\PHPUnit\Util\GlobalState.php:388
6.1022 2205936 13. class_exists() C:\xampp\php\pear\PHPUnit\Util\GlobalState.php:409
6.1038 2206144 14. Mfw\Autoloader->autoload() C:\xampp\php\pear\PHPUnit\Util\GlobalState.php:0
Fatal error: require(): Failed opening required 'C:\www\vendor\Mfw\tests/../../PHP\Invoker.php' (include_path='.;C:\xampp\php\PEAR') in C:\www\vendor\Mfw\Autoloader.php on line 32
[ ... identical stack trace omitted ...]
I manually placed Invoker.php in the PEAR/PHP directory as it couldn’t find a release package through the installer. Still, it’s trying to locate it in my webroot to begin with. I’m suspecting that my autoloader may be involved, but i’m not sure if so, and how. Here it is, copied nearly 1-on-1 from the PRS-0 fig-standard:
<?php
namespace Mfw;
class Autoloader
{
protected $vendorDir = '';
public function __construct($vendorDir)
{
if (!is_string($vendorDir) || !is_dir($vendorDir)) {
throw new \InvalidArgumentException(
'Autoloader must be supplied a string with the vendor directory'
);
}
$this->vendorDir = rtrim($vendorDir, '/');
}
public function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace)
. DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
require $this->vendorDir . '/' . $fileName;
}
}
Anyone dare hazard a guess what might be going on any suggestion whatsoever? Thanks!