DispatchableDeserializerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
buildDeserializer() 0 1 ?
deserializableProvider() 0 1 ?
nonDeserializableProvider() 0 1 ?
deserializationProvider() 0 1 ?
A testImplementsDispatchableDeserializerInterface() 0 3 1
A testIsDeserializerForReturnsTrue() 0 3 1
A testIsDeserializerForReturnsFalse() 0 3 1
A testDeserializeThrowsDeserializationException() 0 6 1
A testDeserialization() 0 3 1
1
<?php
2
3
namespace Tests\Wikibase\DataModel\Deserializers;
4
5
use Deserializers\DispatchableDeserializer;
6
use Deserializers\Exceptions\DeserializationException;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @license GPL-2.0-or-later
11
 * @author Thomas Pellissier Tanon
12
 * @author Thiemo Kreuz
13
 */
14
abstract class DispatchableDeserializerTest extends TestCase {
15
16
	/**
17
	 * @return DispatchableDeserializer
18
	 */
19
	abstract protected function buildDeserializer();
20
21
	public function testImplementsDispatchableDeserializerInterface() {
22
		$this->assertInstanceOf( DispatchableDeserializer::class, $this->buildDeserializer() );
23
	}
24
25
	/**
26
	 * @dataProvider deserializableProvider
27
	 */
28
	public function testIsDeserializerForReturnsTrue( $deserializable ) {
29
		$this->assertTrue( $this->buildDeserializer()->isDeserializerFor( $deserializable ) );
30
	}
31
32
	/**
33
	 * @return array[] things that are deserialized by the deserializer
34
	 */
35
	abstract public function deserializableProvider();
36
37
	/**
38
	 * @dataProvider nonDeserializableProvider
39
	 */
40
	public function testIsDeserializerForReturnsFalse( $nonDeserializable ) {
41
		$this->assertFalse( $this->buildDeserializer()->isDeserializerFor( $nonDeserializable ) );
42
	}
43
44
	/**
45
	 * @dataProvider nonDeserializableProvider
46
	 */
47
	public function testDeserializeThrowsDeserializationException( $nonDeserializable ) {
48
		$deserializer = $this->buildDeserializer();
49
50
		$this->expectException( DeserializationException::class );
51
		$deserializer->deserialize( $nonDeserializable );
52
	}
53
54
	/**
55
	 * @return array[] things that aren't deserialized by the deserializer
56
	 */
57
	abstract public function nonDeserializableProvider();
58
59
	/**
60
	 * @dataProvider deserializationProvider
61
	 */
62
	public function testDeserialization( $object, $serialization ) {
63
		$this->assertEquals( $object, $this->buildDeserializer()->deserialize( $serialization ) );
64
	}
65
66
	/**
67
	 * @return array[] an array of array( object deserialized, serialization )
68
	 */
69
	abstract public function deserializationProvider();
70
71
}
72