mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR: Avoid access-changing subclass in test.
Using a subclass to change the visibility of protected items didn’t seem necessary in this case, if we add a reasonably logical getter method.
This commit is contained in:
parent
52ca089d0b
commit
262f487053
@ -796,6 +796,13 @@ class Config_LRU {
|
||||
$this->indexing = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the numbers of items in the index
|
||||
*/
|
||||
public function getIndexCount() {
|
||||
return count($this->indexing);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -295,46 +295,42 @@ class ConfigTest extends SapphireTest {
|
||||
}
|
||||
|
||||
public function testLRUDiscarding() {
|
||||
$cache = new ConfigTest_Config_LRU();
|
||||
$cache = new Config_LRU();
|
||||
for ($i = 0; $i < Config_LRU::SIZE*2; $i++) $cache->set($i, $i);
|
||||
$this->assertEquals(
|
||||
Config_LRU::SIZE, count($cache->indexing),
|
||||
Config_LRU::SIZE, $cache->getIndexCount(),
|
||||
'Homogenous usage gives exact discarding'
|
||||
);
|
||||
$cache = new ConfigTest_Config_LRU();
|
||||
$cache = new Config_LRU();
|
||||
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set($i, $i);
|
||||
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set(-1, -1);
|
||||
$this->assertLessThan(
|
||||
Config_LRU::SIZE, count($cache->indexing),
|
||||
Config_LRU::SIZE, $cache->getIndexCount(),
|
||||
'Heterogenous usage gives sufficient discarding'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testLRUCleaning() {
|
||||
$cache = new ConfigTest_Config_LRU();
|
||||
$cache = new Config_LRU();
|
||||
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set($i, $i);
|
||||
$this->assertEquals(Config_LRU::SIZE, count($cache->indexing));
|
||||
$this->assertEquals(Config_LRU::SIZE, $cache->getIndexCount());
|
||||
$cache->clean();
|
||||
$this->assertEquals(0, count($cache->indexing), 'Clean clears all items');
|
||||
$this->assertEquals(0, $cache->getIndexCount(), 'Clean clears all items');
|
||||
$this->assertFalse($cache->get(1), 'Clean clears all items');
|
||||
$cache->set(1, 1, array('Foo'));
|
||||
$this->assertEquals(1, count($cache->indexing));
|
||||
$this->assertEquals(1, $cache->getIndexCount());
|
||||
$cache->clean('Foo');
|
||||
$this->assertEquals(0, count($cache->indexing), 'Clean items with matching tag');
|
||||
$this->assertEquals(0, $cache->getIndexCount(), 'Clean items with matching tag');
|
||||
$this->assertFalse($cache->get(1), 'Clean items with matching tag');
|
||||
$cache->set(1, 1, array('Foo', 'Bar'));
|
||||
$this->assertEquals(1, count($cache->indexing));
|
||||
$this->assertEquals(1, $cache->getIndexCount());
|
||||
$cache->clean('Bar');
|
||||
$this->assertEquals(0, count($cache->indexing), 'Clean items with any single matching tag');
|
||||
$this->assertEquals(0, $cache->getIndexCount(), 'Clean items with any single matching tag');
|
||||
$this->assertFalse($cache->get(1), 'Clean items with any single matching tag');
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigTest_Config_LRU extends Config_LRU implements TestOnly {
|
||||
public $cache;
|
||||
public $indexing;
|
||||
}
|
||||
|
||||
class ConfigTest_Config_MemCache extends Config_MemCache implements TestOnly {
|
||||
|
||||
public $cache;
|
||||
|
Loading…
x
Reference in New Issue
Block a user