diff --git a/cache/classes/dummystore.php b/cache/classes/dummystore.php index c11e197cd0c..bcc9ca1e72f 100644 --- a/cache/classes/dummystore.php +++ b/cache/classes/dummystore.php @@ -258,7 +258,9 @@ class cachestore_dummy extends cache_store { */ public static function initialise_test_instance(cache_definition $definition) { $cache = new cachestore_dummy('Dummy store test'); - $cache->initialise($definition); + if ($cache->is_ready()) { + $cache->initialise($definition); + } return $cache; } diff --git a/cache/stores/apcu/lib.php b/cache/stores/apcu/lib.php index cbb20db9110..077a5d7a3ff 100644 --- a/cache/stores/apcu/lib.php +++ b/cache/stores/apcu/lib.php @@ -155,15 +155,6 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i return ($this->definition !== null); } - /** - * Returns true if this cache store instance is ready to use. - * @return bool - */ - public function is_ready() { - // No set up is actually required, providing apc is installed and enabled. - return true; - } - /** * Prepares the given key for use. * @@ -325,6 +316,7 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i } $name = 'APCu test'; $cache = new cachestore_apcu($name); + // No need to check if is_ready() as this has already being done by requirement check. $cache->initialise($definition); return $cache; } diff --git a/cache/stores/file/lib.php b/cache/stores/file/lib.php index 91a0839b3d5..dd5e05825e4 100644 --- a/cache/stores/file/lib.php +++ b/cache/stores/file/lib.php @@ -673,7 +673,9 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i $name = 'File test'; $path = make_cache_directory('cachestore_file_test'); $cache = new cachestore_file($name, array('path' => $path)); - $cache->initialise($definition); + if ($cache->is_ready()) { + $cache->initialise($definition); + } return $cache; } diff --git a/cache/stores/memcache/lib.php b/cache/stores/memcache/lib.php index 6f89d1ace95..60ee49b3b99 100644 --- a/cache/stores/memcache/lib.php +++ b/cache/stores/memcache/lib.php @@ -576,7 +576,9 @@ class cachestore_memcache extends cache_store implements cache_is_configurable { } $store = new cachestore_memcache('Test memcache', $configuration); - $store->initialise($definition); + if ($store->is_ready()) { + $store->initialise($definition); + } return $store; } diff --git a/cache/stores/memcache/tests/memcache_test.php b/cache/stores/memcache/tests/memcache_test.php index 18f486a77ba..f5d4f087b7f 100644 --- a/cache/stores/memcache/tests/memcache_test.php +++ b/cache/stores/memcache/tests/memcache_test.php @@ -58,12 +58,12 @@ class cachestore_memcache_test extends cachestore_tests { $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcache', 'phpunit_test'); $instance = new cachestore_memcache('Memcache Test', cachestore_memcache::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { // Something prevented memcache store to be inited (extension, TEST_CACHESTORE_MEMCACHE_TESTSERVERS...). $this->markTestSkipped(); } + $instance->initialise($definition); $keys = array( // Alphanumeric. diff --git a/cache/stores/memcached/lib.php b/cache/stores/memcached/lib.php index 0c7be7bb9ca..56df93771b9 100644 --- a/cache/stores/memcached/lib.php +++ b/cache/stores/memcached/lib.php @@ -733,7 +733,10 @@ class cachestore_memcached extends cache_store implements cache_is_configurable } $store = new cachestore_memcached($name, $configuration); - $store->initialise($definition); + // If store is ready then only initialise. + if ($store->is_ready()) { + $store->initialise($definition); + } return $store; } diff --git a/cache/stores/memcached/tests/memcached_test.php b/cache/stores/memcached/tests/memcached_test.php index 87517c02b9c..bef5cbe2704 100644 --- a/cache/stores/memcached/tests/memcached_test.php +++ b/cache/stores/memcached/tests/memcached_test.php @@ -62,12 +62,12 @@ class cachestore_memcached_test extends cachestore_tests { $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcached', 'phpunit_test'); $instance = new cachestore_memcached('Memcached Test', cachestore_memcached::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { // Something prevented memcached store to be inited (extension, TEST_CACHESTORE_MEMCACHED_TESTSERVERS...). $this->markTestSkipped(); } + $instance->initialise($definition); $keys = array( // Alphanumeric. @@ -183,7 +183,7 @@ class cachestore_memcached_test extends cachestore_tests { set_config('testname', $testserver, 'cachestore_memcached'); set_config('testservers', $testserver, 'cachestore_memcached'); $checkinstance = cachestore_memcached::initialise_test_instance($definition); - if (!$checkinstance) { + if (!$checkinstance->is_ready()) { $this->markTestSkipped(); } $checkinstances[] = $checkinstance; diff --git a/cache/stores/mongodb/tests/mongodb_test.php b/cache/stores/mongodb/tests/mongodb_test.php index edb7f76ad20..8e97822f2fa 100644 --- a/cache/stores/mongodb/tests/mongodb_test.php +++ b/cache/stores/mongodb/tests/mongodb_test.php @@ -57,11 +57,11 @@ class cachestore_mongodb_test extends cachestore_tests { // This generates a definition that has a hash starting with a number. MDL-46208. $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_mongodb', 'abc'); $instance = new cachestore_mongodb('MongoDB_Test', cachestore_mongodb::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { $this->markTestSkipped(); } + $instance->initialise($definition); $this->assertTrue($instance->set(1, 'alpha')); $this->assertTrue($instance->set(2, 'beta')); diff --git a/cache/tests/fixtures/stores.php b/cache/tests/fixtures/stores.php index 7048a7d120e..c1046b76813 100644 --- a/cache/tests/fixtures/stores.php +++ b/cache/tests/fixtures/stores.php @@ -63,33 +63,33 @@ abstract class cachestore_tests extends advanced_testcase { if ($modes & cache_store::MODE_APPLICATION) { $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, $class, 'phpunit_test'); $instance = new $class($class.'_test', $class::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { $this->markTestSkipped('Could not test '.$class.'. No test instance configured for application caches.'); } else { + $instance->initialise($definition); $this->run_tests($instance); } } if ($modes & cache_store::MODE_SESSION) { $definition = cache_definition::load_adhoc(cache_store::MODE_SESSION, $class, 'phpunit_test'); $instance = new $class($class.'_test', $class::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { $this->markTestSkipped('Could not test '.$class.'. No test instance configured for session caches.'); } else { + $instance->initialise($definition); $this->run_tests($instance); } } if ($modes & cache_store::MODE_REQUEST) { $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, $class, 'phpunit_test'); $instance = new $class($class.'_test', $class::unit_test_configuration()); - $instance->initialise($definition); if (!$instance->is_ready()) { $this->markTestSkipped('Could not test '.$class.'. No test instance configured for request caches.'); } else { + $instance->initialise($definition); $this->run_tests($instance); } }