Completed
Push — master ( 4ccc94...34cde4 )
by Nicolas
08:38
created

MenuTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 129
Duplicated Lines 34.88 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 3
dl 45
loc 129
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A it_generates_an_empty_menu() 15 15 1
A it_makes_is_an_alias_for_create() 15 15 1
A it_render_is_an_alias_of_get() 15 15 1
A it_can_get_the_instance_of_a_menu() 0 7 1
A it_can_modify_a_menu_instance() 0 11 1
A it_gets_a_partial_for_dropdown_styles() 0 7 1
A it_can_get_all_menus() 0 9 1
A it_can_count_menus() 0 9 1
A it_can_destroy_all_menus() 0 11 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 Nwidart\Menus\Tests;
4
5
use Nwidart\Menus\Menu;
6
use Nwidart\Menus\MenuBuilder;
7
8
class MenuTest extends BaseTestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
9
{
10
    /**
11
     * @var Menu
12
     */
13
    private $menu;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
        $this->menu = app(Menu::class);
19
    }
20
    /** @test */
21 View Code Duplication
    public function it_generates_an_empty_menu()
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
        $this->menu->create('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
        });
25
26
        $expected = <<<TEXT
27
28
<ul class="nav navbar-nav">
29
30
</ul>
31
32
TEXT;
33
34
        self::assertEquals($expected, $this->menu->get('test'));
35
    }
36
37
    /** @test */
38 View Code Duplication
    public function it_makes_is_an_alias_for_create()
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...
39
    {
40
        $this->menu->make('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
        });
42
43
        $expected = <<<TEXT
44
45
<ul class="nav navbar-nav">
46
47
</ul>
48
49
TEXT;
50
51
        self::assertEquals($expected, $this->menu->get('test'));
52
    }
53
54
    /** @test */
55 View Code Duplication
    public function it_render_is_an_alias_of_get()
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...
56
    {
57
        $this->menu->make('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
        });
59
60
        $expected = <<<TEXT
61
62
<ul class="nav navbar-nav">
63
64
</ul>
65
66
TEXT;
67
68
        self::assertEquals($expected, $this->menu->render('test'));
69
    }
70
71
    /** @test */
72
    public function it_can_get_the_instance_of_a_menu()
73
    {
74
        $this->menu->create('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
        });
76
77
        $this->assertInstanceOf(MenuBuilder::class, $this->menu->instance('test'));
78
    }
79
80
    /** @test */
81
    public function it_can_modify_a_menu_instance()
82
    {
83
        $this->menu->create('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84
        });
85
86
        $this->menu->modify('test', function (MenuBuilder $builder) {
87
            $builder->url('hello', 'world');
88
        });
89
90
        $this->assertCount(1, $this->menu->instance('test'));
91
    }
92
93
    /** @test */
94
    public function it_gets_a_partial_for_dropdown_styles()
95
    {
96
        $this->menu->create('test', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
        });
98
99
        $this->assertContains('.dropdown-submenu', $this->menu->style());
100
    }
101
102
    /** @test */
103
    public function it_can_get_all_menus()
104
    {
105
        $this->menu->create('main', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
        });
107
        $this->menu->create('footer', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
        });
109
110
        $this->assertCount(2, $this->menu->all());
111
    }
112
113
    /** @test */
114
    public function it_can_count_menus()
115
    {
116
        $this->menu->create('main', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
        });
118
        $this->menu->create('footer', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
        });
120
121
        $this->assertEquals(2, $this->menu->count());
122
    }
123
124
    /** @test */
125
    public function it_can_destroy_all_menus()
126
    {
127
        $this->menu->create('main', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
128
        });
129
        $this->menu->create('footer', function (MenuBuilder $menu) {
0 ignored issues
show
Unused Code introduced by
The parameter $menu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
        });
131
132
        $this->assertCount(2, $this->menu->all());
133
        $this->menu->destroy();
134
        $this->assertCount(0,  $this->menu->all());
135
    }
136
}
137