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

NormalizerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 2 Features 0
Metric Value
dl 0
loc 47
c 2
b 2
f 0
wmc 5
lcom 1
cbo 8
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testReflectionSkip() 0 7 1
A testReflectionInheritance() 0 10 1
A testGetObjectVarsNormalizer() 0 8 1
A testCallbackNormalizer() 0 10 1
A testCallbackNormalizerInvalidCallback() 0 5 1
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