Completed
Push — master ( a70ca2...b8c2a5 )
by Daniel
14:22
created

RpcRouterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 49.18 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 5
dl 30
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testRouterDump() 13 13 1
A testRouterRpcService() 17 17 1
A getServiceContainer() 0 20 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
3
namespace Cmobi\RabbitmqBundle\Tests\Routing;
4
5
use Cmobi\RabbitmqBundle\Routing\Method;
6
use Cmobi\RabbitmqBundle\Routing\MethodCollection;
7
use Cmobi\RabbitmqBundle\Routing\MethodRouter;
8
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
9
10
class RpcRouterTest extends BaseTestCase
11
{
12 View Code Duplication
    public function testRouterDump()
0 ignored issues
show
Duplication introduced by
This method 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...
13
    {
14
        $methodCollection = new MethodCollection();
15
        $method = new Method(null, 'foo');
16
        $methodCollection->add('foo', $method);
17
        $sc = $this->getServiceContainer($methodCollection);
18
        $sc->setParameter('parameter.foo', 'foo');
19
20
        $router = new MethodRouter($sc, 'foo');
21
        $parameters = $router->match('foo');
22
23
        $this->assertEquals('foo', $parameters['_method']);
24
    }
25
26 View Code Duplication
    public function testRouterRpcService()
0 ignored issues
show
Duplication introduced by
This method 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...
27
    {
28
        $methodCollection = new MethodCollection();
29
        $method = new Method(null, 'foo');
30
        $methodCollection->add('foo', $method);
31
        $sc = $this->getServiceContainer($methodCollection);
32
        $sc->setParameter('parameter.foo', 'foo');
33
34
        $router = new MethodRouter($sc, 'foo');
35
36
        $method = $router->getMethodCollection()->get('foo');
37
38
        $this->assertEquals(
39
            'foo',
40
            $method->getName()
41
        );
42
    }
43
44
    /**
45
     * @param MethodCollection $methods
46
     *
47
     * @return \Symfony\Component\DependencyInjection\Container
48
     */
49
    private function getServiceContainer(MethodCollection $methods)
50
    {
51
        $loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
52
53
        $loader
54
            ->expects($this->any())
55
            ->method('load')
56
            ->will($this->returnValue($methods))
57
        ;
58
59
        $sc = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get'));
60
61
        $sc
62
            ->expects($this->once())
63
            ->method('get')
64
            ->will($this->returnValue($loader))
65
        ;
66
67
        return $sc;
68
    }
69
70
}