These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Tests\Wikibase\DataModel\Serializers; |
||
4 | |||
5 | use Serializers\Serializer; |
||
6 | use Wikibase\DataModel\Entity\ItemId; |
||
7 | use Wikibase\DataModel\Reference; |
||
8 | use Wikibase\DataModel\ReferenceList; |
||
9 | use Wikibase\DataModel\Serializers\StatementSerializer; |
||
10 | use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
||
11 | use Wikibase\DataModel\Snak\PropertySomeValueSnak; |
||
12 | use Wikibase\DataModel\Snak\SnakList; |
||
13 | use Wikibase\DataModel\Statement\Statement; |
||
14 | |||
15 | /** |
||
16 | * @covers Wikibase\DataModel\Serializers\StatementSerializer |
||
17 | * |
||
18 | * @license GPL-2.0-or-later |
||
19 | * @author Thomas Pellissier Tanon |
||
20 | */ |
||
21 | class StatementSerializerTest extends DispatchableSerializerTest { |
||
22 | |||
23 | protected function buildSerializer() { |
||
24 | $snakSerializerFake = $this->getMockBuilder( Serializer::class )->getMock(); |
||
25 | $snakSerializerFake->expects( $this->any() ) |
||
26 | ->method( 'serialize' ) |
||
27 | ->will( $this->returnValue( [ |
||
28 | 'snaktype' => 'novalue', |
||
29 | 'property' => "P42" |
||
30 | ] ) ); |
||
31 | |||
32 | $snaksSerializerFake = $this->getMockBuilder( Serializer::class )->getMock(); |
||
33 | $snaksSerializerFake->expects( $this->any() ) |
||
34 | ->method( 'serialize' ) |
||
35 | ->will( $this->returnValue( [ |
||
36 | 'P42' => [ |
||
37 | [ |
||
38 | 'snaktype' => 'novalue', |
||
39 | 'property' => 'P42' |
||
40 | ] |
||
41 | ] |
||
42 | ] ) ); |
||
43 | |||
44 | $referencesSerializerFake = $this->getMockBuilder( Serializer::class )->getMock(); |
||
45 | $referencesSerializerFake->expects( $this->any() ) |
||
46 | ->method( 'serialize' ) |
||
47 | ->will( $this->returnValue( [ |
||
48 | [ |
||
49 | 'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709', |
||
50 | 'snaks' => [] |
||
51 | ] |
||
52 | ] ) ); |
||
53 | |||
54 | return new StatementSerializer( $snakSerializerFake, $snaksSerializerFake, $referencesSerializerFake ); |
||
0 ignored issues
–
show
$snaksSerializerFake is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Serializers\Serializer> .
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...
$referencesSerializerFake is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Serializers\Serializer> .
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...
|
|||
55 | } |
||
56 | |||
57 | public function serializableProvider() { |
||
58 | return [ |
||
59 | [ |
||
60 | new Statement( new PropertyNoValueSnak( 42 ) ) |
||
61 | ], |
||
62 | ]; |
||
63 | } |
||
64 | |||
65 | public function nonSerializableProvider() { |
||
66 | return [ |
||
67 | [ |
||
68 | 5 |
||
69 | ], |
||
70 | [ |
||
71 | [] |
||
72 | ], |
||
73 | [ |
||
74 | new ItemId( 'Q42' ) |
||
75 | ], |
||
76 | ]; |
||
77 | } |
||
78 | |||
79 | public function serializationProvider() { |
||
80 | $serializations = []; |
||
81 | |||
82 | $serializations[] = [ |
||
83 | [ |
||
84 | 'mainsnak' => [ |
||
85 | 'snaktype' => 'novalue', |
||
86 | 'property' => 'P42' |
||
87 | ], |
||
88 | 'type' => 'statement', |
||
89 | 'rank' => 'normal' |
||
90 | ], |
||
91 | new Statement( new PropertyNoValueSnak( 42 ) ) |
||
92 | ]; |
||
93 | |||
94 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
95 | $statement->setGuid( 'q42' ); |
||
96 | $serializations[] = [ |
||
97 | [ |
||
98 | 'mainsnak' => [ |
||
99 | 'snaktype' => 'novalue', |
||
100 | 'property' => 'P42' |
||
101 | ], |
||
102 | 'type' => 'statement', |
||
103 | 'id' => 'q42', |
||
104 | 'rank' => 'normal' |
||
105 | ], |
||
106 | $statement |
||
107 | ]; |
||
108 | |||
109 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
110 | $statement->setRank( Statement::RANK_PREFERRED ); |
||
111 | $serializations[] = [ |
||
112 | [ |
||
113 | 'mainsnak' => [ |
||
114 | 'snaktype' => 'novalue', |
||
115 | 'property' => 'P42' |
||
116 | ], |
||
117 | 'type' => 'statement', |
||
118 | 'rank' => 'preferred' |
||
119 | ], |
||
120 | $statement |
||
121 | ]; |
||
122 | |||
123 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
124 | $statement->setRank( Statement::RANK_DEPRECATED ); |
||
125 | $serializations[] = [ |
||
126 | [ |
||
127 | 'mainsnak' => [ |
||
128 | 'snaktype' => 'novalue', |
||
129 | 'property' => 'P42' |
||
130 | ], |
||
131 | 'type' => 'statement', |
||
132 | 'rank' => 'deprecated' |
||
133 | ], |
||
134 | $statement |
||
135 | ]; |
||
136 | |||
137 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
138 | $statement->setQualifiers( new SnakList( [] ) ); |
||
139 | $serializations[] = [ |
||
140 | [ |
||
141 | 'mainsnak' => [ |
||
142 | 'snaktype' => 'novalue', |
||
143 | 'property' => "P42" |
||
144 | ], |
||
145 | 'type' => 'statement', |
||
146 | 'rank' => 'normal' |
||
147 | ], |
||
148 | $statement |
||
149 | ]; |
||
150 | |||
151 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
152 | $statement->setQualifiers( new SnakList( [ |
||
153 | new PropertyNoValueSnak( 42 ) |
||
154 | ] ) ); |
||
155 | $serializations[] = [ |
||
156 | [ |
||
157 | 'mainsnak' => [ |
||
158 | 'snaktype' => 'novalue', |
||
159 | 'property' => "P42" |
||
160 | ], |
||
161 | 'type' => 'statement', |
||
162 | 'qualifiers' => [ |
||
163 | 'P42' => [ |
||
164 | [ |
||
165 | 'snaktype' => 'novalue', |
||
166 | 'property' => 'P42' |
||
167 | ] |
||
168 | ] |
||
169 | ], |
||
170 | 'qualifiers-order' => [ |
||
171 | 'P42' |
||
172 | ], |
||
173 | 'rank' => 'normal' |
||
174 | ], |
||
175 | $statement |
||
176 | ]; |
||
177 | |||
178 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
179 | $statement->setReferences( new ReferenceList( [ |
||
180 | new Reference( [ new PropertyNoValueSnak( 1 ) ] ) |
||
181 | ] ) ); |
||
182 | $serializations[] = [ |
||
183 | [ |
||
184 | 'mainsnak' => [ |
||
185 | 'snaktype' => 'novalue', |
||
186 | 'property' => "P42" |
||
187 | ], |
||
188 | 'type' => 'statement', |
||
189 | 'rank' => 'normal', |
||
190 | 'references' => [ |
||
191 | [ |
||
192 | 'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709', |
||
193 | 'snaks' => [] |
||
194 | ] |
||
195 | ], |
||
196 | ], |
||
197 | $statement |
||
198 | ]; |
||
199 | |||
200 | return $serializations; |
||
201 | } |
||
202 | |||
203 | public function testQualifiersOrderSerialization() { |
||
204 | $snakSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
205 | $snakSerializerMock->expects( $this->any() ) |
||
206 | ->method( 'serialize' ) |
||
207 | ->will( $this->returnValue( [ |
||
208 | 'snaktype' => 'novalue', |
||
209 | 'property' => 'P42' |
||
210 | ] ) ); |
||
211 | |||
212 | $snaksSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
213 | $snaksSerializerMock->expects( $this->any() ) |
||
214 | ->method( 'serialize' ) |
||
215 | ->will( $this->returnValue( [] ) ); |
||
216 | |||
217 | $referencesSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
218 | $statementSerializer = new StatementSerializer( |
||
219 | $snakSerializerMock, |
||
220 | $snaksSerializerMock, |
||
221 | $referencesSerializerMock |
||
222 | ); |
||
223 | |||
224 | $statement = new Statement( new PropertyNoValueSnak( 42 ) ); |
||
225 | $statement->setQualifiers( new SnakList( [ |
||
226 | new PropertyNoValueSnak( 42 ), |
||
227 | new PropertySomeValueSnak( 24 ), |
||
228 | new PropertyNoValueSnak( 24 ) |
||
229 | ] ) ); |
||
230 | $this->assertEquals( |
||
231 | [ |
||
232 | 'mainsnak' => [ |
||
233 | 'snaktype' => 'novalue', |
||
234 | 'property' => 'P42' |
||
235 | ], |
||
236 | 'qualifiers' => [], |
||
237 | 'qualifiers-order' => [ |
||
238 | 'P42', |
||
239 | 'P24' |
||
240 | ], |
||
241 | 'type' => 'statement', |
||
242 | 'rank' => 'normal' |
||
243 | ], |
||
244 | $statementSerializer->serialize( $statement ) |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | } |
||
249 |
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: