1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\CacheFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SMW\CacheFactory |
9
|
|
|
* @group semantic-mediawiki |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 2.2 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class CacheFactoryTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$this->assertInstanceOf( |
21
|
|
|
'\SMW\CacheFactory', |
22
|
|
|
new CacheFactory( 'hash' ) |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetMainCacheType() { |
27
|
|
|
|
28
|
|
|
$instance = new CacheFactory( 'hash' ); |
29
|
|
|
|
30
|
|
|
$this->assertEquals( |
31
|
|
|
'hash', |
32
|
|
|
$instance->getMainCacheType() |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$instance = new CacheFactory( CACHE_NONE ); |
36
|
|
|
|
37
|
|
|
$this->assertEquals( |
38
|
|
|
CACHE_NONE, |
39
|
|
|
$instance->getMainCacheType() |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetCachePrefix() { |
44
|
|
|
|
45
|
|
|
$instance = new CacheFactory( 'hash' ); |
46
|
|
|
|
47
|
|
|
$this->assertInternalType( |
48
|
|
|
'string', |
49
|
|
|
$instance->getCachePrefix() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testCanConstructCacheOptions() { |
54
|
|
|
|
55
|
|
|
$instance = new CacheFactory( 'hash' ); |
56
|
|
|
|
57
|
|
|
$cacheOptions = $instance->newCacheOptions( array( |
58
|
|
|
'useCache' => true, |
59
|
|
|
'ttl' => 0 |
60
|
|
|
) ); |
61
|
|
|
|
62
|
|
|
$this->assertTrue( |
63
|
|
|
$cacheOptions->useCache |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testIncompleteCacheOptionsThrowsException() { |
68
|
|
|
|
69
|
|
|
$instance = new CacheFactory( 'hash' ); |
70
|
|
|
|
71
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
72
|
|
|
|
73
|
|
|
$cacheOptions = $instance->newCacheOptions( array( |
|
|
|
|
74
|
|
|
'useCache' => true |
75
|
|
|
) ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testCanConstructFixedInMemoryCache() { |
79
|
|
|
|
80
|
|
|
$instance = new CacheFactory( 'hash' ); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf( |
83
|
|
|
'Onoi\Cache\Cache', |
84
|
|
|
$instance->newFixedInMemoryCache() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testCanConstructNullCache() { |
89
|
|
|
|
90
|
|
|
$instance = new CacheFactory( 'hash' ); |
91
|
|
|
|
92
|
|
|
$this->assertInstanceOf( |
93
|
|
|
'Onoi\Cache\Cache', |
94
|
|
|
$instance->newNullCache() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testCanConstructMediaWikiCompositeCache() { |
99
|
|
|
|
100
|
|
|
$instance = new CacheFactory( 'hash' ); |
101
|
|
|
|
102
|
|
|
$this->assertInstanceOf( |
103
|
|
|
'Onoi\Cache\Cache', |
104
|
|
|
$instance->newMediaWikiCompositeCache( CACHE_NONE ) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->assertInstanceOf( |
108
|
|
|
'Onoi\Cache\Cache', |
109
|
|
|
$instance->newMediaWikiCompositeCache( $instance->getMainCacheType() ) |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testCanConstructBlobStore() { |
114
|
|
|
|
115
|
|
|
$instance = new CacheFactory( 'hash' ); |
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf( |
118
|
|
|
'Onoi\BlobStore\BlobStore', |
119
|
|
|
$instance->newBlobStore( 'foo', CACHE_NONE ) |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.