CachedItemIdForQueryLookupTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetItemsForQueryWithCacheHit() 0 21 1
B testGetItemsForQueryWithCacheMiss() 0 25 1
1
<?php
2
3
namespace Wikibase\EntityStore\Cache;
4
5
use Ask\Language\Description\AnyValue;
6
use OutOfBoundsException;
7
use Wikibase\DataModel\Entity\ItemId;
8
9
/**
10
 * @covers Wikibase\EntityStore\Cache\CachedItemIdForQueryLookup
11
 *
12
 * @licence GPLv2+
13
 * @author Thomas Pellissier Tanon
14
 */
15
class CachedItemIdForQueryLookupTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testGetItemsForQueryWithCacheHit() {
18
		$itemIds = [ new ItemId( 'Q1' ) ];
19
20
		$itemIdForQueryLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\ItemIdForQueryLookup' )
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$entityIdForQueryCacheMock = $this->getMockBuilder( 'Wikibase\EntityStore\Cache\EntityIdForQueryCache' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
		$entityIdForQueryCacheMock->expects( $this->once() )
28
			->method( 'fetch' )
29
			->with( $this->equalTo( new AnyValue() ), $this->isNull(), $this->equalTo( 'item' ) )
30
			->willReturn( $itemIds );
31
32
		$itemIdForQueryLookup = new CachedItemIdForQueryLookup( $itemIdForQueryLookupMock, $entityIdForQueryCacheMock );
33
		$this->assertEquals(
34
			$itemIds,
35
			$itemIdForQueryLookup->getItemIdsForQuery( new AnyValue() )
36
		);
37
	}
38
39
	public function testGetItemsForQueryWithCacheMiss() {
40
		$itemIds = [ new ItemId( 'Q1' ) ];
41
42
		$itemIdForQueryLookupMock = $this->getMockBuilder( 'Wikibase\EntityStore\ItemIdForQueryLookup' )
43
			->disableOriginalConstructor()
44
			->getMock();
45
		$itemIdForQueryLookupMock->expects( $this->once() )
46
			->method( 'getItemIdsForQuery' )
47
			->with( $this->equalTo( new AnyValue() ) )
48
			->willReturn( $itemIds );
49
50
		$entityIdForQueryCacheMock = $this->getMockBuilder( 'Wikibase\EntityStore\Cache\EntityIdForQueryCache' )
51
			->disableOriginalConstructor()
52
			->getMock();
53
		$entityIdForQueryCacheMock->expects( $this->once() )
54
			->method( 'fetch' )
55
			->with( $this->equalTo( new AnyValue() ), $this->isNull(), $this->equalTo( 'item' ) )
56
			->willThrowException( new OutOfBoundsException() );
57
58
		$itemIdForQueryLookup = new CachedItemIdForQueryLookup( $itemIdForQueryLookupMock, $entityIdForQueryCacheMock );
59
		$this->assertEquals(
60
			$itemIds,
61
			$itemIdForQueryLookup->getItemIdsForQuery( new AnyValue() )
62
		);
63
	}
64
}
65