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
|
|
|
$this->assertEmpty( |
59
|
|
|
$instance->getStats() |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGetFormattedStats() { |
64
|
|
|
|
65
|
|
|
$instance = InMemoryPoolCache::getInstance(); |
66
|
|
|
|
67
|
|
|
$instance->getPoolCacheFor( 'Foo' )->save( 'Bar', 42 ); |
68
|
|
|
|
69
|
|
|
$this->assertNotEmpty( |
70
|
|
|
$instance->getStats() |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$this->assertInternalType( |
74
|
|
|
'string', |
75
|
|
|
$instance->getFormattedStats( InMemoryPoolCache::FORMAT_PLAIN ) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->assertContains( |
79
|
|
|
'ul', |
80
|
|
|
$instance->getFormattedStats( InMemoryPoolCache::FORMAT_HTML ) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->assertInternalType( |
84
|
|
|
'string', |
85
|
|
|
$instance->getFormattedStats( InMemoryPoolCache::FORMAT_JSON ) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$instance->resetPoolCacheFor( 'Foo' ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|