Completed
Push — master ( 16bc1d...b837ed )
by Leszek
11s
created

getEntityLookup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Services\Tests\Lookup;
4
5
use Wikibase\DataModel\Entity\EntityId;
6
use Wikibase\DataModel\Entity\ItemId;
7
use Wikibase\DataModel\Services\Lookup\DisabledEntityTypesEntityLookup;
8
use Wikibase\DataModel\Services\Lookup\EntityLookup;
9
use Wikibase\DataModel\Services\Lookup\EntityLookupException;
10
11
/**
12
 * @covers Wikibase\DataModel\Services\Lookup\DisabledEntityTypesEntityLookup
13
 *
14
 * @license GPL-2.0+
15
 * @author Amir Sarabadani
16
 */
17
class DisabledEntityTypesEntityLookupTest extends \PHPUnit_Framework_TestCase {
18
19
	/**
20
	 * @return EntityLookup
21
	 */
22
	private function getEntityLookup() {
23
		$entityLookup = $this->getMock( EntityLookup::class );
24
25
		$entityLookup->expects( $this->any() )
26
			->method( 'hasEntity' )
27
			->will( $this->returnValue( true ) );
28
29
		$entityLookup->expects( $this->any() )
30
			->method( 'getEntity' )
31
			->will( $this->returnCallback( function( EntityId $id ) {
32
				return $id->getSerialization();
33
			} ) );
34
35
		return $entityLookup;
36
	}
37
38
	public function testConstructor() {
39
		$lookup = new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [] );
40
		$this->assertInstanceOf(
41
			DisabledEntityTypesEntityLookup::class,
42
			$lookup
43
		);
44
	}
45
46
	/**
47
	 * @expectedException \InvalidArgumentException
48
	 */
49
	public function testConstructor_exception() {
50
		new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [ 0 ] );
51
	}
52
53
	public function testHasEntity() {
54
		$lookup = new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [] );
55
56
		$this->assertTrue( $lookup->hasEntity( new ItemId( 'Q22' ) ) );
57
	}
58
59
	public function testGetEntity() {
60
		$lookup = new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [] );
61
62
		for ( $i = 1; $i < 6; $i++ ) {
63
			$this->assertSame(
64
				'Q' . $i,
65
				$lookup->getEntity( new ItemId( 'Q' . $i ) )
66
			);
67
		}
68
	}
69
70
	public function testGetEntity_exceptionDisabledEntityType() {
71
		$lookup = new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [ 'item' ] );
72
		$this->setExpectedException( EntityLookupException::class );
73
		$lookup->getEntity( new ItemId( 'Q1' ) );
74
	}
75
76
}
77