diff --git a/src/StorageFactory.php b/src/StorageFactory.php index 6bde52f31..5779e9d09 100644 --- a/src/StorageFactory.php +++ b/src/StorageFactory.php @@ -54,16 +54,16 @@ public static function factory($cfg) throw new Exception\InvalidArgumentException('Missing "adapter"'); } $adapterName = $cfg['adapter']; - $adapterOptions = null; + $adapterOptions = array(); if (is_array($cfg['adapter'])) { if (!isset($cfg['adapter']['name'])) { throw new Exception\InvalidArgumentException('Missing "adapter.name"'); } $adapterName = $cfg['adapter']['name']; - $adapterOptions = isset($cfg['adapter']['options']) ? $cfg['adapter']['options'] : null; + $adapterOptions = isset($cfg['adapter']['options']) ? $cfg['adapter']['options'] : array(); } - if ($adapterOptions && isset($cfg['options'])) { + if (isset($cfg['options'])) { $adapterOptions = array_merge($adapterOptions, $cfg['options']); } diff --git a/test/StorageFactoryTest.php b/test/StorageFactoryTest.php index 7cd9993f7..febf526ba 100644 --- a/test/StorageFactoryTest.php +++ b/test/StorageFactoryTest.php @@ -89,6 +89,22 @@ public function testFactoryAdapterAsString() $this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache); } + /** + * @group 4445 + */ + public function testFactoryWithAdapterAsStringAndOptions() + { + $cache = Cache\StorageFactory::factory(array( + 'adapter' => 'Memory', + 'options' => array( + 'namespace' => 'test' + ), + )); + + $this->assertInstanceOf('Zend\Cache\Storage\Adapter\Memory', $cache); + $this->assertSame('test', $cache->getOptions()->getNamespace()); + } + public function testFactoryAdapterAsArray() { $cache = Cache\StorageFactory::factory(array(