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 ); |
|
|
|
|
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 ); |
|
|
|
|
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
|
|
|
|
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: