1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\InMemoryPoolCache; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SMW\InMemoryPoolCache |
9
|
|
|
* @group semantic-mediawiki |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 2.3 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class InMemoryPoolCacheTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
protected function tearDown() { |
19
|
|
|
InMemoryPoolCache::getInstance()->clear(); |
20
|
|
|
parent::tearDown(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testCanConstruct() { |
24
|
|
|
|
25
|
|
|
$cacheFactory = $this->getMockBuilder( '\SMW\CacheFactory' ) |
26
|
|
|
->disableOriginalConstructor() |
27
|
|
|
->getMock(); |
28
|
|
|
|
29
|
|
|
$this->assertInstanceOf( |
30
|
|
|
'\SMW\InMemoryPoolCache', |
31
|
|
|
new InMemoryPoolCache( $cacheFactory ) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$this->assertInstanceOf( |
35
|
|
|
'\SMW\InMemoryPoolCache', |
36
|
|
|
InMemoryPoolCache::getInstance() |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testPoolCache() { |
41
|
|
|
|
42
|
|
|
$instance = InMemoryPoolCache::getInstance(); |
43
|
|
|
|
44
|
|
|
$this->assertInstanceOf( |
45
|
|
|
'\Onoi\Cache\Cache', |
46
|
|
|
$instance->getPoolCacheFor( 'Foo' ) |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$instance->getPoolCacheFor( 'Foo' )->save( 'Bar', 42 ); |
50
|
|
|
|
51
|
|
|
$this->assertEquals( |
52
|
|
|
42, |
53
|
|
|
$instance->getPoolCacheFor( 'Foo' )->fetch( 'Bar' ) |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$instance->resetPoolCacheFor( 'Foo' ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetStats() { |
60
|
|
|
|
61
|
|
|
$instance = InMemoryPoolCache::getInstance(); |
62
|
|
|
|
63
|
|
|
$instance->getPoolCacheFor( 'Foo' )->save( 'Bar', 42 ); |
64
|
|
|
|
65
|
|
|
$this->assertNotEmpty( |
66
|
|
|
$instance->getStats() |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$this->assertInternalType( |
70
|
|
|
'string', |
71
|
|
|
$instance->getStats( InMemoryPoolCache::FORMAT_PLAIN ) |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->assertContains( |
75
|
|
|
'ul', |
76
|
|
|
$instance->getStats( InMemoryPoolCache::FORMAT_HTML ) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->assertInternalType( |
80
|
|
|
'string', |
81
|
|
|
$instance->getStats( InMemoryPoolCache::FORMAT_JSON ) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$instance->resetPoolCacheFor( 'Foo' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|