1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Tests\Statement\Filter; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
7
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; |
8
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException; |
9
|
|
|
use Wikibase\DataModel\Services\Statement\Filter\DataTypeStatementFilter; |
10
|
|
|
use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
11
|
|
|
use Wikibase\DataModel\Statement\Statement; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \Wikibase\DataModel\Services\Statement\Filter\DataTypeStatementFilter |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0-or-later |
17
|
|
|
* @author Thiemo Kreuz |
18
|
|
|
*/ |
19
|
|
|
class DataTypeStatementFilterTest extends TestCase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return PropertyDataTypeLookup |
23
|
|
|
*/ |
24
|
|
|
private function getDataTypeLookup() { |
25
|
|
|
$dataTypeLookup = $this->createMock( PropertyDataTypeLookup::class ); |
26
|
|
|
|
27
|
|
|
$dataTypeLookup->expects( $this->once() ) |
28
|
|
|
->method( 'getDataTypeIdForProperty' ) |
29
|
|
|
->will( $this->returnCallback( function( PropertyId $propertyId ) { |
30
|
|
|
$id = $propertyId->getSerialization(); |
31
|
|
|
|
32
|
|
|
if ( $id === 'P3' ) { |
33
|
|
|
throw new PropertyDataTypeLookupException( $propertyId ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $id === 'P1' ? 'identifier' : 'string'; |
37
|
|
|
} ) ); |
38
|
|
|
|
39
|
|
|
return $dataTypeLookup; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider statementProvider |
44
|
|
|
*/ |
45
|
|
|
public function testIsMatch( Statement $statement, $dataTypes, $expected ) { |
46
|
|
|
$filter = new DataTypeStatementFilter( $this->getDataTypeLookup(), $dataTypes ); |
|
|
|
|
47
|
|
|
$this->assertSame( $expected, $filter->statementMatches( $statement ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function statementProvider() { |
51
|
|
|
$identifier = new Statement( new PropertyNoValueSnak( 1 ) ); |
52
|
|
|
$string = new Statement( new PropertyNoValueSnak( 2 ) ); |
53
|
|
|
$deleted = new Statement( new PropertyNoValueSnak( 3 ) ); |
54
|
|
|
|
55
|
|
|
return [ |
56
|
|
|
[ $identifier, null, false ], |
57
|
|
|
[ $identifier, [], false ], |
58
|
|
|
[ $identifier, 'identifier', true ], |
59
|
|
|
[ $identifier, 'identifiers', false ], |
60
|
|
|
[ $deleted, 'identifier', false ], |
61
|
|
|
[ $string, 'identifier', false ], |
62
|
|
|
[ $string, 'string', true ], |
63
|
|
|
[ $identifier, 'string', false ], |
64
|
|
|
[ $identifier, [ 'identifier' ], true ], |
65
|
|
|
[ $identifier, [ 'string', 'identifier' ], true ], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
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: