Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#4480 from marc-mabe/ho…
Browse files Browse the repository at this point in the history
…tfix/4445

fixed Cache\StorageFactory::factory()
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down
16 changes: 16 additions & 0 deletions test/StorageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9a1b341

Please sign in to comment.