1 | <?php |
||
14 | abstract class DispatchableSerializerTest extends TestCase { |
||
15 | |||
16 | /** |
||
17 | * @return DispatchableSerializer |
||
18 | */ |
||
19 | abstract protected function buildSerializer(); |
||
20 | |||
21 | public function testImplementsDispatchableSerializerInterface() { |
||
22 | $this->assertInstanceOf( DispatchableSerializer::class, $this->buildSerializer() ); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @dataProvider serializableProvider |
||
27 | */ |
||
28 | public function testIsSerializerForReturnsTrue( $serializable ) { |
||
29 | $this->assertTrue( $this->buildSerializer()->isSerializerFor( $serializable ) ); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @return array[] things that are serialized by the serializer |
||
34 | */ |
||
35 | abstract public function serializableProvider(); |
||
36 | |||
37 | /** |
||
38 | * @dataProvider nonSerializableProvider |
||
39 | */ |
||
40 | public function testIsSerializerForReturnsFalse( $nonSerializable ) { |
||
41 | $this->assertFalse( $this->buildSerializer()->isSerializerFor( $nonSerializable ) ); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @dataProvider nonSerializableProvider |
||
46 | */ |
||
47 | public function testSerializeThrowsUnsupportedObjectException( $nonSerializable ) { |
||
48 | $this->expectException( UnsupportedObjectException::class ); |
||
49 | $this->buildSerializer()->serialize( $nonSerializable ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return array[] things that aren't serialized by the serializer |
||
54 | */ |
||
55 | abstract public function nonSerializableProvider(); |
||
56 | |||
57 | /** |
||
58 | * @dataProvider serializationProvider |
||
59 | */ |
||
60 | public function testSerialization( $serialization, $object ) { |
||
61 | $this->assertSame( $serialization, $this->buildSerializer()->serialize( $object ) ); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return array[] an array of array( serialization, object to serialize) |
||
66 | */ |
||
67 | abstract public function serializationProvider(); |
||
68 | |||
69 | } |
||
70 |