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 |
||
| 10 | class ContainerTest extends TestCase |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var \JumpGate\Menu\Container |
||
| 14 | */ |
||
| 15 | protected $menu; |
||
| 16 | |||
| 17 | 16 | public function setUp() |
|
| 23 | |||
| 24 | /** @test */ |
||
| 25 | 1 | public function it_adds_a_menu() |
|
| 31 | |||
| 32 | /** @test */ |
||
| 33 | 1 | public function it_checks_if_menu_exists_returns_false() |
|
| 37 | |||
| 38 | /** @test */ |
||
| 39 | 1 | public function it_checks_if_menu_exists_returns_true() |
|
| 46 | |||
| 47 | /** @test */ |
||
| 48 | 1 | public function it_checks_if_has_links_return_true() |
|
| 49 | { |
||
| 50 | 1 | $this->menu->getMenu('menuName') |
|
| 51 | 1 | ->link('slug', function () { |
|
| 52 | // |
||
| 53 | 1 | }); |
|
| 54 | |||
| 55 | 1 | $this->assertTrue($this->menu->hasLinks('menuName')); |
|
| 56 | 1 | } |
|
| 57 | |||
| 58 | /** @test */ |
||
| 59 | 1 | public function it_checks_if_has_links_return_false() |
|
| 66 | |||
| 67 | /** @test */ |
||
| 68 | 1 | public function it_checks_set_active() |
|
| 69 | { |
||
| 70 | 1 | $this->menu->setActive('slug'); |
|
| 71 | |||
| 72 | 1 | $this->assertEquals('slug', $this->menu->getActive()); |
|
| 73 | } |
||
| 74 | |||
| 75 | /** @test */ |
||
| 76 | 1 | public function it_checks_if_get_menu_returns_the_existing_menu() |
|
| 77 | { |
||
| 78 | 1 | $this->menu->getMenu('menuName') |
|
| 79 | 1 | ->link('slug', function () { |
|
| 80 | // |
||
| 81 | 1 | }); |
|
| 82 | |||
| 83 | 1 | $this->assertCount(1, $this->menu->getMenu('menuName')->links); |
|
| 84 | 1 | } |
|
| 85 | |||
| 86 | /** |
||
| 87 | * @test |
||
| 88 | * |
||
| 89 | * @expectedException Exception |
||
| 90 | * @expectedExceptionMessage Menu test not found. |
||
| 91 | */ |
||
| 92 | 1 | public function it_throws_an_exception_if_render_cant_find_the_menu() |
|
| 96 | |||
| 97 | /** @test */ |
||
| 98 | 1 | public function it_can_render_a_menu() |
|
| 99 | { |
||
| 107 | |||
| 108 | /** @test */ |
||
| 109 | 1 | public function it_sets_active_items() |
|
| 122 | |||
| 123 | /** @test */ |
||
| 124 | 1 | View Code Duplication | public function it_sets_active_items_in_dropdown() |
| 140 | |||
| 141 | /** @test */ |
||
| 142 | 1 | View Code Duplication | public function it_sets_active_items_in_dropdown_without_parentage() |
| 160 | |||
| 161 | /** @test */ |
||
| 162 | 1 | public function it_tests_insert_before_link() |
|
| 176 | |||
| 177 | /** @test */ |
||
| 178 | 1 | View Code Duplication | public function it_tests_insert_before_dropdown() |
| 194 | |||
| 195 | /** @test */ |
||
| 196 | 1 | View Code Duplication | public function it_tests_insert_after_link() |
| 218 | |||
| 219 | /** @test */ |
||
| 220 | 1 | public function it_tests_insert_after_dropdown() |
|
| 242 | } |
||
| 243 |