Skip to content

Commit 0444ee9

Browse files
committed
MC-24057: Implement static dependency analysis for wildcard and API urls
- Refactor exceptions
1 parent 567e7bb commit 0444ee9

File tree

1 file changed

+18
-19
lines changed
  • dev/tests/static/framework/Magento/TestFramework/Dependency

1 file changed

+18
-19
lines changed

dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\TestFramework\Dependency\Route\RouteMapper;
1818
use Magento\TestFramework\Exception\NoSuchActionException;
1919
use Magento\Webapi\Model\Config\Converter;
20+
use PHPUnit\Framework\Exception;
2021

2122
/**
2223
* Rule to check the dependencies between modules based on references, getUrl and layout blocks
@@ -113,8 +114,7 @@ public function __construct(
113114
array $pluginMap = [],
114115
array $whitelists = [],
115116
ClassScanner $classScanner = null
116-
)
117-
{
117+
) {
118118
$this->_mapRouters = $mapRouters;
119119
$this->_mapLayoutBlocks = $mapLayoutBlocks;
120120
$this->configReader = $configReader;
@@ -416,25 +416,27 @@ private function processStandardUrl(string $path)
416416
{
417417
$pattern = '#(?<route_id>[a-z0-9\-_]{3,})'
418418
. '\/?(?<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);
429421
}
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+
);
431431
}
432432

433433
/**
434434
* Helper method to get module dependencies used by an API URL
435435
*
436436
* @param string $path
437437
* @return string[]
438+
*
439+
* @throws NoSuchActionException
438440
*/
439441
private function processApiUrl(string $path): array
440442
{
@@ -459,20 +461,17 @@ private function processApiUrl(string $path): array
459461
* any method
460462
*/
461463
if (preg_match($serviceMethodUrlRegex, $path)) {
462-
$method = $methods['GET']
463-
?? $methods['POST']
464-
?? $methods['PUT']
465-
?? $methods['DELETE'];
464+
$method = reset($methods);
466465

467466
$className = $method['service']['class'];
468467
//get module from className
469468
if (preg_match('#(?<module>\w+[\\\]\w+).*#', $className, $match)) {
470469
return [$match['module']];
471470
}
472-
break;
471+
throw new Exception('Failed to parse class from className' . $className);
473472
}
474473
}
475-
throw new NoSuchActionException();
474+
throw new NoSuchActionException('Failed to match service with url path: ' . $path);
476475
}
477476

478477
/**

0 commit comments

Comments
 (0)