1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Lookup; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Wikibase\DataModel\Entity\Item; |
7
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
8
|
|
|
use Wikibase\DataModel\Services\Lookup\EntityLookup; |
9
|
|
|
use Wikibase\DataModel\Services\Lookup\ExceptionIgnoringEntityLookup; |
10
|
|
|
use Wikibase\DataModel\Services\Lookup\UnresolvedEntityRedirectException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \Wikibase\DataModel\Services\Lookup\ExceptionIgnoringEntityLookup |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0-or-later |
16
|
|
|
*/ |
17
|
|
|
class ExceptionIgnoringEntityLookupTest extends TestCase { |
18
|
|
|
|
19
|
|
|
public function testGetEntity_returnsEntity() { |
20
|
|
|
$entity = new Item( new ItemId( 'Q1' ) ); |
21
|
|
|
$entityId = $entity->getId(); |
22
|
|
|
$innerLookup = $this->createMock( EntityLookup::class ); |
23
|
|
|
$innerLookup->expects( $this->once() ) |
24
|
|
|
->method( 'getEntity' ) |
25
|
|
|
->with( $entityId ) |
26
|
|
|
->willReturn( $entity ); |
27
|
|
|
$outerLookup = new ExceptionIgnoringEntityLookup( $innerLookup ); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$actual = $outerLookup->getEntity( $entityId ); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->assertSame( $entity, $actual ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGetEntity_returnsNull() { |
35
|
|
|
$entityId = new ItemId( 'Q999999999' ); |
36
|
|
|
$innerLookup = $this->createMock( EntityLookup::class ); |
37
|
|
|
$innerLookup->expects( $this->once() ) |
38
|
|
|
->method( 'getEntity' ) |
39
|
|
|
->with( $entityId ) |
40
|
|
|
->willReturn( null ); |
41
|
|
|
$outerLookup = new ExceptionIgnoringEntityLookup( $innerLookup ); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$actual = $outerLookup->getEntity( $entityId ); |
44
|
|
|
|
45
|
|
|
$this->assertNull( $actual ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetEntity_catchesUnresolvedEntityRedirectException() { |
49
|
|
|
$entityId = new ItemId( 'Q2' ); |
50
|
|
|
$innerLookup = $this->createMock( EntityLookup::class ); |
51
|
|
|
$innerLookup->expects( $this->once() ) |
52
|
|
|
->method( 'getEntity' ) |
53
|
|
|
->with( $entityId ) |
54
|
|
|
->willThrowException( new UnresolvedEntityRedirectException( |
55
|
|
|
$entityId, |
56
|
|
|
new ItemId( 'Q1' ) |
57
|
|
|
) ); |
58
|
|
|
$outerLookup = new ExceptionIgnoringEntityLookup( $innerLookup ); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$actual = $outerLookup->getEntity( $entityId ); |
61
|
|
|
|
62
|
|
|
$this->assertNull( $actual ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider provideBooleans |
67
|
|
|
*/ |
68
|
|
|
public function testHasEntity( $expected ) { |
69
|
|
|
$entityId = new ItemId( 'Q1' ); |
70
|
|
|
$innerLookup = $this->createMock( EntityLookup::class ); |
71
|
|
|
$innerLookup->expects( $this->once() ) |
72
|
|
|
->method( 'hasEntity' ) |
73
|
|
|
->with( $entityId ) |
74
|
|
|
->willReturn( $expected ); |
75
|
|
|
$outerLookup = new ExceptionIgnoringEntityLookup( $innerLookup ); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$actual = $outerLookup->hasEntity( $entityId ); |
78
|
|
|
|
79
|
|
|
$this->assertSame( $expected, $actual ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function provideBooleans() { |
83
|
|
|
return [ |
84
|
|
|
[ true ], |
85
|
|
|
[ false ], |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
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: