MDL-84124 cache: Purge Redis cache between tests

This commit is contained in:
Andrew Nicols 2025-01-09 07:45:30 +08:00
parent c58bc49a07
commit 00f0ec3ccf
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14

View File

@ -37,10 +37,10 @@ require_once(__DIR__.'/../lib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class compressor_test extends \advanced_testcase {
/** @var null|\cachestore_redis */
protected ?cachestore_redis $store = null;
/**
* Test set up
*/
#[\Override]
public function setUp(): void {
if (!cachestore_redis::are_requirements_met() || !defined('TEST_CACHESTORE_REDIS_TESTSERVERS')) {
$this->markTestSkipped('Could not test cachestore_redis. Requirements are not met.');
@ -49,6 +49,16 @@ final class compressor_test extends \advanced_testcase {
parent::setUp();
}
#[\Override]
protected function tearDown(): void {
parent::tearDown();
if ($this->store !== null) {
$this->store->purge();
$this->store = null;
}
}
/**
* Create a cachestore.
*
@ -64,6 +74,7 @@ final class compressor_test extends \advanced_testcase {
$config['serializer'] = $serializer;
$store = new cachestore_redis('Test', $config);
$store->initialise($definition);
$this->store = $store;
return $store;
}