3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \TestFramework \Dependency ;
7
8
9
+ use Magento \Framework \Config \Reader \Filesystem ;
8
10
use Magento \Framework \Exception \LocalizedException ;
9
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
10
12
use Magento \TestFramework \Dependency \Reader \ClassScanner ;
11
- use \Magento \Webapi \Model \Config \Reader ;
12
13
13
14
/**
14
15
* Test for PhpRule dependency check
@@ -31,7 +32,7 @@ class PhpRuleTest extends \PHPUnit\Framework\TestCase
31
32
private $ classScanner ;
32
33
33
34
/**
34
- * @var Reader
35
+ * @var \PHPUnit\Framework\MockObject\MockObject | Filesystem
35
36
*/
36
37
private $ webApiConfigReader ;
37
38
@@ -51,15 +52,15 @@ protected function setUp(): void
51
52
52
53
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
53
54
$ this ->classScanner = $ this ->createMock (ClassScanner::class);
54
- $ this ->webApiConfigReader = $ this ->objectManagerHelper -> getObject (Reader::class );
55
+ $ this ->webApiConfigReader = $ this ->makeWebApiConfigReaderMock ( );
55
56
56
57
$ this ->model = $ this ->objectManagerHelper ->getObject (
57
58
PhpRule::class,
58
59
[
59
60
'mapRouters ' => $ mapRoutes ,
60
61
'mapLayoutBlocks ' => $ mapLayoutBlocks ,
61
62
'pluginMap ' => $ pluginMap ,
62
- 'webApiConfig ' => $ this ->webApiConfigReader ,
63
+ 'configReader ' => $ this ->webApiConfigReader ,
63
64
'whitelists ' => $ whitelist ,
64
65
'classScanner ' => $ this ->classScanner
65
66
]
@@ -114,7 +115,7 @@ public function getDependencyInfoDataProvider()
114
115
[
115
116
[
116
117
'modules ' => ['Magento\SomeModule ' ],
117
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
118
+ 'type ' => RuleInterface::TYPE_HARD ,
118
119
'source ' => 'Magento\SomeModule\Any\ClassName ' ,
119
120
]
120
121
]
@@ -132,7 +133,7 @@ public function getDependencyInfoDataProvider()
132
133
[
133
134
[
134
135
'modules ' => ['Magento\SomeModule ' ],
135
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
136
+ 'type ' => RuleInterface::TYPE_HARD ,
136
137
'source ' => 'Magento_SomeModule ' ,
137
138
]
138
139
]
@@ -150,7 +151,7 @@ public function getDependencyInfoDataProvider()
150
151
[
151
152
[
152
153
'modules ' => ['Magento\SomeModule ' ],
153
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
154
+ 'type ' => RuleInterface::TYPE_HARD ,
154
155
'source ' => 'Magento\SomeModule\Any\ClassName ' ,
155
156
]
156
157
]
@@ -168,7 +169,7 @@ public function getDependencyInfoDataProvider()
168
169
[
169
170
[
170
171
'modules ' => ['Magento\SomeModule ' ],
171
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
172
+ 'type ' => RuleInterface::TYPE_HARD ,
172
173
'source ' => 'getBlock( \'block.name \') ' ,
173
174
]
174
175
]
@@ -192,7 +193,7 @@ public function getDependencyInfoDataProvider()
192
193
[
193
194
[
194
195
'modules ' => ['Magento\Module2 ' ],
195
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_SOFT ,
196
+ 'type ' => RuleInterface::TYPE_SOFT ,
196
197
'source ' => 'Magento\Module2\Subject ' ,
197
198
]
198
199
],
@@ -204,7 +205,7 @@ public function getDependencyInfoDataProvider()
204
205
[
205
206
[
206
207
'modules ' => ['Magento\Module2 ' ],
207
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_SOFT ,
208
+ 'type ' => RuleInterface::TYPE_SOFT ,
208
209
'source ' => 'Magento\Module2\NotSubject ' ,
209
210
]
210
211
]
@@ -216,7 +217,7 @@ public function getDependencyInfoDataProvider()
216
217
[
217
218
[
218
219
'modules ' => ['Magento\OtherModule ' ],
219
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
220
+ 'type ' => RuleInterface::TYPE_HARD ,
220
221
'source ' => 'Magento\OtherModule\NotSubject ' ,
221
222
]
222
223
]
@@ -259,11 +260,43 @@ public function getDependencyInfoDataCaseGetUrlDataProvider()
259
260
[
260
261
[
261
262
'modules ' => ['Magento\Cms ' ],
262
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
263
+ 'type ' => RuleInterface::TYPE_HARD ,
263
264
'source ' => 'getUrl("cms/index/index" ' ,
264
265
]
265
266
]
266
267
],
268
+ 'getUrl from API of same module ' => [
269
+ 'Magento\Catalog\SomeClass ' ,
270
+ '$this->getUrl("rest/V1/products/3") ' ,
271
+ []
272
+ ],
273
+ 'getUrl from API of different module ' => [
274
+ 'Magento\Backend\SomeClass ' ,
275
+ '$this->getUrl("rest/V1/products/43/options") ' ,
276
+ [
277
+ [
278
+ 'modules ' => ['Magento\Catalog ' ],
279
+ 'type ' => RuleInterface::TYPE_HARD ,
280
+ 'source ' => 'getUrl("rest/V1/products/43/options" '
281
+ ]
282
+ ],
283
+ ],
284
+ //Skip processing routeid wildcards
285
+ 'getUrl from routeid wildcard in controller ' => [
286
+ 'Magento\Catalog\Controller\ControllerName\SomeClass ' ,
287
+ '$this->getUrl("*/Invalid/*") ' ,
288
+ []
289
+ ],
290
+ 'getUrl from wildcard url within ignored Block class ' => [
291
+ 'Magento\Cms\Block\SomeClass ' ,
292
+ '$this->getUrl("Catalog/*/View") ' ,
293
+ []
294
+ ],
295
+ 'getUrl from wildcard url for ControllerName ' => [
296
+ 'Magento\Catalog\Controller\Category\IGNORE ' ,
297
+ '$this->getUrl("Catalog/*/View") ' ,
298
+ []
299
+ ],
267
300
];
268
301
}
269
302
@@ -297,6 +330,11 @@ public function getDependencyInfoDataCaseGetUrlExceptionDataProvider()
297
330
'$this->getUrl("someModule") ' ,
298
331
new LocalizedException (__ ('Invalid URL path: %1 ' , 'somemodule/index/index ' )),
299
332
],
333
+ 'getUrl from unknown wildcard path ' => [
334
+ 'Magento\Catalog\Controller\Product\View ' ,
335
+ '$this->getUrl("Catalog/*/INVALID") ' ,
336
+ new LocalizedException (__ ('Invalid URL path: %1 ' , 'catalog/product/invalid ' )),
337
+ ],
300
338
];
301
339
}
302
340
@@ -332,7 +370,7 @@ public function getDefaultModelDependencyDataProvider()
332
370
[
333
371
[
334
372
'modules ' => ['Magento\SomeModule ' ],
335
- 'type ' => \ Magento \ TestFramework \ Dependency \ RuleInterface::TYPE_HARD ,
373
+ 'type ' => RuleInterface::TYPE_HARD ,
336
374
'source ' => 'getBlock( \'block.name \') ' ,
337
375
]
338
376
],
@@ -363,4 +401,29 @@ private function getModuleFromClass(string $class): string
363
401
$ moduleNameLength = strpos ($ class , '\\' , strpos ($ class , '\\' ) + 1 );
364
402
return substr ($ class , 0 , $ moduleNameLength );
365
403
}
404
+
405
+ /**
406
+ * Returns an example list of services that would be parsed via the configReader
407
+ */
408
+ private function makeWebApiConfigReaderMock ()
409
+ {
410
+ $ services = [ 'routes ' => [
411
+ '/V1/products/:sku ' => [
412
+ 'GET ' => ['service ' => [
413
+ 'class ' => 'Magento\Catalog\Api\ProductRepositoryInterface ' ,
414
+ 'method ' => 'get '
415
+ ] ],
416
+ 'PUT ' => ['service ' => [
417
+ 'class ' => 'Magento\Catalog\Api\ProductRepositoryInterface ' ,
418
+ 'method ' => 'save '
419
+ ] ],
420
+ ],
421
+ 'V1/products/:sku/options ' => ['GET ' => ['service ' => [
422
+ 'class ' => 'Magento\Catalog\Api\ProductCustomOptionRepositoryInterface ' ,
423
+ 'method ' => 'getList '
424
+ ] ] ]
425
+ ] ];
426
+
427
+ return $ this ->createConfiguredMock (Filesystem::class, [ 'read ' => $ services ]);
428
+ }
366
429
}
0 commit comments