14 use MediaWikiCoversValidator;
21 $this->assertAttributeEquals( [],
'cache',
$cache, $msg );
29 for ( $i = 1; $i <= $numEntries; $i++ ) {
30 $cache->set(
"cache-key-$i",
"prop-$i",
"value-$i" );
41 if ( $entryToFill === 0 ) {
44 } elseif ( $entryToFill <= $cacheMaxEntries ) {
49 $firstKey = 1 + $entryToFill - $cacheMaxEntries;
52 $lastKey = $entryToFill;
54 for ( $i = $firstKey; $i <= $lastKey; $i++ ) {
55 $expected[
"cache-key-$i"] = [
"prop-$i" =>
"value-$i" ];
66 $one = [
'A' => 1,
'B' => 2 ];
67 $two = [
'B' => 2,
'A' => 1 ];
69 $this->assertEquals( $one, $two );
71 $this->assertNotSame( $one, $two );
107 $oneCache->set(
'cache-key',
'prop1',
'value1' );
108 $this->assertEquals( 1, $oneCache->getEntriesCount() );
109 $this->assertTrue( $oneCache->has(
'cache-key',
'prop1' ) );
110 $this->assertEquals(
'value1', $oneCache->get(
'cache-key',
'prop1' ) );
121 $oneCache->set(
'cache-key',
'prop1',
'value1' );
122 $oneCache->set(
'cache-key',
'prop1',
'value2' );
123 $this->assertEquals(
'value2', $oneCache->get(
'cache-key',
'prop1' ) );
143 "Filling a $cacheMaxEntries entries cache with $entryToFill entries"
176 $cache->set(
"cache-key-1",
"prop-1",
"new-value-for-1" );
180 'cache-key-2' => [
'prop-2' =>
'value-2' ],
181 'cache-key-1' => [
'prop-1' =>
'new-value-for-1' ],
194 $cache->set(
'first',
'prop1',
'value1' );
195 $cache->set(
'second',
'prop2',
'value2' );
198 $cache->get(
'first',
'prop1' );
200 $cache->set(
'third',
'prop3',
'value3' );
202 $this->assertFalse(
$cache->has(
'second',
'prop2' ) );
221 $cache->set(
"cache-key-2",
"prop-2",
"new-value-for-2" );
224 'cache-key-1' => [
'prop-1' =>
'value-1' ],
225 'cache-key-3' => [
'prop-3' =>
'value-3' ],
226 'cache-key-2' => [
'prop-2' =>
'new-value-for-2' ],
230 $this->assertEquals(
'new-value-for-2',
231 $cache->get(
'cache-key-2',
'prop-2' )
243 $cache->set(
"cache-key-1",
"prop-1",
"new value for 1" );
246 'cache-key-2' => [
'prop-2' =>
'value-2' ],
247 'cache-key-3' => [
'prop-3' =>
'value-3' ],
248 'cache-key-1' => [
'prop-1' =>
'new value for 1' ],
266 return count( $this->
cache );
Test for ProcessCacheLRU class.
testPhpUnitArrayEquality()
Highlight diff between assertEquals and assertNotSame @coversNothing.
testReplaceExistingKeyInAFullCacheShouldBumpToTop()
This first create a full cache then update the value for the 2nd filled entry.
testFillingCache( $cacheMaxEntries, $entryToFill, $msg='')
This test that we properly overflow when filling a cache with a sequence of always different cache-ke...
getExpectedCache( $cacheMaxEntries, $entryToFill)
Generates an array of what would be expected in cache for a given cache size and a number of entries ...
testReplaceExistingKeyShouldBumpEntryToTop()
Create a cache with only one remaining entry then update the first inserted entry.
fillCache(&$cache, $numEntries)
Helper to fill a cache object passed by reference.
testAddAndGetAKey()
ProcessCacheLRU::get ProcessCacheLRU::set ProcessCacheLRU::has.
testConstructorGivenInvalidValue( $maxSize)
provideInvalidConstructorArg Wikimedia\Assert\ParameterAssertionException ProcessCacheLRU::__construc...
assertCacheEmpty( $cache, $msg='Cache should be empty')
Helper to verify emptiness of a cache object.
static provideInvalidConstructorArg()
Value which are forbidden by the constructor.
testDeleteOldKey()
ProcessCacheLRU::set ProcessCacheLRU::get.
testBumpExistingKeyToTop()
ProcessCacheLRU::set.
testRecentlyAccessedKeyStickIn()
ProcessCacheLRU::get ProcessCacheLRU::set ProcessCacheLRU::has.
static provideCacheFilling()
Provider for testFillingCache.
Overrides some ProcessCacheLRU methods and properties accessibility.
Class for process caching individual properties of expiring items.
you have access to all of the normal MediaWiki so you can get a DB use the cache