1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\DataModel\Deserializers; |
4
|
|
|
|
5
|
|
|
use Deserializers\Deserializer; |
6
|
|
|
use Deserializers\Exceptions\DeserializationException; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Wikibase\DataModel\Deserializers\StatementListDeserializer; |
9
|
|
|
use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
10
|
|
|
use Wikibase\DataModel\Statement\Statement; |
11
|
|
|
use Wikibase\DataModel\Statement\StatementList; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers Wikibase\DataModel\Deserializers\StatementListDeserializer |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0-or-later |
17
|
|
|
* @author Bene* < [email protected] > |
18
|
|
|
*/ |
19
|
|
|
class StatementListDeserializerTest extends TestCase { |
20
|
|
|
|
21
|
|
|
private function buildDeserializer() { |
22
|
|
|
$statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
23
|
|
|
$statement->setGuid( 'test' ); |
24
|
|
|
|
25
|
|
|
$statementDeserializerMock = $this->getMockBuilder( Deserializer::class )->getMock(); |
26
|
|
|
$statementDeserializerMock->expects( $this->any() ) |
27
|
|
|
->method( 'deserialize' ) |
28
|
|
|
->with( $this->equalTo( [ |
29
|
|
|
'mainsnak' => [ |
30
|
|
|
'snaktype' => 'novalue', |
31
|
|
|
'property' => 'P42' |
32
|
|
|
], |
33
|
|
|
'type' => 'statement', |
34
|
|
|
'rank' => 'normal' |
35
|
|
|
] ) ) |
36
|
|
|
->will( $this->returnValue( $statement ) ); |
37
|
|
|
|
38
|
|
|
return new StatementListDeserializer( $statementDeserializerMock ); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @dataProvider nonDeserializableProvider |
43
|
|
|
*/ |
44
|
|
|
public function testDeserializeThrowsDeserializationException( $nonDeserializable ) { |
45
|
|
|
$deserializer = $this->buildDeserializer(); |
46
|
|
|
|
47
|
|
|
$this->expectException( DeserializationException::class ); |
48
|
|
|
$deserializer->deserialize( $nonDeserializable ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function nonDeserializableProvider() { |
52
|
|
|
return [ |
53
|
|
|
[ |
54
|
|
|
42 |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
[ |
58
|
|
|
'id' => 'P10' |
59
|
|
|
] |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
[ |
63
|
|
|
'type' => '42' |
64
|
|
|
] |
65
|
|
|
], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @dataProvider deserializationProvider |
71
|
|
|
*/ |
72
|
|
|
public function testDeserialization( $object, $serialization ) { |
73
|
|
|
$this->assertEquals( $object, $this->buildDeserializer()->deserialize( $serialization ) ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function deserializationProvider() { |
77
|
|
|
$statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
78
|
|
|
$statement->setGuid( 'test' ); |
79
|
|
|
|
80
|
|
|
return [ |
81
|
|
|
[ |
82
|
|
|
new StatementList(), |
83
|
|
|
[] |
84
|
|
|
], |
85
|
|
|
[ |
86
|
|
|
new StatementList( [ |
87
|
|
|
$statement |
88
|
|
|
] ), |
89
|
|
|
[ |
90
|
|
|
'P42' => [ |
91
|
|
|
[ |
92
|
|
|
'mainsnak' => [ |
93
|
|
|
'snaktype' => 'novalue', |
94
|
|
|
'property' => 'P42' |
95
|
|
|
], |
96
|
|
|
'type' => 'statement', |
97
|
|
|
'rank' => 'normal' |
98
|
|
|
] |
99
|
|
|
] |
100
|
|
|
] |
101
|
|
|
], |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
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: