testGetEntityIdsForTerm()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 38
rs 8.8571
cc 1
eloc 31
nc 1
nop 0
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