Skip to content
Browse files

clean up testing situation, add path tracking for debug info

  • Loading branch information...
1 parent 2ba0799 commit e4c60e0d860c61a81b17ab8a0b34fc5232a8a0ac @pmjones pmjones committed Dec 29, 2011
View
2 config/default.php
@@ -2,4 +2,4 @@
/**
* Package prefix for autoloader.
*/
-$loader->addPrefix('Aura\Autoload\\', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src');
+$loader->add('Aura\Autoload\\', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src');
View
2 config/test.php
@@ -2,4 +2,4 @@
/**
* Package prefix for autoloader.
*/
-$loader->addPrefix('Aura\Autoload\\', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tests');
+$loader->add('Aura\Autoload\\', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'tests');
View
41 src/Aura/Autoload/Loader.php
@@ -83,6 +83,8 @@ class Loader
*/
protected $mode = self::MODE_NORMAL;
+ protected $tried_paths;
+
/**
*
* Sets the autoloader operational mode.
@@ -298,7 +300,9 @@ public function load($spec)
return;
} else {
// yes, throw an exception
- throw new Exception\NotFound($spec);
+ $message = $spec . PHP_EOL
+ . implode(PHP_EOL, $this->tried_paths);
+ throw new Exception\NotFound($message);
}
}
@@ -321,7 +325,16 @@ public function load($spec)
$this->loaded[$spec] = $file;
}
- public function isDeclared($spec)
+ /**
+ *
+ * Tells if a class or interface exists.
+ *
+ * @param string $spec The class or interface.
+ *
+ * @return bool
+ *
+ */
+ protected function isDeclared($spec)
{
return class_exists($spec, false)
|| interface_exists($spec, false);
@@ -344,6 +357,8 @@ public function find($spec)
return $this->classes[$spec];
}
+ $this->tried_paths = array();
+
// go through each of the path prefixes
foreach ($this->paths as $prefix => $paths) {
@@ -360,7 +375,10 @@ public function find($spec)
$ctf = $this->classToFile($spec);
// ... and go through each of the paths for the prefix
- foreach ($paths as $path) {
+ foreach ($paths as $i => $path) {
+
+ // track which paths we have tried
+ $this->tried_paths[] = "#{$i}: {$path}";
// convert the remaining spec to a file name
$file = $path . DIRECTORY_SEPARATOR . $ctf;
@@ -373,26 +391,13 @@ public function find($spec)
}
}
- // fall back to the include-path
- return $this->findInclude($spec);
- }
-
- /**
- *
- * Finds a class in the include-path.
- *
- * @param string $spec The class or interface to find.
- *
- * @return mixed The path to the file, or false if not found.
- *
- */
- protected function findInclude($spec)
- {
// fall back to the include path
$file = $this->classToFile($spec);
try {
$obj = new \SplFileObject($file, 'r', true);
} catch (\RuntimeException $e) {
+ $k = count($this->tried_paths);
+ $this->tried_paths[] = "#{$k}" . get_include_path();
return false;
}
$path = $obj->getRealPath();
View
3 tests/Aura/Autoload/Bar/MockAutoloadRouterClass.php
@@ -0,0 +1,3 @@
+<?php
+namespace Aura\Autoload\Bar;
+class MockAutoloadRouterClass {}
View
3 tests/Aura/Autoload/Foo/MockAutoloadCliClass.php
@@ -0,0 +1,3 @@
+<?php
+namespace Aura\Autoload\Foo;
+class MockAutoloadCliClass {}
View
12 tests/Aura/Autoload/LoaderTest.php
@@ -233,12 +233,12 @@ public function testSetClasses()
public function testSetPaths()
{
- $class1 = 'Aura\Cli\MockAutoloadCliClass';
- $class2 = 'Aura\Router\MockAutoloadRouterClass';
+ $class1 = 'Aura\Autoload\Foo\MockAutoloadCliClass';
+ $class2 = 'Aura\Autoload\Bar\MockAutoloadRouterClass';
$autoloader = new Loader;
$autoloader->setPaths(array(
- 'Aura\Cli\\', dirname(dirname(__DIR__)),
- 'Aura\Router\\', dirname(dirname(__DIR__))
+ 'Aura\Autoload\Foo\\' => dirname(dirname(__DIR__)),
+ 'Aura\Autoload\Bar\\' => dirname(dirname(__DIR__))
));
$autoloader->load($class1);
$autoloader->load($class2);
@@ -249,8 +249,8 @@ public function testSetPaths()
$this->assertSame($class1, $actual);
$expect = array(
- $class1 => dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'Aura/Cli/MockAutoloadCliClass.php',
- $class2 => dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'Aura/Router/MockAutoloadRouterClass.php',
+ $class1 => dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'Aura/Autoload/Foo/MockAutoloadCliClass.php',
+ $class2 => dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'Aura/Autoload/Bar/MockAutoloadRouterClass.php',
);
$actual = $autoloader->getLoaded();
View
3 tests/Aura/Cli/MockAutoloadCliClass.php
@@ -1,3 +0,0 @@
-<?php
-namespace Aura\Cli;
-class MockAutoloadCliClass {}
View
3 tests/Aura/Router/MockAutoloadRouterClass.php
@@ -1,3 +0,0 @@
-<?php
-namespace Aura\Router;
-class MockAutoloadRouterClass {}

0 comments on commit e4c60e0

Please sign in to comment.
Something went wrong with that request. Please try again.