Browse Source

Add test case for the memcached config on the second port, #14985

bancer 5 years ago
parent
commit
e87d041edd

+ 10 - 0
src/Cache/Engine/MemcachedEngine.php

@@ -523,4 +523,14 @@ class MemcachedEngine extends CacheEngine
     {
         return (bool)$this->_Memcached->increment($this->_config['prefix'] . $group);
     }
+
+    /**
+     * Get the list of the servers in the pool.
+     *
+     * @return array
+     */
+    public function getServerList()
+    {
+        return $this->_Memcached->getServerList();
+    }
 }

+ 41 - 0
tests/TestCase/Cache/Engine/MemcachedEngineTest.php

@@ -361,6 +361,47 @@ class MemcachedEngineTest extends TestCase
     }
 
     /**
+     * testPhpSerializerSetting method
+     *
+     * @return void
+     */
+    public function testConfigDifferentPorts()
+    {
+        $Memcached1 = new MemcachedEngine();
+        $config1 = [
+            'className' => 'Memcached',
+            'servers' => ['127.0.0.1:11211'],
+            'persistent' => true,
+        ];
+        $Memcached1->init($config1);
+        $expectedServers = [
+            [
+                'host' => '127.0.0.1',
+                'port' => 11211,
+                'type' => 'TCP',
+            ],
+        ];
+        $this->assertEquals($expectedServers, $Memcached1->getServerList());
+
+        $Memcached2 = new MemcachedEngine();
+        $config2 = [
+            'className' => 'Memcached',
+            'servers' => ['127.0.0.1:11212'],
+            'persistent' => true,
+        ];
+
+        $Memcached2->init($config2);
+        $expectedServers = [
+            [
+                'host' => '127.0.0.1',
+                'port' => 11212,
+                'type' => 'TCP',
+            ],
+        ];
+        $this->assertEquals($expectedServers, $Memcached2->getServerList());
+    }
+
+    /**
      * testConfig method
      *
      * @return void