*/
function fillCache( &$cache, $numEntries ) {
// Fill cache with three values
- for( $i=1; $i<=$numEntries; $i++) {
+ for ( $i = 1; $i <= $numEntries; $i++ ) {
$cache->set( "cache-key-$i", "prop-$i", "value-$i" );
}
}
function getExpectedCache( $cacheMaxEntries, $entryToFill ) {
$expected = array();
- if( $entryToFill === 0 ) {
+ if ( $entryToFill === 0 ) {
# The cache is empty!
return array();
- } elseif( $entryToFill <= $cacheMaxEntries ) {
+ } elseif ( $entryToFill <= $cacheMaxEntries ) {
# Cache is not fully filled
$firstKey = 1;
} else {
$firstKey = 1 + $entryToFill - $cacheMaxEntries;
}
- $lastKey = $entryToFill;
+ $lastKey = $entryToFill;
- for( $i=$firstKey; $i<=$lastKey; $i++ ) {
+ for ( $i = $firstKey; $i <= $lastKey; $i++ ) {
$expected["cache-key-$i"] = array( "prop-$i" => "value-$i" );
}
+
return $expected;
}
/**
* Highlight diff between assertEquals and assertNotSame
*/
- function testPhpUnitArrayEquality() {
+ public function testPhpUnitArrayEquality() {
$one = array( 'A' => 1, 'B' => 2 );
$two = array( 'B' => 2, 'A' => 1 );
- $this->assertEquals( $one, $two ); // ==
+ $this->assertEquals( $one, $two ); // ==
$this->assertNotSame( $one, $two ); // ===
}
* @dataProvider provideInvalidConstructorArg
* @expectedException MWException
*/
- function testConstructorGivenInvalidValue( $maxSize ) {
- $c = new ProcessCacheLRUTestable( $maxSize );
+ public function testConstructorGivenInvalidValue( $maxSize ) {
+ new ProcessCacheLRUTestable( $maxSize );
}
/**
);
}
- function testAddAndGetAKey() {
+ public function testAddAndGetAKey() {
$oneCache = new ProcessCacheLRUTestable( 1 );
$this->assertCacheEmpty( $oneCache );
$this->assertEquals( 'value1', $oneCache->get( 'cache-key', 'prop1' ) );
}
- function testDeleteOldKey() {
+ public function testDeleteOldKey() {
$oneCache = new ProcessCacheLRUTestable( 1 );
$this->assertCacheEmpty( $oneCache );
* @param $cacheMaxEntries Maximum entry the created cache will hold
* @param $entryToFill Number of entries to insert in the created cache.
*/
- function testFillingCache( $cacheMaxEntries, $entryToFill, $msg = '' ) {
+ public function testFillingCache( $cacheMaxEntries, $entryToFill, $msg = '' ) {
$cache = new ProcessCacheLRUTestable( $cacheMaxEntries );
- $this->fillCache( $cache, $entryToFill);
+ $this->fillCache( $cache, $entryToFill );
$this->assertSame(
$this->getExpectedCache( $cacheMaxEntries, $entryToFill ),
$cache->getCache(),
"Filling a $cacheMaxEntries entries cache with $entryToFill entries"
);
-
}
/**
public static function provideCacheFilling() {
// ($cacheMaxEntries, $entryToFill, $msg='')
return array(
- array( 1, 0 ),
- array( 1, 1 ),
- array( 1, 2 ), # overflow
+ array( 1, 0 ),
+ array( 1, 1 ),
+ array( 1, 2 ), # overflow
array( 5, 33 ), # overflow
);
-
}
/**
* Create a cache with only one remaining entry then update
* the first inserted entry. Should bump it to the top.
*/
- function testReplaceExistingKeyShouldBumpEntryToTop() {
+ public function testReplaceExistingKeyShouldBumpEntryToTop() {
$maxEntries = 3;
$cache = new ProcessCacheLRUTestable( $maxEntries );
);
}
- function testRecentlyAccessedKeyStickIn() {
+ public function testRecentlyAccessedKeyStickIn() {
$cache = new ProcessCacheLRUTestable( 2 );
- $cache->set( 'first' , 'prop1', 'value1' );
+ $cache->set( 'first', 'prop1', 'value1' );
$cache->set( 'second', 'prop2', 'value2' );
// Get first
* Given a cache having 1,2,3 as key, updating 2 should bump 2 to
* the top of the queue with the new value: 1,3,2* (* = updated).
*/
- function testReplaceExistingKeyInAFullCacheShouldBumpToTop() {
+ public function testReplaceExistingKeyInAFullCacheShouldBumpToTop() {
$maxEntries = 3;
$cache = new ProcessCacheLRUTestable( $maxEntries );
);
}
- function testBumpExistingKeyToTop() {
+ public function testBumpExistingKeyToTop() {
$cache = new ProcessCacheLRUTestable( 3 );
$this->fillCache( $cache, 3 );
),
$cache->getCache()
);
-
}
-
}
/**
public function getCache() {
return $this->cache;
}
+
public function getEntriesCount() {
return count( $this->cache );
}