MongoDBEntityIdForTermLookupTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testGetEntityIdsForTerm() 0 38 1
1
<?php
2
3
namespace Wikibase\EntityStore\MongoDB;
4
5
use Wikibase\DataModel\Entity\ItemId;
6
use Wikibase\DataModel\Term\Term;
7
8
/**
9
 * @covers Wikibase\EntityStore\MongoDB\MongoDBEntityIdForTermLookup
10
 *
11
 * @licence GPLv2+
12
 * @author Thomas Pellissier Tanon
13
 */
14
class MongoDBEntityIdForTermLookupTest extends \PHPUnit_Framework_TestCase {
15
16
	public function testGetEntityIdsForTerm() {
17
		$collectionMock = $this->getMockBuilder( 'Doctrine\MongoDB\Collection' )
18
			->disableOriginalConstructor()
19
			->getMock();
20
		$collectionMock->expects( $this->once() )
21
			->method( 'find' )
22
			->with( $this->equalTo( [
23
				'sterms.en' => 'foo'
24
			] ) )
25
			->willReturn( [ [ '_id' => 'Q1' ] ] );
26
27
		$databaseMock = $this->getMockBuilder( 'Doctrine\MongoDB\Database' )
28
			->disableOriginalConstructor()
29
			->getMock();
30
		$databaseMock->expects( $this->once() )
31
			->method( 'selectCollection' )
32
			->with( $this->equalTo( 'item' ) )
33
			->willReturn( $collectionMock );
34
35
		$documentBuilderMock = $this->getMockBuilder( 'Wikibase\EntityStore\MongoDB\MongoDBDocumentBuilder' )
36
			->disableOriginalConstructor()
37
			->getMock();
38
		$documentBuilderMock->expects( $this->once() )
39
			->method( 'buildEntityIdForDocument' )
40
			->with( $this->equalTo( [ '_id' => 'Q1' ] ) )
41
			->willReturn( new ItemId( 'Q1' ) );
42
		$documentBuilderMock->expects( $this->once() )
43
			->method( 'cleanTextForSearch' )
44
			->with( $this->equalTo( 'Foo' ) )
45
			->willReturn( 'foo' );
46
47
		$lookup = new MongoDBEntityIdForTermLookup( $databaseMock, $documentBuilderMock );
48
49
		$this->assertEquals(
50
			[ new ItemId( 'Q1' ) ],
51
			$lookup->getEntityIdsForTerm( new Term( 'en', 'Foo' ), 'item' )
52
		);
53
	}
54
}
55