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:
Sam Minnee 2015-08-29 16:20:00 +12:00
parent 52ca089d0b
commit 262f487053
2 changed files with 19 additions and 16 deletions

View File

@ -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);
}
}
/**

View File

@ -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;