Completed
Push — master ( 0e7db1...c18576 )
by Tomasz
12s
created

NormalizerTest::testCallbackNormalizer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
namespace Thunder\Serializard\Tests;
3
4
use Thunder\Serializard\Normalizer\CallbackNormalizer;
5
use Thunder\Serializard\Normalizer\GetObjectVarsNormalizer;
6
use Thunder\Serializard\Normalizer\ReflectionNormalizer;
7
use Thunder\Serializard\Tests\Fake\Inheritance\FakeClass;
8
use Thunder\Serializard\Tests\Fake\FakeTag;
9
use Thunder\Serializard\Tests\Fake\FakeUser;
10
use Thunder\Serializard\Tests\Fake\PropertyVisibility;
11
12
/**
13
 * @author Tomasz Kowalczyk <[email protected]>
14
 */
15
final class NormalizerTest extends AbstractTestCase
16
{
17
    public function testReflectionSkip()
18
    {
19
        $normalizer = new ReflectionNormalizer(array('tag', 'tags'));
20
        $object = new FakeUser(12, 'XXX', new FakeTag(144, 'YYY'));
21
22
        $this->assertSame(array('id' => 12, 'name' => 'XXX'), $normalizer($object));
23
    }
24
25
    public function testReflectionInheritance()
26
    {
27
        $normalizer = new ReflectionNormalizer();
28
29
        $this->assertSame(array(
30
            'property' => 'property',
31
            'parentProperty' => 'parent',
32
            'parentParentProperty' => 'parentParent',
33
        ), $normalizer(new FakeClass('parentParent', 'parent', 'property')));
34
    }
35
36
    public function testGetObjectVarsNormalizer()
37
    {
38
        $normalizer = new GetObjectVarsNormalizer();
39
40
        $this->assertSame(array(
41
            'public' => 'public',
42
        ), $normalizer(new PropertyVisibility()));
43
    }
44
45
    public function testCallbackNormalizer()
46
    {
47
        $normalizer = new CallbackNormalizer(function(PropertyVisibility $pv) {
48
            return array('public' => $pv->public);
49
        });
50
51
        $this->assertSame(array(
52
            'public' => 'public',
53
        ), $normalizer(new PropertyVisibility()));
54
    }
55
56
    public function testCallbackNormalizerInvalidCallback()
57
    {
58
        $this->expectException('InvalidArgumentException');
59
        new CallbackNormalizer('invalid');
60
    }
61
}
62