|
1
|
|
|
<?php |
|
2
|
|
|
namespace Malezha\Menu\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Malezha\Menu\Contracts\Builder; |
|
5
|
|
|
use Malezha\Menu\Contracts\Menu; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class MenuTest |
|
9
|
|
|
* @package Malezha\Menu\Tests |
|
10
|
|
|
*/ |
|
11
|
|
|
class MenuTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return Menu |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function menuFactory() |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Menu $menu */ |
|
19
|
|
|
$menu = $this->app->make(Menu::class, ['container' => $this->app]); |
|
20
|
|
|
$menu->make('test', function(Builder $builder) { |
|
21
|
|
|
$builder->add('one', 'One', '/one'); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
return $menu; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testFacade() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertInstanceOf(Menu::class, \Menu::getFacadeRoot()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGet() |
|
33
|
|
|
{ |
|
34
|
|
|
$menu = $this->menuFactory(); |
|
35
|
|
|
$builder = $menu->get('test'); |
|
36
|
|
|
$this->assertInstanceOf(Builder::class, $builder); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @expectedException \RuntimeException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testGetException() |
|
43
|
|
|
{ |
|
44
|
|
|
$menu = \Menu::get('test'); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testHas() |
|
48
|
|
|
{ |
|
49
|
|
|
$menu = $this->menuFactory(); |
|
50
|
|
|
$this->assertFalse($menu->has('another')); |
|
51
|
|
|
$this->assertTrue($menu->has('test')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testForget() |
|
55
|
|
|
{ |
|
56
|
|
|
$menu = $this->menuFactory(); |
|
57
|
|
|
$menu->forget('test'); |
|
58
|
|
|
$this->assertAttributeEquals([], 'menuList', $menu); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testRender() |
|
62
|
|
|
{ |
|
63
|
|
|
$menu = $this->menuFactory(); |
|
64
|
|
|
$file = file_get_contents(__DIR__ . '/stub/facade_render.html'); |
|
65
|
|
|
$this->assertEquals($file, $menu->render('test')); |
|
66
|
|
|
} |
|
67
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.