ReferenceListSerializerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildSerializer() 0 11 1
A serializableProvider() 0 12 1
A nonSerializableProvider() 0 13 1
A serializationProvider() 0 24 1
1
<?php
2
3
namespace Tests\Wikibase\DataModel\Serializers;
4
5
use Serializers\Serializer;
6
use Wikibase\DataModel\Reference;
7
use Wikibase\DataModel\ReferenceList;
8
use Wikibase\DataModel\Serializers\ReferenceListSerializer;
9
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
10
11
/**
12
 * @covers Wikibase\DataModel\Serializers\ReferenceListSerializer
13
 *
14
 * @license GPL-2.0-or-later
15
 * @author Thomas Pellissier Tanon
16
 */
17
class ReferenceListSerializerTest extends DispatchableSerializerTest {
18
19
	protected function buildSerializer() {
20
		$referenceSerializerFake = $this->getMockBuilder( Serializer::class )->getMock();
21
		$referenceSerializerFake->expects( $this->any() )
22
			->method( 'serialize' )
23
			->will( $this->returnValue( [
24
				'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
25
				'snaks' => []
26
			] ) );
27
28
		return new ReferenceListSerializer( $referenceSerializerFake );
0 ignored issues
show
Documentation introduced by
$referenceSerializerFake 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...
29
	}
30
31
	public function serializableProvider() {
32
		return [
33
			[
34
				new ReferenceList()
35
			],
36
			[
37
				new ReferenceList( [
38
					new Reference()
39
				] )
40
			],
41
		];
42
	}
43
44
	public function nonSerializableProvider() {
45
		return [
46
			[
47
				5
48
			],
49
			[
50
				[]
51
			],
52
			[
53
				new Reference()
54
			],
55
		];
56
	}
57
58
	public function serializationProvider() {
59
		return [
60
			[
61
				[],
62
				new ReferenceList()
63
			],
64
			[
65
				[
66
					[
67
						'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
68
						'snaks' => []
69
					],
70
					[
71
						'hash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
72
						'snaks' => []
73
					]
74
				],
75
				new ReferenceList( [
76
					new Reference( [ new PropertyNoValueSnak( 1 ) ] ),
77
					new Reference( [ new PropertyNoValueSnak( 1 ) ] )
78
				] )
79
			],
80
		];
81
	}
82
83
}
84