@@ -95,21 +95,22 @@ protected function setUp(): void
95
95
96
96
/**
97
97
* @dataProvider matchDataProvider
98
- * @param MockObject|Http $requestMock
98
+ * @param MockObject|\Closure $requestMock
99
99
* @param string $defaultPath
100
100
* @param string $moduleFrontName
101
101
* @param string|null $actionPath
102
102
* @param string|null $actionName
103
103
* @param string|null $moduleName
104
104
*/
105
105
public function testMatch (
106
- MockObject $ requestMock ,
106
+ MockObject | \ Closure $ requestMock ,
107
107
string $ defaultPath ,
108
108
string $ moduleFrontName ,
109
109
?string $ actionPath ,
110
110
?string $ actionName ,
111
111
?string $ moduleName
112
112
) {
113
+ $ requestMock = $ requestMock ($ this );
113
114
$ actionInstance = 'Magento_TestFramework_ActionInstance ' ;
114
115
115
116
$ defaultReturnMap = [
@@ -147,33 +148,45 @@ public function testMatch(
147
148
$ this ->assertEquals ($ actionMock , $ this ->model ->match ($ requestMock ));
148
149
}
149
150
150
- public function matchDataProvider (): array
151
+ protected function getMockForHttpClass ($ moduleFrontName , $ actionPath , $ actionName , $ originalPathInfo )
152
+ {
153
+ $ requestMock = $ this ->createMock (Http::class);
154
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
155
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ($ actionPath );
156
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ($ actionName );
157
+ if ($ moduleFrontName !=null && $ moduleFrontName !='' ) {
158
+ $ requestMock ->expects ($ this ->atLeastOnce ())
159
+ ->method ('getPathInfo ' )
160
+ ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' );
161
+ }
162
+ else {
163
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('' );
164
+ }
165
+
166
+ if ($ originalPathInfo ) {
167
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getOriginalPathInfo ' )->willReturn ('' );
168
+ }
169
+ return $ requestMock ;
170
+ }
171
+
172
+ public static function matchDataProvider (): array
151
173
{
152
174
$ moduleFrontName = 'module_front_name ' ;
153
175
$ actionPath = 'action_path ' ;
154
176
$ actionName = 'action_name ' ;
155
177
$ moduleName = 'module_name ' ;
156
178
157
- $ requestMock = $ this ->createMock (Http::class);
158
- $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
159
- $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ($ actionPath );
160
- $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ($ actionName );
161
- $ requestMock ->expects ($ this ->atLeastOnce ())
162
- ->method ('getPathInfo ' )
163
- ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/key/val/key2/val2/ ' );
164
-
165
- $ emptyRequestMock = $ this ->createMock (Http::class);
166
- $ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
167
- $ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ('' );
168
- $ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ('' );
169
- $ emptyRequestMock ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('' );
170
-
171
- $ emptyRequestMock2 = $ this ->createMock (Http::class);
172
- $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
173
- $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ('' );
174
- $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ('' );
175
- $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('' );
176
- $ emptyRequestMock2 ->expects ($ this ->atLeastOnce ())->method ('getOriginalPathInfo ' )->willReturn ('' );
179
+ $ requestMock = static fn (self $ testCase ) => $ testCase ->getMockForHttpClass (
180
+ $ moduleFrontName , $ actionPath , $ actionName , false
181
+ );
182
+
183
+ $ emptyRequestMock = static fn (self $ testCase ) => $ testCase ->getMockForHttpClass (
184
+ '' , '' , '' , false
185
+ );
186
+
187
+ $ emptyRequestMock2 = static fn (self $ testCase ) => $ testCase ->getMockForHttpClass (
188
+ '' , '' , '' , true
189
+ );
177
190
178
191
return [
179
192
[
@@ -205,21 +218,22 @@ public function matchDataProvider(): array
205
218
206
219
/**
207
220
* @dataProvider matchEmptyActionDataProvider
208
- * @param MockObject|Http $requestMock
221
+ * @param MockObject|\Closure $requestMock
209
222
* @param string $defaultPath
210
223
* @param string $moduleFrontName
211
224
* @param string|null $actionPath
212
225
* @param string|null $actionName
213
226
* @param string|null $moduleName
214
227
*/
215
228
public function testMatchEmptyAction (
216
- MockObject $ requestMock ,
229
+ MockObject | \ Closure $ requestMock ,
217
230
string $ defaultPath ,
218
231
string $ moduleFrontName ,
219
232
?string $ actionPath ,
220
233
?string $ actionName ,
221
234
?string $ moduleName
222
235
) {
236
+ $ requestMock = $ requestMock ($ this );
223
237
$ defaultReturnMap = [
224
238
['module ' , $ moduleFrontName ],
225
239
['controller ' , $ actionPath ],
@@ -240,29 +254,43 @@ public function testMatchEmptyAction(
240
254
$ this ->assertNull ($ this ->model ->match ($ requestMock ));
241
255
}
242
256
243
- public function matchEmptyActionDataProvider (): array
257
+ protected function getMockForHttpClassTwo ($ moduleFrontName , $ actionPath , $ actionName , $ bool )
258
+ {
259
+ $ requestMock = $ this ->createMock (Http::class);
260
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
261
+ if ($ bool ) {
262
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ($ actionPath );
263
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ($ actionName );
264
+ }
265
+ if ($ moduleFrontName !='' ) {
266
+ $ requestMock ->expects ($ this ->atLeastOnce ())
267
+ ->method ('getPathInfo ' )
268
+ ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' );
269
+ }
270
+ else {
271
+ $ requestMock ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('0 ' );
272
+ }
273
+
274
+ return $ requestMock ;
275
+ }
276
+
277
+ public static function matchEmptyActionDataProvider (): array
244
278
{
245
279
$ moduleFrontName = 'module_front_name ' ;
246
280
$ actionPath = 'action_path ' ;
247
281
$ actionName = 'action_name ' ;
248
282
249
- $ requestMock1 = $ this ->createMock (Http::class);
250
- $ requestMock1 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
251
- $ requestMock1 ->expects ($ this ->atLeastOnce ())->method ('getControllerName ' )->willReturn ($ actionPath );
252
- $ requestMock1 ->expects ($ this ->atLeastOnce ())->method ('getActionName ' )->willReturn ($ actionName );
253
- $ requestMock1 ->expects ($ this ->atLeastOnce ())
254
- ->method ('getPathInfo ' )
255
- ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' );
256
-
257
- $ requestMock2 = $ this ->createMock (Http::class);
258
- $ requestMock2 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ($ moduleFrontName );
259
- $ requestMock2 ->expects ($ this ->atLeastOnce ())
260
- ->method ('getPathInfo ' )
261
- ->willReturn ($ moduleFrontName . '/ ' . $ actionPath . '/ ' . $ actionName . '/ ' );
262
-
263
- $ requestMock3 = $ this ->createMock (Http::class);
264
- $ requestMock3 ->expects ($ this ->atLeastOnce ())->method ('getModuleName ' )->willReturn ('' );
265
- $ requestMock3 ->expects ($ this ->atLeastOnce ())->method ('getPathInfo ' )->willReturn ('0 ' );
283
+ $ requestMock1 = static fn (self $ testCase ) => $ testCase ->getMockForHttpClassTwo (
284
+ $ moduleFrontName , $ actionPath , $ actionName , true
285
+ );
286
+
287
+ $ requestMock2 = static fn (self $ testCase ) => $ testCase ->getMockForHttpClassTwo (
288
+ $ moduleFrontName , $ actionPath , $ actionName , false
289
+ );
290
+
291
+ $ requestMock3 = static fn (self $ testCase ) => $ testCase ->getMockForHttpClassTwo (
292
+ '' , '' , '' , false
293
+ );
266
294
267
295
return [
268
296
[
0 commit comments