Completed
Push — master ( e11051...f173c0 )
by mw
10s
created

BackendCacheTest::testConstructFromInject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace SUC\Tests;
4
5
use SUC\BackendCache;
6
use SUC\Options;
7
use Onoi\BlobStore\BlobStore;
8
use Title;
9
10
/**
11
 * @covers \SUC\BackendCache
12
 * @group summary-cards
13
 *
14
 * @license GNU GPL v2+
15
 * @since   1.0
16
 *
17
 * @author mwjames
18
 */
19
class BackendCacheTest extends \PHPUnit_Framework_TestCase {
20
21
	public function testCanConstruct() {
22
23
		$blobStore = $this->getMockBuilder( BlobStore::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$options = $this->getMockBuilder( Options::class )
28
			->disableOriginalConstructor()
29
			->getMock();
30
31
		$this->assertInstanceOf(
32
			BackendCache::class,
33
			new BackendCache( $blobStore, $options)
34
		);
35
36
		$this->assertInstanceOf(
37
			BackendCache::class,
38
			BackendCache::getInstance()
39
		);
40
41
		BackendCache::clear();
42
	}
43
44
	public function testConstructFromInject() {
45
46
		$backendCache = $this->getMockBuilder( BackendCache::class )
47
			->disableOriginalConstructor()
48
			->getMock();
49
50
		$this->assertSame(
51
			$backendCache,
52
			BackendCache::getInstance( $backendCache )
53
		);
54
	}
55
56
	public function testGetHashFromForNonMatchableNamespace() {
57
58
		$blobStore = $this->getMockBuilder( BlobStore::class )
59
			->disableOriginalConstructor()
60
			->getMock();
61
62
		$options = new Options(
63
			array( 'enabledNamespaceWithTemplate' => array( NS_CATEGORY => 'Foo' ) )
64
		);
65
66
		$instance = new BackendCache(
67
			$blobStore,
68
			$options
69
		);
70
71
		$this->assertInternalType(
72
			'string',
73
			$instance->getHashFrom( Title::newFromText( __METHOD__ ) )
74
		);
75
	}
76
77
	public function testGetHashFromForMatchableNamespace() {
78
79
		$blobStore = $this->getMockBuilder( BlobStore::class )
80
			->disableOriginalConstructor()
81
			->getMock();
82
83
		$options = new Options(
84
			array(
85
				'enabledNamespaceWithTemplate' => array( NS_CATEGORY => 'Foo' ),
86
				'backendParserCacheLifetime'   => 50
87
			)
88
		);
89
90
		$instance = new BackendCache(
91
			$blobStore,
92
			$options
93
		);
94
95
		$this->assertInternalType(
96
			'string',
97
			$instance->getHashFrom( Title::newFromText( __METHOD__, NS_CATEGORY ) )
98
		);
99
	}
100
101
	public function testGetTargetFromForNonFragment() {
102
103
		$blobStore = $this->getMockBuilder( BlobStore::class )
104
			->disableOriginalConstructor()
105
			->getMock();
106
107
		$options = $this->getMockBuilder( Options::class )
108
			->disableOriginalConstructor()
109
			->getMock();
110
111
		$instance = new BackendCache(
112
			$blobStore,
113
			$options
114
		);
115
116
		$this->assertInstanceOf(
117
			Title::class,
118
			$instance->getTargetFrom( __METHOD__ )
119
		);
120
	}
121
122
	public function testInvalidateCache() {
123
124
		$blobStore = $this->getMockBuilder( BlobStore::class )
125
			->disableOriginalConstructor()
126
			->getMock();
127
128
		$blobStore->expects( $this->once() )
129
			->method( 'delete' );
130
131
		$options = $this->getMockBuilder( Options::class )
132
			->disableOriginalConstructor()
133
			->getMock();
134
135
		$instance = new BackendCache(
136
			$blobStore,
137
			$options
138
		);
139
140
		$this->assertInstanceOf(
141
			BlobStore::class,
142
			$instance->getBlobStore()
143
		);
144
145
		$instance->invalidateCache( Title::newFromText( __METHOD__ ) );
146
	}
147
148
}
149