MDL-48568 cache: stores now determine testing

Cache stores are now responsible for deciding if they are suitable
for use as the primary cache store during unit and acceptance tests

Changes are as follows:
* New method: cache_store::ready_to_be_used_for_testing
* Core cache store have been updated to override this method as
  required.
* MongoDB usesafe default changed to true to match actual default
  behaviour.
This commit is contained in:
Sam Hemelryk 2014-12-12 09:27:16 +13:00
parent 2d84748c26
commit 63b159d0d4
6 changed files with 53 additions and 5 deletions

View File

@ -377,4 +377,16 @@ abstract class cache_store implements cache_store_interface {
public function get_warnings() {
return array();
}
/**
* Returns true if this cache store instance is both suitable for testing, and ready for testing.
*
* Cache stores that support being used as the default store for unit and acceptance testing should
* override this function and return true if there requirements have been met.
*
* @return bool
*/
public static function ready_to_be_used_for_testing() {
return false;
}
}

View File

@ -633,4 +633,16 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
}
return $warnings;
}
/**
* Returns true if this cache store instance is both suitable for testing, and ready for testing.
*
* Cache stores that support being used as the default store for unit and acceptance testing should
* override this function and return true if there requirements have been met.
*
* @return bool
*/
public static function ready_to_be_used_for_testing() {
return defined('TEST_CACHESTORE_MEMCACHE_TESTSERVERS');
}
}

View File

@ -696,4 +696,16 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
}
return $warnings;
}
/**
* Returns true if this cache store instance is both suitable for testing, and ready for testing.
*
* Cache stores that support being used as the default store for unit and acceptance testing should
* override this function and return true if there requirements have been met.
*
* @return bool
*/
public static function ready_to_be_used_for_testing() {
return defined('TEST_CACHESTORE_MEMCACHED_TESTSERVERS');
}
}

View File

@ -85,7 +85,7 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
* Determines if and what safe setting is to be used.
* @var bool|int
*/
protected $usesafe = false;
protected $usesafe = true;
/**
* If set to true then multiple identifiers will be requested and used.
@ -599,4 +599,16 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
public function my_name() {
return $this->name;
}
/**
* Returns true if this cache store instance is both suitable for testing, and ready for testing.
*
* Cache stores that support being used as the default store for unit and acceptance testing should
* override this function and return true if there requirements have been met.
*
* @return bool
*/
public static function ready_to_be_used_for_testing() {
return defined('TEST_CACHESTORE_MONGODB_TESTSERVER');
}
}

View File

@ -61,14 +61,13 @@ class cache_config_phpunittest extends cache_config_writer {
$appdefine = defined('TEST_CACHE_USING_APPLICATION_STORE') ? TEST_CACHE_USING_APPLICATION_STORE : false;
if ($appdefine !== false && preg_match('/^[a-zA-Z][a-zA-Z0-9_]+$/', $appdefine)) {
$expectedstore = $appdefine;
$expecteddefine = 'TEST_CACHESTORE_'.strtoupper($expectedstore).'_TESTSERVERS';
$file = $CFG->dirroot.'/cache/stores/'.$appdefine.'/lib.php';
$class = 'cachestore_'.$appdefine;
if (file_exists($file)) {
require_once($file);
}
if (defined($expecteddefine) && class_exists($class)) {
/** @var cache_store $class */
if (class_exists($class) && $class::ready_to_be_used_for_testing()) {
/* @var cache_store $class */
$writer->configstores['test_application'] = array(
'use_test_store' => true,
'name' => 'test_application',

3
cache/upgrade.txt vendored
View File

@ -10,6 +10,7 @@ Information provided here is intended especially for developers.
- cache_definition::load Argument 3 (final arg) is now unused.
- cache_factory::create_cache_from_definition Argument 4 (final arg) is now unused.
- cache::make Argument 4 (final arg) is now unused.
* New method cache_store::ready_to_be_used_for_testing() that returns true|false if the store is suitable and ready for use as the primary store during unit and acceptance tests.
=== 2.7 ===
* cache_store::is_ready is no longer abstract, calling cache_store::are_requirements_met by default.
@ -32,4 +33,4 @@ Information provided here is intended especially for developers.
* cleanup method renamed to instance_deleted.
It is now called when the store is deleted as all comments suggested anyway.
* instance_created method added.
It is called when the store is created for the very first time.
It is called when the store is created for the very first time.