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

testSerializeThrowsUnsupportedObjectException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Tests\Wikibase\DataModel\Serializers;
4
5
use PHPUnit_Framework_TestCase;
6
use Serializers\DispatchableSerializer;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Thomas Pellissier Tanon
11
 * @author Thiemo Mättig
12
 */
13
abstract class DispatchableSerializerTest extends PHPUnit_Framework_TestCase {
14
15
	/**
16
	 * @return DispatchableSerializer
17
	 */
18
	protected abstract function buildSerializer();
19
20
	public function testImplementsDispatchableSerializerInterface() {
21
		$this->assertInstanceOf( 'Serializers\DispatchableSerializer', $this->buildSerializer() );
22
	}
23
24
	/**
25
	 * @dataProvider serializableProvider
26
	 */
27
	public function testIsSerializerForReturnsTrue( $serializable ) {
28
		$this->assertTrue( $this->buildSerializer()->isSerializerFor( $serializable ) );
29
	}
30
31
	/**
32
	 * @return array[] things that are serialized by the serializer
33
	 */
34
	public abstract function serializableProvider();
35
36
	/**
37
	 * @dataProvider nonSerializableProvider
38
	 */
39
	public function testIsSerializerForReturnsFalse( $nonSerializable ) {
40
		$this->assertFalse( $this->buildSerializer()->isSerializerFor( $nonSerializable ) );
41
	}
42
43
	/**
44
	 * @dataProvider nonSerializableProvider
45
	 */
46
	public function testSerializeThrowsUnsupportedObjectException( $nonSerializable ) {
47
		$this->setExpectedException( 'Serializers\Exceptions\UnsupportedObjectException' );
48
		$this->buildSerializer()->serialize( $nonSerializable );
49
	}
50
51
	/**
52
	 * @return array[] things that aren't serialized by the serializer
53
	 */
54
	public abstract function nonSerializableProvider();
55
56
	/**
57
	 * @dataProvider serializationProvider
58
	 */
59
	public function testSerialization( $serialization, $object ) {
60
		$this->assertSame( $serialization, $this->buildSerializer()->serialize( $object ) );
61
	}
62
63
	/**
64
	 * @return array[] an array of array( serialization, object to serialize)
65
	 */
66
	public abstract function serializationProvider();
67
68
}
69