1 | <?php |
||
14 | * @group legacy |
||
15 | */ |
||
16 | class CollectionHandlerTest extends PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | /** |
||
19 | * tests serialize() method. |
||
20 | * |
||
21 | * @dataProvider testSerializeProvider |
||
22 | */ |
||
23 | public function testSerialize($object, $scope, $output) |
||
24 | { |
||
25 | $collectionHandler = new CollectionHandler(); |
||
26 | |||
27 | $this->assertEquals( |
||
28 | $output, |
||
29 | $collectionHandler->serialize($object, $scope) |
||
30 | ); |
||
31 | } |
||
32 | |||
33 | public function testSerializeProvider() |
||
34 | { |
||
35 | $cases = array( |
||
36 | 'string_as_array' => array('string', 'test', array('string')), |
||
37 | 'int_as_array' => array(42, 'test', array(42)), |
||
38 | 'array_as_array' => array( |
||
39 | array('hello', 'foo' => 'bar', 42), |
||
40 | 'test', |
||
41 | array('hello', 'foo' => 'bar', 42), |
||
42 | ), |
||
43 | ); |
||
44 | |||
45 | $scope = 'test'; |
||
46 | $object = $this->prophesize('StdClass'); |
||
47 | $object->willImplement('Majora\Framework\Serializer\Model\SerializableInterface'); |
||
48 | $object->serialize($scope)->willReturnArgument(0); |
||
49 | |||
50 | $cases['array_as_serialized'] = array($object->reveal(), $scope, $scope); |
||
51 | |||
52 | return $cases; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * tests deserialize() method. |
||
57 | * |
||
58 | * @dataProvider testDeserializeProvider |
||
59 | */ |
||
60 | public function testDeserialize($data, $type, $output) |
||
61 | { |
||
62 | $collectionHandler = new CollectionHandler(); |
||
63 | |||
64 | $this->assertEquals( |
||
65 | $output, |
||
66 | $collectionHandler->deserialize($data, $type) |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | public function testDeserializeProvider() |
||
71 | { |
||
72 | return array( |
||
73 | 'not_an_object' => array(123, 'integer', 123), |
||
74 | 'inexistant_object' => array('biggoron', 'F*ckingBigSword', 'biggoron'), |
||
75 | 'not_serializable' => array(array('ganon' => 'dorf'), 'StdClass', new \StdClass()), |
||
76 | 'serializable' => array( |
||
77 | array('id' => 42), |
||
78 | 'Majora\Framework\Serializer\Tests\Model\SerializableMock1', |
||
79 | (new SerializableMock1())->setId(42), |
||
80 | ), |
||
81 | ); |
||
82 | } |
||
84 |