1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Lookup; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
8
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
9
|
|
|
use Wikibase\DataModel\Services\Lookup\DisabledEntityTypesEntityLookup; |
10
|
|
|
use Wikibase\DataModel\Services\Lookup\EntityLookup; |
11
|
|
|
use Wikibase\DataModel\Services\Lookup\EntityLookupException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \Wikibase\DataModel\Services\Lookup\DisabledEntityTypesEntityLookup |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0-or-later |
17
|
|
|
* @author Amir Sarabadani |
18
|
|
|
*/ |
19
|
|
|
class DisabledEntityTypesEntityLookupTest extends TestCase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return EntityLookup |
23
|
|
|
*/ |
24
|
|
|
private function getEntityLookup() { |
25
|
|
|
$entityLookup = $this->createMock( EntityLookup::class ); |
26
|
|
|
|
27
|
|
|
$entityLookup->expects( $this->any() ) |
28
|
|
|
->method( 'hasEntity' ) |
29
|
|
|
->will( $this->returnValue( true ) ); |
30
|
|
|
|
31
|
|
|
$entityLookup->expects( $this->any() ) |
32
|
|
|
->method( 'getEntity' ) |
33
|
|
|
->will( $this->returnCallback( function( EntityId $id ) { |
34
|
|
|
return $id->getSerialization(); |
35
|
|
|
} ) ); |
36
|
|
|
|
37
|
|
|
return $entityLookup; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testConstructor() { |
41
|
|
|
$lookup = new DisabledEntityTypesEntityLookup( $this->getEntityLookup(), [] ); |
|
|
|
|
42
|
|
|
$this->assertInstanceOf( |
43
|
|
|
DisabledEntityTypesEntityLookup::class, |
44
|
|
|
$lookup |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testConstructor_exception() { |
49
|
|
|
$this->expectException( InvalidArgumentException::class ); |
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->expectException( EntityLookupException::class ); |
73
|
|
|
$lookup->getEntity( new ItemId( 'Q1' ) ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: