Parcourir la source

ZF-5606
- Changed Zend_Db::factory() to not normalize the adapterNamespace value

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18328 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph il y a 16 ans
Parent
commit
b169ea2715

+ 4 - 2
library/Zend/Db.php

@@ -241,8 +241,10 @@ class Zend_Db
             }
             unset($config['adapterNamespace']);
         }
-        $adapterName = strtolower($adapterNamespace . '_' . $adapter);
-        $adapterName = str_replace(' ', '_', ucwords(str_replace('_', ' ', $adapterName)));
+
+        // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606
+        $adapterName = $adapterNamespace . '_';
+        $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', $adapter)));
 
         /*
          * Load the adapter class.  This throws an exception

+ 48 - 1
tests/Zend/Db/Adapter/StaticTest.php

@@ -109,7 +109,8 @@ class Zend_Db_Adapter_StaticTest extends PHPUnit_Framework_TestCase
         set_include_path($newIp);
 
         try {
-            $db = Zend_Db::factory('Static', array('dbname' => 'dummy', 'adapterNamespace' => 'TestNamespace'));
+            // this test used to read as 'TestNamespace', but due to ZF-5606 has been changed
+            $db = Zend_Db::factory('Static', array('dbname' => 'dummy', 'adapterNamespace' => 'Testnamespace'));
         } catch (Zend_Exception $e) {
             set_include_path($ip);
             $this->fail('Caught exception of type '.get_class($e).' where none was expected: '.$e->getMessage());
@@ -304,6 +305,52 @@ class Zend_Db_Adapter_StaticTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($db->isConnected());
     }
 
+    /**
+     * @group ZF-5606
+     */
+    public function testDbFactoryDoesNotNormalizeNamespace()
+    {
+        $newIncludePath = realpath(dirname(__FILE__) . '/_files/') . PATH_SEPARATOR . get_include_path();
+        $oldIncludePath = set_include_path($newIncludePath);
+        
+        try {
+            $adapter = Zend_Db::factory(
+                'Dbadapter',
+                array('dbname' => 'dummy', 'adapterNamespace' => 'Test_MyCompany1')
+                );
+        } catch (Exception $e) {
+            set_include_path($oldIncludePath);
+            $this->fail('Could not load file for reason: ' . $e->getMessage());
+        }
+        $this->assertEquals('Test_MyCompany1_Dbadapter', get_class($adapter));
+        set_include_path($oldIncludePath);
+        
+    }
+    
+    /**
+     * @group ZF-5606
+     */
+    public function testDbFactoryWillThrowExceptionWhenAssumingBadBehavior()
+    {
+        $newIncludePath = realpath(dirname(__FILE__) . '/_files/') . PATH_SEPARATOR . get_include_path();
+        $oldIncludePath = set_include_path($newIncludePath);
+        
+        try {
+            $adapter = Zend_Db::factory(
+                'Dbadapter',
+                array('dbname' => 'dummy', 'adapterNamespace' => 'Test_MyCompany2')
+                );
+        } catch (Exception $e) {
+            set_include_path($oldIncludePath);
+            $this->assertContains('failed to open stream', $e->getMessage());
+            return;
+        }
+        
+        $this->assertFalse(class_exists('Test_MyCompany2_Dbadapter'));
+        set_include_path($oldIncludePath);
+        
+    }
+    
     public function getDriver()
     {
         return 'Static';

+ 50 - 0
tests/Zend/Db/Adapter/_files/Test/MyCompany1/Dbadapter.php

@@ -0,0 +1,50 @@
+<?php 
+
+class Test_MyCompany1_Dbadapter extends Zend_Db_Adapter_Abstract
+{
+    protected function _connect()
+    {}
+
+    function _checkRequiredOptions(array $config)
+    {}
+    
+    public function isConnected()
+    {}
+
+    public function closeConnection()
+    {}
+
+    public function prepare($sql)
+    {}
+
+    public function lastInsertId($tableName = null, $primaryKey = null)
+    {}
+
+    protected function _beginTransaction()
+    {}
+
+    protected function _commit()
+    {}
+
+    protected function _rollBack()
+    {}
+    
+    public function listTables()
+    {}
+    
+    public function describeTable($tableName, $schemaName = null)
+    {}
+
+    public function setFetchMode($mode)
+    {}
+    
+    public function limit($sql, $count, $offset = 0)
+    {}
+    
+    public function supportsParameters($type)
+    {}
+    
+    public function getServerVersion()
+    {}
+    
+}

+ 50 - 0
tests/Zend/Db/Adapter/_files/Test/Mycompany2/Dbadapter.php

@@ -0,0 +1,50 @@
+<?php 
+
+class Test_Mycompany2_Dbadapter extends Zend_Db_Adapter_Abstract
+{
+    protected function _connect()
+    {}
+
+    function _checkRequiredOptions(array $config)
+    {}
+    
+    public function isConnected()
+    {}
+
+    public function closeConnection()
+    {}
+
+    public function prepare($sql)
+    {}
+
+    public function lastInsertId($tableName = null, $primaryKey = null)
+    {}
+
+    protected function _beginTransaction()
+    {}
+
+    protected function _commit()
+    {}
+
+    protected function _rollBack()
+    {}
+    
+    public function listTables()
+    {}
+    
+    public function describeTable($tableName, $schemaName = null)
+    {}
+
+    public function setFetchMode($mode)
+    {}
+    
+    public function limit($sql, $count, $offset = 0)
+    {}
+    
+    public function supportsParameters($type)
+    {}
+    
+    public function getServerVersion()
+    {}
+    
+}