Completed
Push — master ( 5ba1dc...b85ec4 )
by Tomasz
02:09
created

HydratorContainerTest::testAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
namespace Thunder\Serializard\Tests;
3
4
use Thunder\Serializard\HydratorContainer\HydratorContainer;
5
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9 View Code Duplication
class HydratorContainerTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    public function testAlias()
12
    {
13
        $handlers = new HydratorContainer();
14
        $handlers->add('stdClass', 'std', function() { return 'value'; });
15
        $handlers->addAlias('DateTime', 'stdClass');
16
17
        $this->assertSame('value', call_user_func_array($handlers->getHandler('stdClass'), array()));
18
        $this->assertSame('value', call_user_func_array($handlers->getHandler('DateTime'), array()));
19
    }
20
21
    public function testInterface()
22
    {
23
        $hydrators = new HydratorContainer();
24
        $interfaceName = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface';
25
        $interfaceTypeA = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeA';
26
        $interfaceTypeB = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeB';
27
        $hydrators->add($interfaceName, 'type', function() { return 'type'; });
28
29
        $this->assertSame('type', call_user_func_array($hydrators->getHandler($interfaceTypeA), array()));
30
        $this->assertSame('type', call_user_func_array($hydrators->getHandler($interfaceTypeB), array()));
31
    }
32
33
    public function testInheritance()
34
    {
35
        $hydrators = new HydratorContainer();
36
        $ancestorName = 'Thunder\Serializard\Tests\Fake\FakeUserParentParent';
37
        $parentName = 'Thunder\Serializard\Tests\Fake\FakeUserParent';
38
        $userName = 'Thunder\Serializard\Tests\Fake\FakeUser';
39
        $hydrators->add($ancestorName, 'type', function() { return 'ancestor'; });
40
41
        $this->assertSame('ancestor', call_user_func_array($hydrators->getHandler($ancestorName), array()));
42
        $this->assertSame('ancestor', call_user_func_array($hydrators->getHandler($parentName), array()));
43
        $this->assertSame('ancestor', call_user_func_array($hydrators->getHandler($userName), array()));
44
    }
45
46
    public function testMultipleInterfacesException()
47
    {
48
        $typeInterface = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface';
49
        $typeAnother = 'Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface';
50
        $typeMultiple = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple';
51
52
        $hydrators = new HydratorContainer();
53
        $hydrators->add($typeInterface, 'type', function() { return 'multiple'; });
54
        $hydrators->add($typeAnother, 'type', function() { return 'multiple'; });
55
56
        $this->setExpectedException('RuntimeException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
57
        $hydrators->getHandler($typeMultiple);
58
    }
59
60
    public function testInvalidClassOrInterfaceName()
61
    {
62
        $handlers = new HydratorContainer();
63
        $this->setExpectedException('RuntimeException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
64
        $handlers->add('invalid', 'root', function() {});
65
    }
66
67
    public function testAliasForInvalidClass()
68
    {
69
        $handlers = new HydratorContainer();
70
        $this->setExpectedException('RuntimeException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
71
        $handlers->addAlias('stdClass', 'DateTime');
72
    }
73
74
    public function testInvalidHandler()
75
    {
76
        $handlers = new HydratorContainer();
77
        $this->setExpectedException('RuntimeException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
78
        $handlers->add('stdClass', 'name', 'invalid');
79
    }
80
}
81