@@ -22,16 +22,36 @@ class RouteParamsResolverTest extends \PHPUnit_Framework_TestCase
22
22
*/
23
23
protected $ queryParamsResolverMock ;
24
24
25
+ /**
26
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
27
+ */
28
+ protected $ storeMock ;
29
+
25
30
/**
26
31
* @var \Magento\Store\Url\Plugin\RouteParamsResolver
27
32
*/
28
33
protected $ model ;
29
34
35
+ /**
36
+ * @return void
37
+ */
30
38
protected function setUp ()
31
39
{
32
- $ this ->scopeConfigMock = $ this ->getMock ('Magento\Framework\App\Config\ScopeConfigInterface ' );
33
- $ this ->storeManagerMock = $ this ->getMock ('Magento\Store\Model\StoreManagerInterface ' );
34
- $ this ->queryParamsResolverMock = $ this ->getMock ('Magento\Framework\Url\QueryParamsResolverInterface ' );
40
+ $ this ->scopeConfigMock = $ this ->getMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
41
+
42
+ $ this ->storeMock = $ this ->getMockBuilder (\Magento \Store \Model \Store::class)
43
+ ->setMethods (['getCode ' ])
44
+ ->disableOriginalConstructor ()
45
+ ->getMock ();
46
+ $ this ->storeMock ->expects ($ this ->any ())->method ('getCode ' )->willReturn ('custom_store ' );
47
+
48
+ $ this ->storeManagerMock = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class);
49
+ $ this ->storeManagerMock
50
+ ->expects ($ this ->once ())
51
+ ->method ('getStore ' )
52
+ ->willReturn ($ this ->storeMock );
53
+
54
+ $ this ->queryParamsResolverMock = $ this ->getMock (\Magento \Framework \Url \QueryParamsResolverInterface::class);
35
55
$ this ->model = new \Magento \Store \Url \Plugin \RouteParamsResolver (
36
56
$ this ->scopeConfigMock ,
37
57
$ this ->storeManagerMock ,
@@ -40,11 +60,15 @@ protected function setUp()
40
60
}
41
61
42
62
/**
43
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
63
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
64
+ *
65
+ * @return void
44
66
*/
45
- public function testAroundSetRouteParamsScopeInParams ()
67
+ public function testBeforeSetRouteParamsScopeInParams ()
46
68
{
47
69
$ storeCode = 'custom_store ' ;
70
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
71
+
48
72
$ this ->scopeConfigMock
49
73
->expects ($ this ->once ())
50
74
->method ('getValue ' )
@@ -55,33 +79,33 @@ public function testAroundSetRouteParamsScopeInParams()
55
79
)
56
80
->will ($ this ->returnValue (false ));
57
81
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
58
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
59
- /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
60
- $ routeParamsResolverMock = $ this ->getMockBuilder (' Magento\Framework\Url\RouteParamsResolver ' )
82
+
83
+ /** @var \PHPUnit_Framework_MockObject_MockObject $routeResolverMock */
84
+ $ routeResolverMock = $ this ->getMockBuilder (\ Magento \Framework \Url \RouteParamsResolver::class )
61
85
->setMethods (['setScope ' , 'getScope ' ])
62
86
->disableOriginalConstructor ()
63
87
->getMock ();
64
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
65
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
88
+ $ routeResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
89
+ $ routeResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
66
90
67
- $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
91
+ $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
68
92
69
- $ this ->model ->aroundSetRouteParams (
70
- $ routeParamsResolverMock ,
71
- function ($ data , $ unsetOldParams ) {
72
- $ this ->assertArrayNotHasKey ('_scope_to_url ' , $ data , 'This data item should have been unset. ' );
73
- $ this ->assertArrayNotHasKey ('_scope ' , $ data , 'This data item should have been unset. ' );
74
- },
93
+ $ this ->model ->beforeSetRouteParams (
94
+ $ routeResolverMock ,
75
95
$ data
76
96
);
77
97
}
78
98
79
99
/**
80
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
100
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
101
+ *
102
+ * @return void
81
103
*/
82
- public function testAroundSetRouteParamsScopeUseStoreInUrl ()
104
+ public function testBeforeSetRouteParamsScopeUseStoreInUrl ()
83
105
{
84
106
$ storeCode = 'custom_store ' ;
107
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
108
+
85
109
$ this ->scopeConfigMock
86
110
->expects ($ this ->once ())
87
111
->method ('getValue ' )
@@ -91,34 +115,35 @@ public function testAroundSetRouteParamsScopeUseStoreInUrl()
91
115
$ storeCode
92
116
)
93
117
->will ($ this ->returnValue (true ));
118
+
94
119
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
95
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
96
- /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
97
- $ routeParamsResolverMock = $ this ->getMockBuilder (' Magento\Framework\Url\RouteParamsResolver ' )
120
+
121
+ /** @var \PHPUnit_Framework_MockObject_MockObject $routeResolverMock */
122
+ $ routeResolverMock = $ this ->getMockBuilder (\ Magento \Framework \Url \RouteParamsResolver::class )
98
123
->setMethods (['setScope ' , 'getScope ' ])
99
124
->disableOriginalConstructor ()
100
125
->getMock ();
101
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
102
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
126
+ $ routeResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
127
+ $ routeResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
103
128
104
- $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
129
+ $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
105
130
106
- $ this ->model ->aroundSetRouteParams (
107
- $ routeParamsResolverMock ,
108
- function ($ data , $ unsetOldParams ) {
109
- $ this ->assertArrayNotHasKey ('_scope_to_url ' , $ data , 'This data item should have been unset. ' );
110
- $ this ->assertArrayNotHasKey ('_scope ' , $ data , 'This data item should have been unset. ' );
111
- },
131
+ $ this ->model ->beforeSetRouteParams (
132
+ $ routeResolverMock ,
112
133
$ data
113
134
);
114
135
}
115
136
116
137
/**
117
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
138
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
139
+ *
140
+ * @return void
118
141
*/
119
- public function testAroundSetRouteParamsSingleStore ()
142
+ public function testBeforeSetRouteParamsSingleStore ()
120
143
{
121
144
$ storeCode = 'custom_store ' ;
145
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
146
+
122
147
$ this ->scopeConfigMock
123
148
->expects ($ this ->once ())
124
149
->method ('getValue ' )
@@ -129,33 +154,33 @@ public function testAroundSetRouteParamsSingleStore()
129
154
)
130
155
->will ($ this ->returnValue (false ));
131
156
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (true );
132
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
133
- /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
134
- $ routeParamsResolverMock = $ this ->getMockBuilder (' Magento\Framework\Url\RouteParamsResolver ' )
157
+
158
+ /** @var \PHPUnit_Framework_MockObject_MockObject $routeResolverMock */
159
+ $ routeResolverMock = $ this ->getMockBuilder (\ Magento \Framework \Url \RouteParamsResolver::class )
135
160
->setMethods (['setScope ' , 'getScope ' ])
136
161
->disableOriginalConstructor ()
137
162
->getMock ();
138
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
139
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
163
+ $ routeResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
164
+ $ routeResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
140
165
141
166
$ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
142
167
143
- $ this ->model ->aroundSetRouteParams (
144
- $ routeParamsResolverMock ,
145
- function ($ data , $ unsetOldParams ) {
146
- $ this ->assertArrayNotHasKey ('_scope_to_url ' , $ data , 'This data item should have been unset. ' );
147
- $ this ->assertArrayNotHasKey ('_scope ' , $ data , 'This data item should have been unset. ' );
148
- },
168
+ $ this ->model ->beforeSetRouteParams (
169
+ $ routeResolverMock ,
149
170
$ data
150
171
);
151
172
}
152
173
153
174
/**
154
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
175
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
176
+ *
177
+ * @return void
155
178
*/
156
- public function testAroundSetRouteParamsNoScopeInParams ()
179
+ public function testBeforeSetRouteParamsNoScopeInParams ()
157
180
{
158
181
$ storeCode = 'custom_store ' ;
182
+ $ data = ['_scope_to_url ' => true ];
183
+
159
184
$ this ->scopeConfigMock
160
185
->expects ($ this ->once ())
161
186
->method ('getValue ' )
@@ -164,32 +189,22 @@ public function testAroundSetRouteParamsNoScopeInParams()
164
189
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
165
190
$ storeCode
166
191
)
167
- ->will ($ this ->returnValue (false ));
192
+ ->will ($ this ->returnValue (true ));
193
+
168
194
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
169
- /** @var \PHPUnit_Framework_MockObject_MockObject| $routeParamsResolverMock */
170
- $ storeMock = $ this ->getMockBuilder ('Magento\Store\Model\Store ' )
171
- ->setMethods (['getCode ' ])
172
- ->disableOriginalConstructor ()
173
- ->getMock ();
174
- $ storeMock ->expects ($ this ->any ())->method ('getCode ' )->willReturn ($ storeCode );
175
- $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
176
195
177
- $ data = ['_scope_to_url ' => true ];
178
- /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
179
- $ routeParamsResolverMock = $ this ->getMockBuilder ('Magento\Framework\Url\RouteParamsResolver ' )
196
+ /** @var \PHPUnit_Framework_MockObject_MockObject $routeResolverMock */
197
+ $ routeResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
180
198
->setMethods (['setScope ' , 'getScope ' ])
181
199
->disableOriginalConstructor ()
182
200
->getMock ();
183
- $ routeParamsResolverMock ->expects ($ this ->never ())->method ('setScope ' );
184
- $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn (false );
201
+ $ routeResolverMock ->expects ($ this ->never ())->method ('setScope ' );
202
+ $ routeResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn (false );
185
203
186
204
$ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )->with ('___store ' , $ storeCode );
187
205
188
- $ this ->model ->aroundSetRouteParams (
189
- $ routeParamsResolverMock ,
190
- function ($ data , $ unsetOldParams ) {
191
- $ this ->assertArrayNotHasKey ('_scope_to_url ' , $ data , 'This data item should have been unset. ' );
192
- },
206
+ $ this ->model ->beforeSetRouteParams (
207
+ $ routeResolverMock ,
193
208
$ data
194
209
);
195
210
}
0 commit comments