EntityIdForTermCacheTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 29
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetch() 0 6 1
A testFetchWithException() 0 6 1
A testContainsTrue() 0 6 1
A testContainsFalse() 0 5 1
1
<?php
2
3
namespace Wikibase\EntityStore\Cache;
4
5
use Doctrine\Common\Cache\ArrayCache;
6
use Wikibase\DataModel\Entity\ItemId;
7
use Wikibase\DataModel\Term\Term;
8
9
/**
10
 * @covers Wikibase\EntityStore\Cache\EntityIdForTermCache
11
 *
12
 * @licence GPLv2+
13
 * @author Thomas Pellissier Tanon
14
 */
15
class EntityIdForTermCacheTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testFetch() {
18
		$cache = new EntityIdForTermCache( new ArrayCache() );
19
		$cache->save( new Term( 'en', 'foo' ), 'item', [ new ItemId( 'Q42' ) ] );
20
21
		$this->assertEquals( [ new ItemId( 'Q42' ) ], $cache->fetch( new Term( 'en', 'foo' ), 'item' ) );
22
	}
23
24
	public function testFetchWithException() {
25
		$this->setExpectedException( '\OutOfBoundsException' );
26
27
		$cache = new EntityIdForTermCache( new ArrayCache() );
28
		$cache->fetch( new Term( 'en', 'foo' ), 'item' );
29
	}
30
31
	public function testContainsTrue() {
32
		$cache = new EntityIdForTermCache( new ArrayCache() );
33
		$cache->save( new Term( 'en', 'foo' ), 'item', [ new ItemId( 'Q42' ) ] );
34
35
		$this->assertTrue( $cache->contains( new Term( 'en', 'foo' ), 'item' ) );
36
	}
37
38
	public function testContainsFalse() {
39
		$cache = new EntityIdForTermCache( new ArrayCache() );
40
41
		$this->assertFalse( $cache->contains( new Term( 'en', 'foo' ), 'item' ) );
42
	}
43
}
44