From 70def086d1237448ae8e407401b5af7b6cb0852e Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Fri, 24 Feb 2012 16:05:30 -0600 Subject: [PATCH 1/3] updated adapter to use addServers --- src/Storage/Adapter/Memcached.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Storage/Adapter/Memcached.php b/src/Storage/Adapter/Memcached.php index 4db849e3f..11f37970e 100644 --- a/src/Storage/Adapter/Memcached.php +++ b/src/Storage/Adapter/Memcached.php @@ -84,10 +84,7 @@ public function __construct($options = null) $options->addServer('localhost', 11211); $servers = $options->getServers(); } - - foreach ($servers as $server) { - $this->memcached->addServer($server[0], $server[1]); - } + $this->memcached->addServers($servers); } /* options */ From 62e60f09600abadef825d45516df3ad2097d4200 Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Fri, 24 Feb 2012 16:09:55 -0600 Subject: [PATCH 2/3] updated memcached test to reflect usage --- test/Storage/Adapter/MemcachedTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Storage/Adapter/MemcachedTest.php b/test/Storage/Adapter/MemcachedTest.php index d4f801203..66706adc6 100644 --- a/test/Storage/Adapter/MemcachedTest.php +++ b/test/Storage/Adapter/MemcachedTest.php @@ -42,8 +42,7 @@ public function setUp() } $this->_options = new Cache\Storage\Adapter\MemcachedOptions(); - $this->_storage = new Cache\Storage\Adapter\Memcached(); - $this->_storage->setOptions($this->_options); + $this->_storage = new Cache\Storage\Adapter\Memcached($this->_options); parent::setUp(); } From 5185be687fb60448890547055f92245b18e7856b Mon Sep 17 00:00:00 2001 From: Mike Willbanks Date: Fri, 24 Feb 2012 16:19:41 -0600 Subject: [PATCH 3/3] added unit test for server handling --- test/Storage/Adapter/MemcachedTest.php | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/Storage/Adapter/MemcachedTest.php b/test/Storage/Adapter/MemcachedTest.php index 66706adc6..ef3c4cae6 100644 --- a/test/Storage/Adapter/MemcachedTest.php +++ b/test/Storage/Adapter/MemcachedTest.php @@ -47,6 +47,48 @@ public function setUp() parent::setUp(); } + public function testOptionsAddServer() + { + $options = new Cache\Storage\Adapter\MemcachedOptions(); + $options->addServer('127.0.0.1', 11211); + $options->addServer('localhost'); + $options->addServer('domain.com', 11215); + + $servers = array( + array('127.0.0.1', 11211), + array('localhost', 11211), + array('domain.com', 11215), + ); + + $this->assertEquals($options->getServers(), $servers); + $memcached = new Cache\Storage\Adapter\Memcached($options); + $this->assertEquals($memcached->getOptions()->getServers(), $servers); + } + + public function testOptionsSetServers() + { + $options = new Cache\Storage\Adapter\MemcachedOptions(); + $servers = array( + array('127.0.0.1', 12345), + array('localhost', 54321), + array('domain.com') + ); + + $options->setServers($servers); + $servers[2][1] = 11211; + $this->assertEquals($options->getServers(), $servers); + + $memcached = new Cache\Storage\Adapter\Memcached($options); + $this->assertEquals($memcached->getOptions()->getServers(), $servers); + } + + public function testNoOptionsSetsDefaultServer() + { + $memcached = new Cache\Storage\Adapter\Memcached(); + + $this->assertEquals($memcached->getOptions()->getServers(), array(array('localhost', 11211))); + } + public function tearDown() { if (!empty($this->_storage)) {