Completed
Push — master ( 8bfcf4...9b1d73 )
by Tomasz
04:06
created

HandlerContainerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAlias() 0 11 1
A testInvalidClassOrInterfaceName() 0 6 1
A testExceptionOnMultipleInterfaces() 0 15 1
A testAliasForInvalidClass() 0 6 1
A testInvalidHandler() 0 6 1
1
<?php
2
namespace Thunder\Serializard\Tests;
3
use Thunder\Serializard\Format\ArrayFormat;
4
use Thunder\Serializard\FormatContainer\FormatContainer;
5
use Thunder\Serializard\HandlerContainer\HandlerContainer;
6
use Thunder\Serializard\Serializard;
7
use Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple;
8
9
/**
10
 * @author Tomasz Kowalczyk <[email protected]>
11
 */
12
class HandlerContainerTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testAlias()
15
    {
16
        $handlers = new HandlerContainer();
17
        $handlers->add('stdClass', 'std', function() {
18
            return 'value';
19
        });
20
        $handlers->addAlias('DateTime', 'stdClass');
21
22
        $this->assertSame('value', call_user_func_array($handlers->getHandler('stdClass'), array()));
23
        $this->assertSame('value', call_user_func_array($handlers->getHandler('DateTime'), array()));
24
    }
25
26
    public function testInvalidClassOrInterfaceName()
27
    {
28
        $this->setExpectedException('RuntimeException');
29
        $handlers = new HandlerContainer();
30
        $handlers->add('invalid', 'root', function() {});
31
    }
32
33
    public function testExceptionOnMultipleInterfaces()
34
    {
35
        $handlers = new HandlerContainer();
36
        $handlers->add('Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface', 'root', function() {});
37
        $handlers->add('Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface', 'root', function() {});
38
39
        $normalizers = new HandlerContainer();
40
41
        $formats = new FormatContainer();
42
        $formats->add('array', new ArrayFormat());
43
44
        $serializard = new Serializard($formats, $handlers, $normalizers);
45
        $this->setExpectedException('RuntimeException');
46
        $serializard->serialize(new TypeMultiple(), 'array');
47
    }
48
49
    public function testAliasForInvalidClass()
50
    {
51
        $this->setExpectedException('RuntimeException');
52
        $handlers = new HandlerContainer();
53
        $handlers->addAlias('stdClass', 'DateTime');
54
    }
55
56
    public function testInvalidHandler()
57
    {
58
        $this->setExpectedException('RuntimeException');
59
        $handlers = new HandlerContainer();
60
        $handlers->add('stdClass', 'name', 'invalid');
61
    }
62
}
63