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