|
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() |
|
|
|
|
|
|
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
|
|
|
|
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.