17
17
use Magento \TestFramework \Dependency \Route \RouteMapper ;
18
18
use Magento \TestFramework \Exception \NoSuchActionException ;
19
19
use Magento \Webapi \Model \Config \Converter ;
20
+ use PHPUnit \Framework \Exception ;
20
21
21
22
/**
22
23
* Rule to check the dependencies between modules based on references, getUrl and layout blocks
@@ -113,8 +114,7 @@ public function __construct(
113
114
array $ pluginMap = [],
114
115
array $ whitelists = [],
115
116
ClassScanner $ classScanner = null
116
- )
117
- {
117
+ ) {
118
118
$ this ->_mapRouters = $ mapRouters ;
119
119
$ this ->_mapLayoutBlocks = $ mapLayoutBlocks ;
120
120
$ this ->configReader = $ configReader ;
@@ -416,25 +416,27 @@ private function processStandardUrl(string $path)
416
416
{
417
417
$ pattern = '#(?<route_id>[a-z0-9\-_]{3,}) '
418
418
. '\/?(?<controller_name>[a-z0-9\-_]+)?\/?(?<action_name>[a-z0-9\-_]+)?#i ' ;
419
- if (preg_match ($ pattern , $ path , $ match )) {
420
- $ routeId = $ match ['route_id ' ];
421
- $ controllerName = $ match ['controller_name ' ] ?? UrlInterface::DEFAULT_CONTROLLER_NAME ;
422
- $ actionName = $ match ['action_name ' ] ?? UrlInterface::DEFAULT_ACTION_NAME ;
423
-
424
- return $ this ->routeMapper ->getDependencyByRoutePath (
425
- $ routeId ,
426
- $ controllerName ,
427
- $ actionName
428
- );
419
+ if (!preg_match ($ pattern , $ path , $ match )) {
420
+ throw new NoSuchActionException ('Failed to parse standard url path: ' . $ path );
429
421
}
430
- throw new NoSuchActionException ();
422
+ $ routeId = $ match ['route_id ' ];
423
+ $ controllerName = $ match ['controller_name ' ] ?? UrlInterface::DEFAULT_CONTROLLER_NAME ;
424
+ $ actionName = $ match ['action_name ' ] ?? UrlInterface::DEFAULT_ACTION_NAME ;
425
+
426
+ return $ this ->routeMapper ->getDependencyByRoutePath (
427
+ $ routeId ,
428
+ $ controllerName ,
429
+ $ actionName
430
+ );
431
431
}
432
432
433
433
/**
434
434
* Helper method to get module dependencies used by an API URL
435
435
*
436
436
* @param string $path
437
437
* @return string[]
438
+ *
439
+ * @throws NoSuchActionException
438
440
*/
439
441
private function processApiUrl (string $ path ): array
440
442
{
@@ -459,20 +461,17 @@ private function processApiUrl(string $path): array
459
461
* any method
460
462
*/
461
463
if (preg_match ($ serviceMethodUrlRegex , $ path )) {
462
- $ method = $ methods ['GET ' ]
463
- ?? $ methods ['POST ' ]
464
- ?? $ methods ['PUT ' ]
465
- ?? $ methods ['DELETE ' ];
464
+ $ method = reset ($ methods );
466
465
467
466
$ className = $ method ['service ' ]['class ' ];
468
467
//get module from className
469
468
if (preg_match ('#(?<module>\w+[ \\\]\w+).*# ' , $ className , $ match )) {
470
469
return [$ match ['module ' ]];
471
470
}
472
- break ;
471
+ throw new Exception ( ' Failed to parse class from className ' . $ className ) ;
473
472
}
474
473
}
475
- throw new NoSuchActionException ();
474
+ throw new NoSuchActionException (' Failed to match service with url path: ' . $ path );
476
475
}
477
476
478
477
/**
0 commit comments