MenuTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 65.33 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 49
loc 75
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testToString() 9 9 1
A testMachineName() 9 9 1
A testName() 9 9 1
A testLocale() 0 9 1
A testItems() 22 22 1
A getItemInstance() 0 4 1
A getMenuInstance() 0 4 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 Alpixel\Bundle\MenuBundle\Tests\Entity;
4
5
use Alpixel\Bundle\MenuBundle\Entity\Item;
6
use Alpixel\Bundle\MenuBundle\Entity\Menu;
7
use Doctrine\Common\Collections\ArrayCollection;
8
9
class MenuTest extends \PHPUnit_Framework_TestCase
10
{
11 View Code Duplication
    public function testToString()
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...
12
    {
13
        $menu = $this->getMenuInstance();
14
        $this->assertNull($menu->__toString());
15
16
        $test = 'Menu principal';
17
        $menu->setMachineName($test);
18
        $this->assertEquals($test, $menu->__toString());
19
    }
20
21 View Code Duplication
    public function testMachineName()
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...
22
    {
23
        $menu = $this->getMenuInstance();
24
        $this->assertNull($menu->getMachineName());
25
26
        $test = 'main';
27
        $menu->setMachineName($test);
28
        $this->assertEquals($test, $menu->getMachineName());
29
    }
30
31 View Code Duplication
    public function testName()
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...
32
    {
33
        $menu = $this->getMenuInstance();
34
        $this->assertNull($menu->getName());
35
36
        $test = 'Menu principal';
37
        $menu->setName($test);
38
        $this->assertEquals($test, $menu->getName());
39
    }
40
41
    public function testLocale()
42
    {
43
        $menu = $this->getMenuInstance();
44
        $this->assertNull($menu->getLocale());
45
46
        $test = 'fr';
47
        $menu->setLocale($test);
48
        $this->assertEquals($test, $menu->getLocale());
49
    }
50
51 View Code Duplication
    public function testItems()
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...
52
    {
53
        $menu = $this->getMenuInstance();
54
        $this->assertInstanceOf(ArrayCollection::class, $menu->getItems());
55
        $this->assertCount(0, $menu->getItems());
56
57
        $menu->setItem($this->getItemInstance());
0 ignored issues
show
Deprecated Code introduced by
The method Alpixel\Bundle\MenuBundle\Entity\Menu::setItem() has been deprecated.

This method has been deprecated.

Loading history...
58
        $this->assertInstanceOf(ArrayCollection::class, $menu->getItems());
59
        $this->assertCount(1, $menu->getItems());
60
61
        $this->assertCount(1, $menu->getItems()->toArray());
62
        $this->assertInstanceOf(Item::class, $menu->getItems()->first());
63
64
        $menu->removeItem($menu->getItems()->first());
65
        $this->assertCount(0, $menu->getItems()->toArray());
66
67
        $collection = new ArrayCollection();
68
        $collection->add($this->getItemInstance());
69
        $collection->add($this->getItemInstance());
70
        $menu->addItems($collection);
71
        $this->assertCount(2, $menu->getItems()->toArray());
72
    }
73
74
    public function getItemInstance()
75
    {
76
        return new Item();
77
    }
78
79
    public function getMenuInstance()
80
    {
81
        return new Menu();
82
    }
83
}
84