MenuBuilderTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 16.48 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 15
loc 91
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A getEventDispatcher() 0 6 1
A getItem() 0 6 1
A getFactory() 15 15 1
A testGettersAndSetters() 0 18 1
A testCreateMainMenu() 0 9 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 SumoCoders\FrameworkCoreBundle\Tests\Menu;
4
5
use Knp\Menu\FactoryInterface;
6
use Knp\Menu\ItemInterface;
7
use SumoCoders\FrameworkCoreBundle\Menu\MenuBuilder;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
10
class MenuBuilderTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var MenuBuilder
14
     */
15
    protected $menuBuilder;
16
17
    /**
18
     * @inherit
19
     */
20
    protected function setUp()
21
    {
22
        $this->menuBuilder = new MenuBuilder();
23
    }
24
25
    /**
26
     * @inherit
27
     */
28
    protected function tearDown()
29
    {
30
        $this->menuBuilder = null;
31
    }
32
33
    /**
34
     * @return \PHPUnit_Framework_MockObject_MockObject
35
     */
36
    protected function getEventDispatcher()
37
    {
38
        $eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
39
40
        return $eventDispatcher;
41
    }
42
43
    protected function getItem()
44
    {
45
        $item = $this->getMockBuilder(ItemInterface::class)->getMock();
46
47
        return $item;
48
    }
49
50
    /**
51
     * @return \PHPUnit_Framework_MockObject_MockObject
52
     */
53 View Code Duplication
    protected function getFactory()
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...
54
    {
55
        $item = $this->getItem();
56
57
        /** @var \PHPUnit_Framework_MockObject_MockBuilder $factory */
58
        $factory = $this->getMockBuilder(FactoryInterface::class)->getMock();
59
        $factory->method('createItem')
60
            ->will(
61
                $this->returnValue(
62
                    $item
63
                )
64
            );
65
66
        return $factory;
67
    }
68
69
    /**
70
     * Test the getters and setters
71
     */
72
    public function testGettersAndSetters()
73
    {
74
        $eventDispatcher = $this->getEventDispatcher();
75
        $this->menuBuilder->setEventDispatcher($eventDispatcher);
76
        $this->assertEquals(
77
            $eventDispatcher,
78
            $this->menuBuilder->getEventDispatcher(),
79
            'eventDispatcher doesn\'t match'
80
        );
81
82
        $factory = $this->getFactory();
83
        $this->menuBuilder->setFactory($factory);
84
        $this->assertEquals(
85
            $factory,
86
            $this->menuBuilder->getFactory(),
87
            'factory doesn\'t match'
88
        );
89
    }
90
91
    public function testCreateMainMenu()
92
    {
93
        $this->markTestSkipped('I need time to mock this whole thing...');
94
95
        $this->menuBuilder->setFactory($this->getFactory());
96
        $this->menuBuilder->setEventDispatcher($this->getEventDispatcher());
97
98
        $this->menuBuilder->createMainMenu();
99
    }
100
}
101