Browse Source

Skip Memcached and Redis tests when servers are not running.

When the extensions are present but memcached or redis are not running,
tests should be skipped.

Refs #5993
Mark Story 11 years ago
parent
commit
f53cdbf3ba

+ 1 - 1
src/Cache/Engine/MemcachedEngine.php

@@ -115,7 +115,7 @@ class MemcachedEngine extends CacheEngine
         }
 
         parent::init($config);
-        
+
         if (!empty($config['host'])) {
             if (empty($config['port'])) {
                 $config['servers'] = [$config['host']];

+ 4 - 2
tests/TestCase/Cache/Engine/MemcachedEngineTest.php

@@ -66,6 +66,10 @@ class MemcachedEngineTest extends TestCase
         parent::setUp();
         $this->skipIf(!class_exists('Memcached'), 'Memcached is not installed or configured properly.');
 
+        $socket = @fsockopen('127.0.0.1', 11211, $errno, $errstr, 1);
+        $this->skipIf(!$socket, 'Memcached is not running.');
+        fclose($socket);
+
         $this->_configCache();
     }
 
@@ -831,8 +835,6 @@ class MemcachedEngineTest extends TestCase
      */
     public function testLongDurationEqualToZero()
     {
-        $this->markTestSkipped('Cannot run as Memcached cannot be reflected');
-
         $memcached = new TestMemcachedEngine();
         $memcached->init(['prefix' => 'Foo_', 'compress' => false, 'duration' => 50 * DAY]);
 

+ 5 - 1
tests/TestCase/Cache/Engine/RedisEngineTest.php

@@ -36,7 +36,11 @@ class RedisEngineTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->skipIf(!class_exists('Redis'), 'Redis is not installed or configured properly.');
+        $this->skipIf(!class_exists('Redis'), 'Redis extension is not installed or configured properly.');
+
+        $socket = @fsockopen('127.0.0.1', 6379, $errno, $errstr, 1);
+        $this->skipIf(!$socket, 'Redis is not running.');
+        fclose($socket);
 
         Cache::enable();
         $this->_configCache();