EntityIdForQueryCacheTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetch() 0 6 1
A testFetchWithOptions() 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 Ask\Language\Description\AnyValue;
6
use Ask\Language\Option\QueryOptions;
7
use Doctrine\Common\Cache\ArrayCache;
8
use Wikibase\DataModel\Entity\ItemId;
9
10
/**
11
 * @covers Wikibase\EntityStore\Cache\EntityIdForQueryCache
12
 *
13
 * @licence GPLv2+
14
 * @author Thomas Pellissier Tanon
15
 */
16
class EntityIdForQueryCacheTest extends \PHPUnit_Framework_TestCase {
17
18
	public function testFetch() {
19
		$cache = new EntityIdForQueryCache( new ArrayCache() );
20
		$cache->save( new AnyValue(), null, 'item', [ new ItemId( 'Q42' ) ] );
21
22
		$this->assertEquals( [ new ItemId( 'Q42' ) ], $cache->fetch( new AnyValue(), null, 'item' ) );
23
	}
24
25
	public function testFetchWithOptions() {
26
		$cache = new EntityIdForQueryCache( new ArrayCache() );
27
		$cache->save( new AnyValue(), new QueryOptions( 10, 0 ), 'item', [ new ItemId( 'Q42' ) ] );
28
29
		$this->assertEquals( [ new ItemId( 'Q42' ) ], $cache->fetch( new AnyValue(), new QueryOptions( 10, 0 ), 'item' ) );
30
	}
31
32
	public function testFetchWithException() {
33
		$this->setExpectedException( '\OutOfBoundsException' );
34
35
		$cache = new EntityIdForQueryCache( new ArrayCache() );
36
		$cache->fetch( new AnyValue(), null, 'item' );
37
	}
38
39
	public function testContainsTrue() {
40
		$cache = new EntityIdForQueryCache( new ArrayCache() );
41
		$cache->save(new AnyValue(), null, 'item', [ new ItemId( 'Q42' ) ] );
42
43
		$this->assertTrue( $cache->contains( new AnyValue(), null, 'item' ) );
44
	}
45
46
	public function testContainsFalse() {
47
		$cache = new EntityIdForQueryCache( new ArrayCache() );
48
49
		$this->assertFalse( $cache->contains( new AnyValue(), null, 'item' ) );
50
	}
51
}
52