瀏覽代碼

[ZF-10543] Zend_Application_Resource

- Fixed assigning default metadata cache by Bootstrap.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23383 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 15 年之前
父節點
當前提交
3bc9b8544b
共有 2 個文件被更改,包括 33 次插入3 次删除
  1. 5 3
      library/Zend/Application/Resource/ResourceAbstract.php
  2. 28 0
      tests/Zend/Application/Resource/DbTest.php

+ 5 - 3
library/Zend/Application/Resource/ResourceAbstract.php

@@ -83,6 +83,11 @@ abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Applic
      */
     public function setOptions(array $options)
     {
+        if (array_key_exists('bootstrap', $options)) {
+            $this->setBootstrap($options['bootstrap']);
+            unset($options['bootstrap']);
+        }
+
         foreach ($options as $key => $value) {
             if (in_array(strtolower($key), $this->_skipOptions)) {
                 continue;
@@ -92,9 +97,6 @@ abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Applic
             if (method_exists($this, $method)) {
                 $this->$method($value);
             }
-            if ('bootstrap' === $key) {
-                unset($options[$key]);
-            }
         }
 
         $this->_options = $this->mergeOptions($this->_options, $options);

+ 28 - 0
tests/Zend/Application/Resource/DbTest.php

@@ -223,6 +223,34 @@ class Zend_Application_Resource_DbTest extends PHPUnit_Framework_TestCase
         $db = $resource->init();
         $this->assertEquals($db->getFetchMode(), Zend_Db::FETCH_OBJ);
     }
+
+    /**
+     * @group ZF-10543
+     */
+    public function testSetDefaultMetadataCacheThroughBootstrap()
+    {
+        $options = array(
+            'resources' => array(
+                'db'    => array(
+                    'adapter'  => 'Pdo_Sqlite',
+                    'params'   => array(
+                        'dbname'   => ':memory:'
+                     ),
+                     'defaultMetadataCache' => 'default'
+                ),
+                'cachemanager' => array(
+                    'default'  => array(
+                        'backend' => array('name' => 'black-hole')
+                    )
+                )
+            )
+        );
+
+        $this->bootstrap->setOptions($options);
+        $this->bootstrap->bootstrap();
+        $resource = $this->bootstrap->getResource('cachemanager');
+        $this->assertEquals($resource->getCache('default'), Zend_Db_Table::getDefaultMetadataCache());
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_DbTest::main') {