MediaWiki
REL1_31
MapCacheLRUTest.php
Go to the documentation of this file.
1
<?php
5
class
MapCacheLRUTest
extends
PHPUnit\Framework\TestCase {
6
7
use MediaWikiCoversValidator;
8
15
function
testArrayConversion
() {
16
$raw = [
'd'
=> 4,
'c'
=> 3,
'b'
=> 2,
'a'
=> 1 ];
17
$cache
= MapCacheLRU::newFromArray( $raw, 3 );
18
19
$this->assertSame(
true
,
$cache
->has(
'a'
) );
20
$this->assertSame(
true
,
$cache
->has(
'b'
) );
21
$this->assertSame(
true
,
$cache
->has(
'c'
) );
22
$this->assertSame( 1,
$cache
->get(
'a'
) );
23
$this->assertSame( 2,
$cache
->get(
'b'
) );
24
$this->assertSame( 3,
$cache
->get(
'c'
) );
25
26
$this->assertSame(
27
[
'a'
=> 1,
'b'
=> 2,
'c'
=> 3 ],
28
$cache
->toArray()
29
);
30
$this->assertSame(
31
[
'a'
,
'b'
,
'c'
],
32
$cache
->getAllKeys()
33
);
34
35
$cache
->clear(
'a'
);
36
$this->assertSame(
37
[
'b'
=> 2,
'c'
=> 3 ],
38
$cache
->toArray()
39
);
40
41
$cache
->clear();
42
$this->assertSame(
43
[],
44
$cache
->toArray()
45
);
46
}
47
53
function
testLRU
() {
54
$raw = [
'a'
=> 1,
'b'
=> 2,
'c'
=> 3 ];
55
$cache
= MapCacheLRU::newFromArray( $raw, 3 );
56
57
$this->assertSame(
true
,
$cache
->has(
'c'
) );
58
$this->assertSame(
59
[
'a'
=> 1,
'b'
=> 2,
'c'
=> 3 ],
60
$cache
->toArray()
61
);
62
63
$this->assertSame( 3,
$cache
->get(
'c'
) );
64
$this->assertSame(
65
[
'a'
=> 1,
'b'
=> 2,
'c'
=> 3 ],
66
$cache
->toArray()
67
);
68
69
$this->assertSame( 1,
$cache
->get(
'a'
) );
70
$this->assertSame(
71
[
'b'
=> 2,
'c'
=> 3,
'a'
=> 1 ],
72
$cache
->toArray()
73
);
74
75
$cache
->set(
'a'
, 1 );
76
$this->assertSame(
77
[
'b'
=> 2,
'c'
=> 3,
'a'
=> 1 ],
78
$cache
->toArray()
79
);
80
81
$cache
->set(
'b'
, 22 );
82
$this->assertSame(
83
[
'c'
=> 3,
'a'
=> 1,
'b'
=> 22 ],
84
$cache
->toArray()
85
);
86
87
$cache
->set(
'd'
, 4 );
88
$this->assertSame(
89
[
'a'
=> 1,
'b'
=> 22,
'd'
=> 4 ],
90
$cache
->toArray()
91
);
92
93
$cache
->set(
'e'
, 5, 0.33 );
94
$this->assertSame(
95
[
'e'
=> 5,
'b'
=> 22,
'd'
=> 4 ],
96
$cache
->toArray()
97
);
98
99
$cache
->set(
'f'
, 6, 0.66 );
100
$this->assertSame(
101
[
'b'
=> 22,
'f'
=> 6,
'd'
=> 4 ],
102
$cache
->toArray()
103
);
104
105
$cache
->set(
'g'
, 7, 0.90 );
106
$this->assertSame(
107
[
'f'
=> 6,
'g'
=> 7,
'd'
=> 4 ],
108
$cache
->toArray()
109
);
110
111
$cache
->set(
'g'
, 7, 1.0 );
112
$this->assertSame(
113
[
'f'
=> 6,
'd'
=> 4,
'g'
=> 7 ],
114
$cache
->toArray()
115
);
116
}
117
}
MapCacheLRUTest
Cache.
Definition
MapCacheLRUTest.php:5
MapCacheLRUTest\testLRU
testLRU()
MapCacheLRU::has() MapCacheLRU::get() MapCacheLRU::set()
Definition
MapCacheLRUTest.php:53
MapCacheLRUTest\testArrayConversion
testArrayConversion()
MapCacheLRU::newFromArray() MapCacheLRU::toArray() MapCacheLRU::getAllKeys() MapCacheLRU::clear()
Definition
MapCacheLRUTest.php:15
$cache
$cache
Definition
mcc.php:33
tests
phpunit
includes
libs
MapCacheLRUTest.php
Generated on Mon Nov 25 2024 15:36:25 for MediaWiki by
1.10.0