diff --git a/core/Config.php b/core/Config.php index 31662b645..86fc577ae 100644 --- a/core/Config.php +++ b/core/Config.php @@ -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); + } } /** diff --git a/tests/core/ConfigTest.php b/tests/core/ConfigTest.php index f12b16f54..58904e845 100644 --- a/tests/core/ConfigTest.php +++ b/tests/core/ConfigTest.php @@ -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;