5
5
*/
6
6
namespace Magento \Backend \Test \Unit \Model \Menu ;
7
7
8
- /**
9
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
- */
8
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
9
+
11
10
class ConfigTest extends \PHPUnit_Framework_TestCase
12
11
{
13
12
/**
14
13
* @var \PHPUnit_Framework_MockObject_MockObject
15
14
*/
16
- protected $ _cacheInstanceMock ;
17
-
18
- /**
19
- * @var \PHPUnit_Framework_MockObject_MockObject
20
- */
21
- protected $ _directorMock ;
22
-
23
- /**
24
- * @var \PHPUnit_Framework_MockObject_MockObject
25
- */
26
- protected $ _configReaderMock ;
27
-
28
- /**
29
- * @var \PHPUnit_Framework_MockObject_MockObject
30
- */
31
- protected $ _menuFactoryMock ;
15
+ private $ cacheInstanceMock ;
32
16
33
17
/**
34
18
* @var \PHPUnit_Framework_MockObject_MockObject
35
19
*/
36
- protected $ _eventManagerMock ;
20
+ private $ configReaderMock ;
37
21
38
22
/**
39
23
* @var \PHPUnit_Framework_MockObject_MockObject
40
24
*/
41
- protected $ _menuMock ;
25
+ private $ menuMock ;
42
26
43
27
/**
44
28
* @var \PHPUnit_Framework_MockObject_MockObject
45
29
*/
46
- protected $ _menuBuilderMock ;
30
+ private $ menuBuilderMock ;
47
31
48
32
/**
49
33
* @var \PHPUnit_Framework_MockObject_MockObject
50
34
*/
51
- protected $ _logger ;
35
+ private $ logger ;
52
36
53
37
/**
54
38
* @var \Magento\Backend\Model\Menu\Config
55
39
*/
56
- protected $ _model ;
40
+ private $ model ;
57
41
58
42
protected function setUp ()
59
43
{
60
- $ this ->_cacheInstanceMock = $ this ->getMock (
44
+ $ this ->cacheInstanceMock = $ this ->getMock (
61
45
\Magento \Framework \App \Cache \Type \Config::class,
62
46
[],
63
47
[],
64
48
'' ,
65
49
false
66
50
);
67
51
68
- $ this ->_directorMock = $ this ->getMock (
69
- \Magento \Backend \Model \Menu \AbstractDirector::class,
70
- [],
71
- [],
72
- '' ,
73
- false
74
- );
75
-
76
- $ this ->_menuFactoryMock = $ this ->getMock (
52
+ $ menuFactoryMock = $ this ->getMock (
77
53
\Magento \Backend \Model \MenuFactory::class,
78
54
['create ' ],
79
55
[],
80
56
'' ,
81
57
false
82
58
);
83
59
84
- $ this ->_configReaderMock = $ this ->getMock (
60
+ $ this ->configReaderMock = $ this ->getMock (
85
61
\Magento \Backend \Model \Menu \Config \Reader::class,
86
62
[],
87
63
[],
88
64
'' ,
89
65
false
90
66
);
91
67
92
- $ this ->_eventManagerMock = $ this ->getMock (
93
- \Magento \Framework \Event \ManagerInterface::class,
94
- [],
95
- [],
96
- '' ,
97
- false ,
98
- false
99
- );
100
-
101
- $ this ->_logger = $ this ->getMock (\Psr \Log \LoggerInterface::class);
102
-
103
- $ this ->_menuMock = $ this ->getMock (
104
- \Magento \Backend \Model \Menu::class,
105
- [],
106
- [$ this ->getMock (\Psr \Log \LoggerInterface::class)]
107
- );
68
+ $ this ->logger = $ this ->getMock (\Psr \Log \LoggerInterface::class);
108
69
109
- $ this ->_menuBuilderMock = $ this ->getMock (\Magento \Backend \Model \Menu \Builder ::class, [], [], '' , false );
70
+ $ this ->menuMock = $ this ->getMock (\Magento \Backend \Model \Menu::class, [], [], '' , false );
110
71
111
- $ this ->_menuFactoryMock -> expects ( $ this ->any ())-> method ( ' create ' )-> will ( $ this -> returnValue ( $ this -> _menuMock ) );
72
+ $ this ->menuBuilderMock = $ this ->getMock (\ Magento \ Backend \ Model \ Menu \Builder::class, [], [], '' , false );
112
73
113
- $ scopeConfig = $ this ->getMock (\ Magento \ Framework \ App \ Config \ScopeConfigInterface::class) ;
74
+ $ menuFactoryMock -> expects ( $ this ->any ())-> method ( ' create ' )-> will ( $ this -> returnValue ( $ this -> menuMock )); ;
114
75
115
- $ this ->_configReaderMock ->expects ($ this ->any ())->method ('read ' )->will ($ this ->returnValue ([]));
76
+ $ this ->configReaderMock ->expects ($ this ->any ())->method ('read ' )->will ($ this ->returnValue ([]));
116
77
117
78
$ appState = $ this ->getMock (\Magento \Framework \App \State::class, ['getAreaCode ' ], [], '' , false );
118
79
$ appState ->expects (
@@ -123,22 +84,22 @@ protected function setUp()
123
84
$ this ->returnValue (\Magento \Backend \App \Area \FrontNameResolver::AREA_CODE )
124
85
);
125
86
126
- $ this ->_model = new \ Magento \ Backend \ Model \ Menu \ Config (
127
- $ this -> _menuBuilderMock ,
128
- $ this -> _directorMock ,
129
- $ this ->_menuFactoryMock ,
130
- $ this -> _configReaderMock ,
131
- $ this ->_cacheInstanceMock ,
132
- $ this ->_eventManagerMock ,
133
- $ this ->_logger ,
134
- $ scopeConfig ,
135
- $ appState
87
+ $ this ->model = ( new ObjectManager ( $ this ))-> getObject (
88
+ \ Magento \ Backend \ Model \ Menu \Config::class ,
89
+ [
90
+ ' menuBuilder ' => $ this ->menuBuilderMock ,
91
+ ' menuFactory ' => $ menuFactoryMock ,
92
+ ' configReader ' => $ this ->configReaderMock ,
93
+ ' configCacheType ' => $ this ->cacheInstanceMock ,
94
+ ' logger ' => $ this ->logger ,
95
+ ' appState ' => $ appState ,
96
+ ]
136
97
);
137
98
}
138
99
139
100
public function testGetMenuWithCachedObjectReturnsUnserializedObject ()
140
101
{
141
- $ this ->_cacheInstanceMock ->expects (
102
+ $ this ->cacheInstanceMock ->expects (
142
103
$ this ->once ()
143
104
)->method (
144
105
'load '
@@ -148,14 +109,14 @@ public function testGetMenuWithCachedObjectReturnsUnserializedObject()
148
109
$ this ->returnValue ('menu_cache ' )
149
110
);
150
111
151
- $ this ->_menuMock ->expects ($ this ->once ())->method ('unserialize ' )->with ('menu_cache ' );
112
+ $ this ->menuMock ->expects ($ this ->once ())->method ('unserialize ' )->with ('menu_cache ' );
152
113
153
- $ this ->assertEquals ($ this ->_menuMock , $ this ->_model ->getMenu ());
114
+ $ this ->assertEquals ($ this ->menuMock , $ this ->model ->getMenu ());
154
115
}
155
116
156
117
public function testGetMenuWithNotCachedObjectBuidlsObject ()
157
118
{
158
- $ this ->_cacheInstanceMock ->expects (
119
+ $ this ->cacheInstanceMock ->expects (
159
120
$ this ->at (0 )
160
121
)->method (
161
122
'load '
@@ -165,17 +126,17 @@ public function testGetMenuWithNotCachedObjectBuidlsObject()
165
126
$ this ->returnValue (false )
166
127
);
167
128
168
- $ this ->_configReaderMock ->expects ($ this ->once ())->method ('read ' )->will ($ this ->returnValue ([]));
129
+ $ this ->configReaderMock ->expects ($ this ->once ())->method ('read ' )->will ($ this ->returnValue ([]));
169
130
170
- $ this ->_menuBuilderMock ->expects (
131
+ $ this ->menuBuilderMock ->expects (
171
132
$ this ->exactly (1 )
172
133
)->method (
173
134
'getResult '
174
135
)->will (
175
- $ this ->returnValue ($ this ->_menuMock )
136
+ $ this ->returnValue ($ this ->menuMock )
176
137
);
177
138
178
- $ this ->assertEquals ($ this ->_menuMock , $ this ->_model ->getMenu ());
139
+ $ this ->assertEquals ($ this ->menuMock , $ this ->model ->getMenu ());
179
140
}
180
141
181
142
/**
@@ -186,15 +147,15 @@ public function testGetMenuWithNotCachedObjectBuidlsObject()
186
147
public function testGetMenuExceptionLogged ($ expectedException )
187
148
{
188
149
$ this ->setExpectedException ($ expectedException );
189
- $ this ->_menuBuilderMock ->expects (
150
+ $ this ->menuBuilderMock ->expects (
190
151
$ this ->exactly (1 )
191
152
)->method (
192
153
'getResult '
193
154
)->will (
194
155
$ this ->throwException (new $ expectedException ())
195
156
);
196
157
197
- $ this ->_model ->getMenu ();
158
+ $ this ->model ->getMenu ();
198
159
}
199
160
200
161
public function getMenuExceptionLoggedDataProvider ()
@@ -208,17 +169,17 @@ public function getMenuExceptionLoggedDataProvider()
208
169
209
170
public function testGetMenuGenericExceptionIsNotLogged ()
210
171
{
211
- $ this ->_logger ->expects ($ this ->never ())->method ('critical ' );
172
+ $ this ->logger ->expects ($ this ->never ())->method ('critical ' );
212
173
213
- $ this ->_menuBuilderMock ->expects (
174
+ $ this ->menuBuilderMock ->expects (
214
175
$ this ->exactly (1 )
215
176
)->method (
216
177
'getResult '
217
178
)->will (
218
179
$ this ->throwException (new \Exception ())
219
180
);
220
181
try {
221
- $ this ->_model ->getMenu ();
182
+ $ this ->model ->getMenu ();
222
183
} catch (\Exception $ e ) {
223
184
return ;
224
185
}
0 commit comments