testNewStatementDeserializerReturnsDeserializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Integration\Wikibase\InternalSerialization;
4
5
use Deserializers\Deserializer;
6
use Deserializers\DispatchableDeserializer;
7
use Wikibase\DataModel\Entity\BasicEntityIdParser;
8
use Wikibase\InternalSerialization\DeserializerFactory;
9
10
/**
11
 * @covers Wikibase\InternalSerialization\DeserializerFactory
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Jeroen De Dauw < [email protected] >
15
 * @author Bene* < [email protected] >
16
 */
17
class DeserializerFactoryTest extends \PHPUnit\Framework\TestCase {
18
19
	/**
20
	 * @var DeserializerFactory
21
	 */
22
	private $factory;
23
24
	protected function setUp() : void {
25
		$this->factory = TestFactoryBuilder::newDeserializerFactory( $this );
26
	}
27
28
	public function testNewEntityDeserializerReturnsDeserializer() {
29
		$deserializer = $this->factory->newEntityDeserializer();
30
		$this->assertInstanceOf( Deserializer::class, $deserializer );
31
	}
32
33
	public function testNewStatementDeserializerReturnsDeserializer() {
34
		$deserializer = $this->factory->newStatementDeserializer();
35
		$this->assertInstanceOf( Deserializer::class, $deserializer );
36
	}
37
38
	public function testConstructWithCustomEntityDeserializer() {
39
		$factory = new DeserializerFactory(
40
			$this->createMock( Deserializer::class ),
0 ignored issues
show
Documentation introduced by
$this->createMock(\Deser...rs\Deserializer::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Deserializers\Deserializer>.

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...
41
			new BasicEntityIdParser(),
42
			$this->createMock( DispatchableDeserializer::class )
0 ignored issues
show
Documentation introduced by
$this->createMock(\Deser...bleDeserializer::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Deserializer...spatchableDeserializer>.

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...
43
		);
44
45
		$deserializer = $factory->newEntityDeserializer();
46
		$this->assertInstanceOf( Deserializer::class, $deserializer );
47
	}
48
49
}
50