Code Duplication    Length = 72-72 lines in 2 locations

tests/HydratorContainerTest.php 1 location

@@ 9-80 (lines=72) @@
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9
class HydratorContainerTest extends \PHPUnit_Framework_TestCase
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');
57
        $hydrators->getHandler($typeMultiple);
58
    }
59
60
    public function testInvalidClassOrInterfaceName()
61
    {
62
        $handlers = new HydratorContainer();
63
        $this->setExpectedException('RuntimeException');
64
        $handlers->add('invalid', 'root', function() {});
65
    }
66
67
    public function testAliasForInvalidClass()
68
    {
69
        $handlers = new HydratorContainer();
70
        $this->setExpectedException('RuntimeException');
71
        $handlers->addAlias('stdClass', 'DateTime');
72
    }
73
74
    public function testInvalidHandler()
75
    {
76
        $handlers = new HydratorContainer();
77
        $this->setExpectedException('RuntimeException');
78
        $handlers->add('stdClass', 'name', 'invalid');
79
    }
80
}
81

tests/NormalizerContainerTest.php 1 location

@@ 9-80 (lines=72) @@
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9
class NormalizerContainerTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testAlias()
12
    {
13
        $handlers = new NormalizerContainer();
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 NormalizerContainer();
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 NormalizerContainer();
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 NormalizerContainer();
53
        $hydrators->add($typeInterface, 'type', function() { return 'multiple'; });
54
        $hydrators->add($typeAnother, 'type', function() { return 'multiple'; });
55
56
        $this->setExpectedException('RuntimeException');
57
        $hydrators->getHandler($typeMultiple);
58
    }
59
60
    public function testInvalidClassOrInterfaceName()
61
    {
62
        $handlers = new NormalizerContainer();
63
        $this->setExpectedException('RuntimeException');
64
        $handlers->add('invalid', 'root', function() {});
65
    }
66
67
    public function testAliasForInvalidClass()
68
    {
69
        $handlers = new NormalizerContainer();
70
        $this->setExpectedException('RuntimeException');
71
        $handlers->addAlias('stdClass', 'DateTime');
72
    }
73
74
    public function testInvalidHandler()
75
    {
76
        $handlers = new NormalizerContainer();
77
        $this->setExpectedException('RuntimeException');
78
        $handlers->add('stdClass', 'name', 'invalid');
79
    }
80
}
81