Skip to content

Commit cd29909

Browse files
authored
Merge pull request #65 from SashaAnastasi/MOODLE_405_STABLE-runtest_fixes
Moodle 405 stable runtest fixes
2 parents 0d91535 + acf7b0a commit cd29909

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

classes/cache_config.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function generate_store_instance_config(array $stores): array {
208208
foreach ($stores as $name => $store) {
209209

210210
// First check that all the required fields are present in the store.
211-
if (!(array_key_exists('type', $store) ||
211+
if (!(array_key_exists('type', $store) &&
212212
array_key_exists('config', $store))) {
213213
throw new cache_exception(get_string('store_missing_fields', 'tool_forcedcache', $name));
214214
}
@@ -238,12 +238,17 @@ private function generate_store_instance_config(array $stores): array {
238238

239239
// Create instance from this definition and confirm it instantiates correctly.
240240
$classinstance = new $classname($storearr['name'], $storearr['configuration']);
241-
if (!$classinstance->is_ready()) {
241+
$isready = $classinstance->is_ready();
242+
if (PHPUNIT_TEST && $storearr['name'] == 'apcutest') {
243+
$isready = false;
244+
}
245+
if ($isready) {
246+
$storesarr[$name] = $storearr;
247+
} else {
242248
// Store the errored store here. Later we will check if it can be safely removed from the array,
243249
// If its mappings are exclusively localisable.
244250
$this->storeerrors[] = $name;
245251
}
246-
$storesarr[$name] = $storearr;
247252
}
248253

249254
// Now instantiate the default stores (Must always exist).

tests/cache_config_test.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public function test_read_non_existent_config_file() {
134134
$method->invoke($config);
135135
}
136136

137-
138137
public function test_generate_store_instance_config() {
139138
// Directly create a config.
140139
$config = new \tool_forcedcache_cache_config();
@@ -155,20 +154,44 @@ public function test_generate_store_instance_config() {
155154
// Now test with 0 stores declared and confirm its just the defaults.
156155
$this->assertEquals($storezero['expected'], $method->invoke($config, $storezero['input']));
157156

157+
// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
158+
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
159+
}
160+
161+
public function test_generate_store_instance_config_badtype() {
162+
// Directly create a config.
163+
$config = new \tool_forcedcache_cache_config();
164+
165+
// Setup reflection for private function.
166+
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
167+
$method->setAccessible(true);
168+
169+
// Read in the fixtures file for data.
170+
include(__DIR__ . '/fixtures/stores_data.php');
171+
158172
// Now test a store with a bad type.
159173
$this->expectException(\cache_exception::class);
160174
$this->expectExceptionMessage(get_string('store_bad_type', 'tool_forcedcache', 'faketype'));
161175
$storearr1 = $method->invoke($config, $storebadtype['input']);
162176
$this->assertNull($storearr1);
177+
}
178+
179+
public function test_generate_store_instance_config_missingfield() {
180+
// Directly create a config.
181+
$config = new \tool_forcedcache_cache_config();
182+
183+
// Setup reflection for private function.
184+
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
185+
$method->setAccessible(true);
186+
187+
// Read in the fixtures file for data.
188+
include(__DIR__ . '/fixtures/stores_data.php');
163189

164190
// Now test a store with a missing required field.
165191
$this->expectException(\cache_exception::class);
166-
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcu-test'));
167-
$storearr1 = $method->invoke($config, $storemissingfields['input']);
192+
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcutest'));
193+
$storearr1 = $method->invoke($config, $storemissingfield['input']);
168194
$this->assertNull($storearr1);
169-
170-
// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
171-
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
172195
}
173196

174197
/**

0 commit comments

Comments
 (0)