diff --git a/src/Hoard/CacheManager.php b/src/Hoard/CacheManager.php index 3be0b48..772c6e7 100644 --- a/src/Hoard/CacheManager.php +++ b/src/Hoard/CacheManager.php @@ -53,6 +53,9 @@ public static function getPool($poolName, array $config = array()) // create adapter $adapterClass = '\Hoard\Adapter\Memcached'; + if(array_key_exists('adapter', $config)) { + $adapterClass = $config['adapter']; + } $adapter = new $adapterClass($config); // create pool diff --git a/test/Hoard/CacheManagerTest.php b/test/Hoard/CacheManagerTest.php index ac4f652..4f44585 100644 --- a/test/Hoard/CacheManagerTest.php +++ b/test/Hoard/CacheManagerTest.php @@ -12,9 +12,28 @@ public function log($level, $message, array $context = array()) } +class DummyAdapter extends \Hoard\Adapter\Memcached +{ +} + class CacheManagerTest extends \PHPUnit_Framework_TestCase { + public function testWillUseMemcacheAdapterIfNotProvided() + { + $pool = CacheManager::getPool('test.simple'); + $this->assertInstanceOf('\Hoard\Adapter\Memcached', $pool->getAdapter()); + } + + public function testWillUseAdapterIfProvided() + { + $config = array( + 'adapter' => '\Hoard\DummyAdapter' + ); + $pool = CacheManager::getPool('test.simple', $config); + $this->assertInstanceOf('\Hoard\DummyAdapter', $pool->getAdapter()); + } + public function testWillSetAdapterOptionsWhenCreatingThePool() { $pool = CacheManager::getPool('test.simple');