Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Totara 19 fixes #64

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/cache_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function generate_store_instance_config(array $stores): array {
foreach ($stores as $name => $store) {

// First check that all the required fields are present in the store.
if (!(array_key_exists('type', $store) ||
if (!(array_key_exists('type', $store) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't feel like a Totara specific change to me? - should it land in the main branch and be backported to the t19 branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire MR should probably go in the main branch.
I suspect this issue, and that of the mismatched fields, haven't been detected because the test function's processing stops once the first exception is thrown.

array_key_exists('config', $store))) {
throw new cache_exception(get_string('store_missing_fields', 'tool_forcedcache', $name));
}
Expand Down
55 changes: 47 additions & 8 deletions tests/cache_config_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public function test_read_non_existent_config_file() {
$method->invoke($config);
}


public function test_generate_store_instance_config() {
// Directly create a config.
$config = new \tool_forcedcache_cache_config();
Expand All @@ -153,20 +152,60 @@ public function test_generate_store_instance_config() {
// Now test with 0 stores declared and confirm its just the defaults.
$this->assertEquals($storezero['expected'], $method->invoke($config, $storezero['input']));

// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
}

public function test_generate_store_instance_config_badtype() {
// Directly create a config.
$config = new \tool_forcedcache_cache_config();

// Setup reflection for private function.
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
$method->setAccessible(true);

// Read in the fixtures file for data.
include(__DIR__ . '/fixtures/stores_data.php');

// First test with 1 store.
$this->assertEquals($storeone['expected'], $method->invoke($config, $storeone['input']));

// Now a second store.
$this->assertEquals($storetwo['expected'], $method->invoke($config, $storetwo['input']));

// Now test with 0 stores declared and confirm its just the defaults.
$this->assertEquals($storezero['expected'], $method->invoke($config, $storezero['input']));

// Now test a store with a bad type.
$this->expectException(\cache_exception::class);
$this->expectExceptionMessage(get_string('store_bad_type', 'tool_forcedcache', 'faketype'));
$storearr1 = $method->invoke($config, $storebadtype['input']);
$this->assertNull($storearr1);
}

public function test_generate_store_instance_config_missingfield() {
// Directly create a config.
$config = new \tool_forcedcache_cache_config();

// Setup reflection for private function.
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
$method->setAccessible(true);

// Read in the fixtures file for data.
include(__DIR__ . '/fixtures/stores_data.php');

// First test with 1 store.
$this->assertEquals($storeone['expected'], $method->invoke($config, $storeone['input']));

// Now a second store.
$this->assertEquals($storetwo['expected'], $method->invoke($config, $storetwo['input']));

// Now test with 0 stores declared and confirm its just the defaults.
$this->assertEquals($storezero['expected'], $method->invoke($config, $storezero['input']));

// Now test a store with a missing required field.
$this->expectException(\cache_exception::class);
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcu-test'));
$storearr1 = $method->invoke($config, $storemissingfields['input']);
$this->assertNull($storearr1);

// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcutest'));
$storearr1 = $method->invoke($config, $storemissingfield['input']);
}

/**
Expand Down
Loading