7 use MediaWikiCoversValidator;
18 $raw = [
'd' => 4,
'c' => 3,
'b' => 2,
'a' => 1 ];
21 $this->assertEquals( 3,
$cache->getMaxSize() );
22 $this->assertSame(
true,
$cache->has(
'a' ) );
23 $this->assertSame(
true,
$cache->has(
'b' ) );
24 $this->assertSame(
true,
$cache->has(
'c' ) );
25 $this->assertSame( 1,
$cache->get(
'a' ) );
26 $this->assertSame( 2,
$cache->get(
'b' ) );
27 $this->assertSame( 3,
$cache->get(
'c' ) );
30 [
'a' => 1,
'b' => 2,
'c' => 3 ],
40 [
'b' => 2,
'c' => 3 ],
53 [
'c' => 3,
'b' => 2,
'a' => 1 ],
67 [
'd' => 4,
'c' => 3,
'b' => 2,
'a' => 1 ],
78 $raw = [
'a' => 1,
'b' => 2,
'c' => 3 ];
81 $this->assertSame(
true,
$cache->has(
'c' ) );
83 [
'a' => 1,
'b' => 2,
'c' => 3 ],
87 $this->assertSame( 3,
$cache->get(
'c' ) );
89 [
'a' => 1,
'b' => 2,
'c' => 3 ],
93 $this->assertSame( 1,
$cache->get(
'a' ) );
95 [
'b' => 2,
'c' => 3,
'a' => 1 ],
101 [
'b' => 2,
'c' => 3,
'a' => 1 ],
107 [
'c' => 3,
'a' => 1,
'b' => 22 ],
113 [
'a' => 1,
'b' => 22,
'd' => 4 ],
117 $cache->set(
'e', 5, 0.33 );
119 [
'e' => 5,
'b' => 22,
'd' => 4 ],
123 $cache->set(
'f', 6, 0.66 );
125 [
'b' => 22,
'f' => 6,
'd' => 4 ],
129 $cache->set(
'g', 7, 0.90 );
131 [
'f' => 6,
'g' => 7,
'd' => 4 ],
135 $cache->set(
'g', 7, 1.0 );
137 [
'f' => 6,
'd' => 4,
'g' => 7 ],
148 $raw = [
'a' => 1,
'b' => 2,
'c' => 3 ];
151 $now = microtime(
true );
152 $cache->setMockTime( $now );
154 $cache->set(
'd',
'xxx' );
155 $this->assertTrue(
$cache->has(
'd', 30 ) );
156 $this->assertEquals(
'xxx',
$cache->get(
'd' ) );
159 $this->assertTrue(
$cache->has(
'd', 30 ) );
160 $this->assertEquals(
'xxx',
$cache->get(
'd' ) );
161 $this->assertEquals(
'xxx',
$cache->get(
'd', 30 ) );
164 $this->assertFalse(
$cache->has(
'd', 30 ) );
165 $this->assertEquals(
'xxx',
$cache->get(
'd' ) );
166 $this->assertNull(
$cache->get(
'd', 30 ) );
175 $raw = [
'a' => 1,
'b' => 2,
'c' => 3 ];
178 $now = microtime(
true );
179 $cache->setMockTime( $now );
181 $cache->setField(
'PMs',
'Tony Blair',
'Labour' );
182 $cache->setField(
'PMs',
'Margaret Thatcher',
'Tory' );
183 $this->assertTrue(
$cache->hasField(
'PMs',
'Tony Blair', 30 ) );
184 $this->assertEquals(
'Labour',
$cache->getField(
'PMs',
'Tony Blair' ) );
185 $this->assertTrue(
$cache->hasField(
'PMs',
'Tony Blair', 30 ) );
188 $this->assertTrue(
$cache->hasField(
'PMs',
'Tony Blair', 30 ) );
189 $this->assertEquals(
'Labour',
$cache->getField(
'PMs',
'Tony Blair' ) );
190 $this->assertEquals(
'Labour',
$cache->getField(
'PMs',
'Tony Blair', 30 ) );
193 $this->assertFalse(
$cache->hasField(
'PMs',
'Tony Blair', 30 ) );
194 $this->assertEquals(
'Labour',
$cache->getField(
'PMs',
'Tony Blair' ) );
195 $this->assertNull(
$cache->getField(
'PMs',
'Tony Blair', 30 ) );
198 [
'Tony Blair' =>
'Labour',
'Margaret Thatcher' =>
'Tory' ],
203 'Edwina Currie' => 1983,
204 'Neil Kinnock' => 1970
208 'Edwina Currie' => 1983,
209 'Neil Kinnock' => 1970
214 $this->assertEquals( 1983,
$cache->getField(
'MPs',
'Edwina Currie' ) );
215 $this->assertEquals( 1970,
$cache->getField(
'MPs',
'Neil Kinnock' ) );
231 $this->fail(
"No exception" );
232 }
catch ( UnexpectedValueException
$e ) {
233 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );
237 $this->fail(
"No exception" );
238 }
catch ( UnexpectedValueException
$e ) {
239 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );
243 $this->fail(
"No exception" );
244 }
catch ( UnexpectedValueException
$e ) {
245 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );
249 $cache->hasField(
'x', 3.4 );
250 $this->fail(
"No exception" );
251 }
catch ( UnexpectedValueException
$e ) {
252 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );
255 $cache->getField(
'x',
false );
256 $this->fail(
"No exception" );
257 }
catch ( UnexpectedValueException
$e ) {
258 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );
261 $cache->setField(
'x', 3.4,
'x' );
262 $this->fail(
"No exception" );
263 }
catch ( UnexpectedValueException
$e ) {
264 $this->assertRegExp(
'/must be string or integer/',
$e->getMessage() );