From 7e1a098f6cd8a5dcfc8fc7451508dc5f96ed00b5 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 2 Sep 2013 22:07:38 -0700 Subject: [PATCH] Autoloader should not throw exceptions. --- flight/core/Loader.php | 7 ------- tests/AutoloadTest.php | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/flight/core/Loader.php b/flight/core/Loader.php index dea5e3b..3b509db 100644 --- a/flight/core/Loader.php +++ b/flight/core/Loader.php @@ -175,13 +175,6 @@ class Loader { return; } } - - // Allow other autoloaders to run before raising an error - $loaders = spl_autoload_functions(); - $loader = array_pop($loaders); - if (is_array($loader) && $loader[0] == __CLASS__ && $loader[1] == __FUNCTION__) { - throw new \Exception('Unable to load file: '.$class_file); - } } /** diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index 4735bbd..7aab378 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -18,12 +18,11 @@ class AutoloadTest extends PHPUnit_Framework_TestCase function setUp() { $this->app = new \flight\Engine(); + $this->app->path(__DIR__.'/classes'); } // Autoload a class function testAutoload(){ - $this->app->path(__DIR__.'/classes'); - $this->app->register('test', 'TestClass'); $loaders = spl_autoload_functions(); @@ -34,4 +33,16 @@ class AutoloadTest extends PHPUnit_Framework_TestCase $this->assertTrue(is_object($test)); $this->assertEquals('TestClass', get_class($test)); } + + // Check autoload failure + function testMissingClass(){ + $test = null; + $this->app->register('test', 'NonExistentClass'); + + if (class_exists('NonExistentClass')) { + $test = $this->app->test(); + } + + $this->assertEquals(null, $test); + } }