Skip to content

Commit

Permalink
Merge branch 'wip-mdl-56273' of https://github.com/rajeshtaneja/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 2, 2016
2 parents e84e836 + 4a910b9 commit 8fa816e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
4 changes: 3 additions & 1 deletion cache/classes/dummystore.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ public function instance_deleted() {
*/
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;
}

Expand Down
10 changes: 1 addition & 9 deletions cache/stores/apcu/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ public function is_initialised() {
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.
*
Expand Down Expand Up @@ -325,6 +316,7 @@ public static function initialise_test_instance(cache_definition $definition) {
}
$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;
}
Expand Down
4 changes: 3 additions & 1 deletion cache/stores/file/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,9 @@ public static function initialise_test_instance(cache_definition $definition) {
$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;
}

Expand Down
4 changes: 3 additions & 1 deletion cache/stores/memcache/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ public static function initialise_test_instance(cache_definition $definition) {
}

$store = new cachestore_memcache('Test memcache', $configuration);
$store->initialise($definition);
if ($store->is_ready()) {
$store->initialise($definition);
}

return $store;
}
Expand Down
2 changes: 1 addition & 1 deletion cache/stores/memcache/tests/memcache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function test_valid_keys() {

$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.
Expand Down
5 changes: 4 additions & 1 deletion cache/stores/memcached/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,10 @@ public static function initialise_test_instance(cache_definition $definition) {
}

$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;
}
Expand Down
4 changes: 2 additions & 2 deletions cache/stores/memcached/tests/memcached_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public function test_valid_keys() {

$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.
Expand Down Expand Up @@ -183,7 +183,7 @@ public function test_clustered() {
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;
Expand Down
2 changes: 1 addition & 1 deletion cache/stores/mongodb/tests/mongodb_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public function test_collection_name() {
// 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'));
Expand Down
6 changes: 3 additions & 3 deletions cache/tests/fixtures/stores.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,33 @@ public function test_test_instance() {
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);
}
}
Expand Down

0 comments on commit 8fa816e

Please sign in to comment.