StatementDeserializerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGivenInvalidSerialization_exceptionIsThrown() 0 4 1
A invalidSerializationProvider() 0 6 1
1
<?php
2
3
namespace Tests\Wikibase\InternalSerialization\Deserializers;
4
5
use Deserializers\Deserializer;
6
use Deserializers\DispatchableDeserializer;
7
use Deserializers\Exceptions\DeserializationException;
8
use Wikibase\InternalSerialization\Deserializers\StatementDeserializer;
9
10
/**
11
 * @covers Wikibase\InternalSerialization\Deserializers\StatementDeserializer
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Thiemo Kreuz
15
 */
16
class StatementDeserializerTest extends \PHPUnit\Framework\TestCase {
17
18
	/**
19
	 * @var Deserializer
20
	 */
21
	private $deserializer;
22
23
	protected function setUp() : void {
24
		$legacyDeserializer = $this->createMock( DispatchableDeserializer::class );
25
		$currentDeserializer = $this->createMock( DispatchableDeserializer::class );
26
		$this->deserializer = new StatementDeserializer( $legacyDeserializer, $currentDeserializer );
0 ignored issues
show
Documentation introduced by
$legacyDeserializer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Deserializers\DispatchableDeserializer>.

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...
Documentation introduced by
$currentDeserializer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Deserializers\DispatchableDeserializer>.

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...
27
	}
28
29
	/**
30
	 * @dataProvider invalidSerializationProvider
31
	 */
32
	public function testGivenInvalidSerialization_exceptionIsThrown( $serialization ) {
33
		$this->expectException( DeserializationException::class );
34
		$this->deserializer->deserialize( $serialization );
35
	}
36
37
	public function invalidSerializationProvider() {
38
		return array(
39
			array( null ),
40
			array( 5 ),
41
		);
42
	}
43
44
}
45