1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Lookup; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
7
|
|
|
use Wikibase\DataModel\Services\Lookup\LanguageLabelDescriptionLookup; |
8
|
|
|
use Wikibase\DataModel\Services\Lookup\TermLookup; |
9
|
|
|
use Wikibase\DataModel\Term\Term; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \Wikibase\DataModel\Services\Lookup\LanguageLabelDescriptionLookup |
13
|
|
|
* |
14
|
|
|
* @license GPL-2.0-or-later |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class LanguageLabelDescriptionLookupTest extends TestCase { |
18
|
|
|
|
19
|
|
|
public function testGetLabelCallsTermLookupAndReturnsStringAsTerm() { |
20
|
|
|
$termLookup = $this->createMock( TermLookup::class ); |
21
|
|
|
|
22
|
|
|
$termLookup->expects( $this->once() ) |
23
|
|
|
->method( 'getLabel' ) |
24
|
|
|
->with( $this->equalTo( new ItemId( 'Q42' ) ), $this->equalTo( 'language_code' ) ) |
25
|
|
|
->will( $this->returnValue( 'term_text' ) ); |
26
|
|
|
|
27
|
|
|
$lookup = new LanguageLabelDescriptionLookup( $termLookup, 'language_code' ); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->assertEquals( |
30
|
|
|
new Term( 'language_code', 'term_text' ), |
31
|
|
|
$lookup->getLabel( new ItemId( 'Q42' ) ) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetDescriptionCallsTermLookupAndReturnsStringAsTerm() { |
36
|
|
|
$termLookup = $this->createMock( TermLookup::class ); |
37
|
|
|
|
38
|
|
|
$termLookup->expects( $this->once() ) |
39
|
|
|
->method( 'getDescription' ) |
40
|
|
|
->with( $this->equalTo( new ItemId( 'Q42' ) ), $this->equalTo( 'language_code' ) ) |
41
|
|
|
->will( $this->returnValue( 'term_text' ) ); |
42
|
|
|
|
43
|
|
|
$lookup = new LanguageLabelDescriptionLookup( $termLookup, 'language_code' ); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->assertEquals( |
46
|
|
|
new Term( 'language_code', 'term_text' ), |
47
|
|
|
$lookup->getDescription( new ItemId( 'Q42' ) ) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testWhenGettingNull_getLabelReturnsNull() { |
52
|
|
|
$termLookup = $this->createMock( TermLookup::class ); |
53
|
|
|
|
54
|
|
|
$termLookup->expects( $this->once() ) |
55
|
|
|
->method( 'getLabel' ) |
56
|
|
|
->will( $this->returnValue( null ) ); |
57
|
|
|
|
58
|
|
|
$lookup = new LanguageLabelDescriptionLookup( $termLookup, 'language_code' ); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->assertNull( $lookup->getLabel( new ItemId( 'Q42' ) ) ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testWhenGettingNull_getDescriptionReturnsNull() { |
64
|
|
|
$termLookup = $this->createMock( TermLookup::class ); |
65
|
|
|
|
66
|
|
|
$termLookup->expects( $this->once() ) |
67
|
|
|
->method( 'getDescription' ) |
68
|
|
|
->will( $this->returnValue( null ) ); |
69
|
|
|
|
70
|
|
|
$lookup = new LanguageLabelDescriptionLookup( $termLookup, 'language_code' ); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->assertNull( $lookup->getDescription( new ItemId( 'Q42' ) ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
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: