1 | <?php |
||
12 | abstract class SerializerBaseTest extends \PHPUnit_Framework_TestCase { |
||
13 | |||
14 | /** |
||
15 | * @return Serializer |
||
16 | */ |
||
17 | public abstract function buildSerializer(); |
||
18 | |||
19 | public function testImplementsSerializerInterface() { |
||
22 | |||
23 | /** |
||
24 | * @dataProvider serializableProvider |
||
25 | */ |
||
26 | public function testIsSerializerForReturnsTrue( $serializable ) { |
||
27 | $serializer = $this->buildSerializer(); |
||
28 | |||
29 | if ( $serializer instanceof DispatchableSerializer ) { |
||
30 | $this->assertTrue( $serializer->isSerializerFor( $serializable ) ); |
||
31 | } else { |
||
32 | $this->assertTrue( true ); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return mixed[] things that are serialized by the serializer |
||
38 | */ |
||
39 | public abstract function serializableProvider(); |
||
40 | |||
41 | /** |
||
42 | * @dataProvider nonSerializableProvider |
||
43 | */ |
||
44 | public function testIsSerializerForReturnsFalse( $nonSerializable ) { |
||
45 | $serializer = $this->buildSerializer(); |
||
46 | |||
47 | if ( $serializer instanceof DispatchableSerializer ) { |
||
48 | $this->assertFalse( $serializer->isSerializerFor( $nonSerializable ) ); |
||
49 | } else { |
||
50 | $this->assertTrue( true ); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @dataProvider nonSerializableProvider |
||
56 | */ |
||
57 | public function testSerializeThrowsUnsupportedObjectException( $nonSerializable ) { |
||
61 | |||
62 | /** |
||
63 | * @return mixed[] things that aren't serialized by the serializer |
||
64 | */ |
||
65 | public abstract function nonSerializableProvider(); |
||
66 | |||
67 | /** |
||
68 | * @dataProvider serializationProvider |
||
69 | */ |
||
70 | public function testSerialization( $serialization, $object ) { |
||
71 | $this->assertEquals( |
||
72 | $serialization, |
||
73 | $this->buildSerializer()->serialize( $object ) |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return array an array of array( serialization, object to serialize) |
||
79 | */ |
||
80 | public abstract function serializationProvider(); |
||
81 | } |
||
82 |