testWhenCacheIsEmpty_decoratedLookupValueIsReturned()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Services\Tests\Lookup;
4
5
use PHPUnit\Framework\TestCase;
6
use Wikibase\DataModel\Entity\PropertyId;
7
use Wikibase\DataModel\Services\Lookup\InProcessCachingDataTypeLookup;
8
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
9
10
/**
11
 * @covers \Wikibase\DataModel\Services\Lookup\InProcessCachingDataTypeLookup
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Katie Filbert < [email protected] >
15
 */
16
class InProcessCachingDataTypeLookupTest extends TestCase {
17
18
	public function testWhenCacheIsEmpty_decoratedLookupValueIsReturned() {
19
		$decoratedLookup = $this->createMock( PropertyDataTypeLookup::class );
20
21
		$decoratedLookup->expects( $this->once() )
22
			->method( 'getDataTypeIdForProperty' )
23
			->with( new PropertyId( 'P1' ) )
24
			->will( $this->returnValue( 'string' ) );
25
26
		$cachingLookup = new InProcessCachingDataTypeLookup( $decoratedLookup );
0 ignored issues
show
Documentation introduced by
$decoratedLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...PropertyDataTypeLookup>.

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...
27
28
		$this->assertSame(
29
			'string',
30
			$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) )
31
		);
32
	}
33
34
	public function testWhenValueInCache_cacheValueIsReturned() {
35
		$decoratedLookup = $this->createMock( PropertyDataTypeLookup::class );
36
37
		$decoratedLookup->expects( $this->once() )
38
			->method( 'getDataTypeIdForProperty' )
39
			->will( $this->returnValue( 'string' ) );
40
41
		$cachingLookup = new InProcessCachingDataTypeLookup( $decoratedLookup );
0 ignored issues
show
Documentation introduced by
$decoratedLookup is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...PropertyDataTypeLookup>.

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...
42
		$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) );
43
44
		$decoratedLookup->expects( $this->never() )
45
			->method( 'getDataTypeIdForProperty' );
46
47
		$this->assertSame(
48
			'string',
49
			$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) )
50
		);
51
	}
52
53
}
54