LanguageLabelDescriptionLookupTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 59
c 0
b 0
f 0
wmc 4
lcom 1
cbo 6
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLabelCallsTermLookupAndReturnsStringAsTerm() 0 15 1
A testGetDescriptionCallsTermLookupAndReturnsStringAsTerm() 0 15 1
A testWhenGettingNull_getLabelReturnsNull() 0 11 1
A testWhenGettingNull_getDescriptionReturnsNull() 0 11 1
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' );
0 ignored issues
show
Documentation introduced by
$termLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...ices\Lookup\TermLookup>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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' );
0 ignored issues
show
Documentation introduced by
$termLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...ices\Lookup\TermLookup>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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' );
0 ignored issues
show
Documentation introduced by
$termLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...ices\Lookup\TermLookup>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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' );
0 ignored issues
show
Documentation introduced by
$termLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...ices\Lookup\TermLookup>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
72
		$this->assertNull( $lookup->getDescription( new ItemId( 'Q42' ) ) );
73
	}
74
75
}
76