Browse Source

[ZF-9721] Zend_Loader:

- correction of the condition (if).

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22603 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 years ago
parent
commit
786d630ce1
2 changed files with 19 additions and 3 deletions
  1. 1 1
      library/Zend/Loader/PluginLoader.php
  2. 18 2
      tests/Zend/Loader/PluginLoaderTest.php

+ 1 - 1
library/Zend/Loader/PluginLoader.php

@@ -256,7 +256,7 @@ class Zend_Loader_PluginLoader implements Zend_Loader_PluginLoader_Interface
 
         if ($path != null) {
             $pos = array_search($path, $registry[$prefix]);
-            if ($pos === null) {
+            if (false === $pos) {
                 require_once 'Zend/Loader/PluginLoader/Exception.php';
                 throw new Zend_Loader_PluginLoader_Exception('Prefix ' . $prefix . ' / Path ' . $path . ' was not found in the PluginLoader.');
             }

+ 18 - 2
tests/Zend/Loader/PluginLoaderTest.php

@@ -464,7 +464,7 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         require_once 'Zend/View/Helper/DeclareVars.php';
         $reflection = new ReflectionClass('Zend_View_Helper_DeclareVars');
         $expected   = $reflection->getFileName();
-        
+
         $loader = new Zend_Loader_PluginLoader(array());
         $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
         $loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
@@ -475,7 +475,7 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
             $paths = $loader->getPaths();
             $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
         }
-        
+
         $classPath = $loader->getClassPath('DeclareVars');
         $this->assertContains($expected, $classPath);
     }
@@ -500,6 +500,22 @@ class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('Zfns\\Foo', $className);
         $this->assertEquals('Zfns\\Foo', $loader->getClassName('Foo'));
     }
+
+    /**
+     * @group ZF-9721
+     */
+    public function testRemovePrefixPathThrowsExceptionIfPathNotRegisteredInPrefix()
+    {
+        try {
+            $loader = new Zend_Loader_PluginLoader(array('My_Namespace_' => 'My/Namespace/'));
+            $loader->removePrefixPath('My_Namespace_', 'ZF9721');
+            $this->fail();
+        } catch (Exception $e) {
+            $this->assertType('Zend_Loader_PluginLoader_Exception', $e);
+            $this->assertContains('Prefix My_Namespace_ / Path ZF9721', $e->getMessage());
+        }
+        $this->assertEquals(1, count($loader->getPaths('My_Namespace_')));
+    }
 }
 
 // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.