Completed
Pull Request — master (#24)
by Quentin
03:30
created

CollectionHandlerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 4
dl 0
loc 68
rs 10
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
 * @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
    }
83
}
84