Revert Cache delete() behavior to stable version

This commit is contained in:
Philipp 2023-01-11 21:10:59 +01:00
parent eda65296f5
commit fd882abd80
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
2 changed files with 58 additions and 49 deletions

View file

@ -40,7 +40,6 @@ class CacheTest extends MockedTest
'int' => 235,
'dec' => 2.456,
'array' => ['1', 2, '3', true, false],
'null' => null,
],
'config' => [
'a' => 'value',
@ -124,7 +123,7 @@ class CacheTest extends MockedTest
// wrong dataset
$configCache->load(['system' => 'not_array']);
self::assertEquals(['system' => 'not_array'], $configCache->getAll());
self::assertEquals([], $configCache->getAll());
// incomplete dataset (key is integer ID of the array)
$configCache = new Cache();
@ -209,16 +208,13 @@ class CacheTest extends MockedTest
{
$configCache = new Cache($data);
$assertion = [];
foreach ($data as $cat => $values) {
$assertion[$cat] = null;
foreach ($values as $key => $value) {
$configCache->delete($cat, $key);
}
}
self::assertEquals($assertion, $configCache->getAll());
self::assertEmpty($configCache->getAll());
}
/**
@ -554,4 +550,30 @@ class CacheTest extends MockedTest
self::assertEquals('new_value', $newCache->get($category, 'new_key'));
}
/**
* Test that keys are removed after a deletion
*
* @dataProvider dataTests
*
*/
public function testDeleteRemovesKey($data)
{
$cache = new Cache();
$cache->load($data, Cache::SOURCE_FILE);
$cache->set('system', 'test', 'overwrite!', Cache::SOURCE_DATA);
self::assertEquals('overwrite!', $cache->get('system', 'test'));
// array should now be removed
$cache->delete('system', 'test');
self::assertArrayNotHasKey('test', $cache->getAll()['system']);
self::assertArrayHasKey('config', $cache->getAll());
self::assertArrayHasKey('a', $cache->getAll()['config']);
// category should now be removed
$cache->delete('config', 'a');
self::assertArrayNotHasKey('config', $cache->getAll());
}
}