Completed
Push — master ( 7d8921...21f60a )
by Thomas
26s
created

StatementListDeserializerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 7
Bugs 2 Features 1
Metric Value
wmc 5
c 7
b 2
f 1
lcom 0
cbo 4
dl 0
loc 86
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDeserializer() 0 19 1
A testDeserializeThrowsDeserializationException() 0 5 1
A nonDeserializableProvider() 0 17 1
A testDeserialization() 0 3 1
B deserializationProvider() 0 28 1
1
<?php
2
3
namespace Tests\Wikibase\DataModel\Deserializers;
4
5
use PHPUnit_Framework_TestCase;
6
use Wikibase\DataModel\Deserializers\StatementListDeserializer;
7
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
8
use Wikibase\DataModel\Statement\Statement;
9
use Wikibase\DataModel\Statement\StatementList;
10
11
/**
12
 * @covers Wikibase\DataModel\Deserializers\StatementListDeserializer
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Bene* < [email protected] >
16
 */
17
class StatementListDeserializerTest extends PHPUnit_Framework_TestCase {
18
19
	private function buildDeserializer() {
20
		$statement = new Statement( new PropertyNoValueSnak( 42 ) );
21
		$statement->setGuid( 'test' );
22
23
		$statementDeserializerMock = $this->getMock( '\Deserializers\Deserializer' );
24
		$statementDeserializerMock->expects( $this->any() )
25
			->method( 'deserialize' )
26
			->with( $this->equalTo( array(
27
				'mainsnak' => array(
28
					'snaktype' => 'novalue',
29
					'property' => 'P42'
30
				),
31
				'type' => 'statement',
32
				'rank' => 'normal'
33
			) ) )
34
			->will( $this->returnValue( $statement ) );
35
36
		return new StatementListDeserializer( $statementDeserializerMock );
37
	}
38
39
	/**
40
	 * @dataProvider nonDeserializableProvider
41
	 */
42
	public function testDeserializeThrowsDeserializationException( $nonDeserializable ) {
43
		$deserializer = $this->buildDeserializer();
44
		$this->setExpectedException( 'Deserializers\Exceptions\DeserializationException' );
45
		$deserializer->deserialize( $nonDeserializable );
46
	}
47
48
	public function nonDeserializableProvider() {
49
		return array(
50
			array(
51
				42
52
			),
53
			array(
54
				array(
55
					'id' => 'P10'
56
				)
57
			),
58
			array(
59
				array(
60
					'type' => '42'
61
				)
62
			),
63
		);
64
	}
65
66
	/**
67
	 * @dataProvider deserializationProvider
68
	 */
69
	public function testDeserialization( $object, $serialization ) {
70
		$this->assertEquals( $object, $this->buildDeserializer()->deserialize( $serialization ) );
71
	}
72
73
	public function deserializationProvider() {
74
		$statement = new Statement( new PropertyNoValueSnak( 42 ) );
75
		$statement->setGuid( 'test' );
76
77
		return array(
78
			array(
79
				new StatementList(),
80
				array()
81
			),
82
			array(
83
				new StatementList( array(
84
					$statement
85
				) ),
86
				array(
87
					'P42' => array(
88
						array(
89
							'mainsnak' => array(
90
								'snaktype' => 'novalue',
91
								'property' => 'P42'
92
							),
93
							'type' => 'statement',
94
							'rank' => 'normal'
95
						)
96
					)
97
				)
98
			),
99
		);
100
	}
101
102
}
103