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

NormalizerContainerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 2
cbo 2
dl 72
loc 72
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testAlias() 9 9 1
A testInterface() 11 11 1
A testInheritance() 12 12 1
A testMultipleInterfacesException() 13 13 1
A testInvalidClassOrInterfaceName() 6 6 1
A testAliasForInvalidClass() 6 6 1
A testInvalidHandler() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Thunder\Serializard\Tests;
3
4
use Thunder\Serializard\NormalizerContainer\NormalizerContainer;
5
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9 View Code Duplication
class NormalizerContainerTest 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 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');
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 NormalizerContainer();
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 NormalizerContainer();
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 NormalizerContainer();
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