Skip to content

Commit e76f1c5

Browse files
committed
#28579:DependencyTest does not analyze GraphQL schema files - added requested changes
1 parent b6ae25b commit e76f1c5

File tree

7 files changed

+152
-143
lines changed

7 files changed

+152
-143
lines changed

dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase
2525
/**
2626
* Sets up data
2727
*
28-
* @throws \Exception
28+
* @throws \Magento\TestFramework\Inspection\Exception
2929
*/
3030
protected function setUp(): void
3131
{
@@ -37,11 +37,12 @@ protected function setUp(): void
3737
'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.'
3838
);
3939
}
40-
$this->dependencyProvider = new DeclarativeSchemaDependencyProvider();
40+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
41+
$this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class);
4142
}
4243

4344
/**
44-
* @throws \Exception
45+
* @throws \Magento\Framework\Exception\LocalizedException
4546
*/
4647
public function testUndeclaredDependencies()
4748
{
@@ -131,14 +132,14 @@ private function getErrorMessage(string $id): string
131132
*
132133
* @param string $file
133134
* @return mixed
134-
* @throws \Exception
135+
* @throws \Magento\TestFramework\Inspection\Exception
135136
*/
136137
private function readJsonFile(string $file, bool $asArray = false)
137138
{
138139
$decodedJson = json_decode(file_get_contents($file), $asArray);
139140
if (null == $decodedJson) {
140141
//phpcs:ignore Magento2.Exceptions.DirectThrow
141-
throw new \Exception("Invalid Json: $file");
142+
throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file");
142143
}
143144

144145
return $decodedJson;

dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1919
*/
20-
class DeclarativeSchemaDependencyProvider extends DependencyProvider
20+
class DeclarativeSchemaDependencyProvider
2121
{
2222
/**
2323
* Declarative name for table entity of the declarative schema.
@@ -49,6 +49,16 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider
4949
*/
5050
private $moduleSchemaFileMapping = [];
5151

52+
/**
53+
* @var DependencyProvider
54+
*/
55+
private $dependencyProvider;
56+
57+
public function __construct(DependencyProvider $dependencyProvider)
58+
{
59+
$this->dependencyProvider = $dependencyProvider;
60+
}
61+
5262
/**
5363
* Provide declared dependencies between modules based on the declarative schema configuration.
5464
*
@@ -58,10 +68,14 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider
5868
*/
5969
public function getDeclaredExistingModuleDependencies(string $moduleName): array
6070
{
61-
$this->initDeclaredDependencies();
71+
$this->dependencyProvider->initDeclaredDependencies();
6272
$dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName));
6373
$dependencies = $this->filterSelfDependency($moduleName, $dependencies);
64-
$declared = $this->getDeclaredDependencies($moduleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED);
74+
$declared = $this->dependencyProvider->getDeclaredDependencies(
75+
$moduleName,
76+
DependencyProvider::TYPE_HARD,
77+
DependencyProvider::MAP_TYPE_DECLARED
78+
);
6579

6680
$existingDeclared = [];
6781
foreach ($dependencies as $dependency) {
@@ -89,7 +103,7 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array
89103
*/
90104
public function getUndeclaredModuleDependencies(string $moduleName): array
91105
{
92-
$this->initDeclaredDependencies();
106+
$this->dependencyProvider->initDeclaredDependencies();
93107
$dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName));
94108
$dependencies = $this->filterSelfDependency($moduleName, $dependencies);
95109
return $this->collectDependencies($moduleName, $dependencies);
@@ -100,7 +114,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array
100114
*
101115
* @param string $module
102116
* @return string
103-
* @throws \Exception
117+
* @throws \Magento\Framework\Exception\LocalizedException
104118
*/
105119
private function getSchemaFileNameByModuleName(string $module): string
106120
{
@@ -128,10 +142,10 @@ private function getSchemaFileNameByModuleName(string $module): string
128142
* @param array $dependencies
129143
* @return array
130144
*/
131-
private function filterSelfDependency(string $moduleName, array $dependencies):array
145+
private function filterSelfDependency(string $moduleName, array $dependencies): array
132146
{
133147
foreach ($dependencies as $id => $modules) {
134-
$decodedId = $this->decodeDependencyId($id);
148+
$decodedId = self::decodeDependencyId($id);
135149
$entityType = $decodedId['entityType'];
136150
if ($entityType === self::SCHEMA_ENTITY_TABLE || $entityType === "column") {
137151
if (array_search($moduleName, $modules) !== false) {
@@ -178,7 +192,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar
178192
* Retrieve declarative schema declaration.
179193
*
180194
* @return array
181-
* @throws \Exception
195+
* @throws \Magento\Framework\Exception\LocalizedException
182196
*/
183197
private function getDeclarativeSchema(): array
184198
{
@@ -201,10 +215,9 @@ private function getDeclarativeSchema(): array
201215
array_push($tableDeclaration['modules'], $moduleName);
202216
$moduleDeclaration = array_replace_recursive(
203217
$moduleDeclaration,
204-
[self::SCHEMA_ENTITY_TABLE =>
205-
[
206-
$tableName => $tableDeclaration,
207-
]
218+
[self::SCHEMA_ENTITY_TABLE => [
219+
$tableName => $tableDeclaration,
220+
]
208221
]
209222
);
210223
foreach ($entityTypes as $entityType) {
@@ -213,11 +226,9 @@ private function getDeclarativeSchema(): array
213226
}
214227
$moduleDeclaration = array_replace_recursive(
215228
$moduleDeclaration,
216-
[self::SCHEMA_ENTITY_TABLE =>
217-
[
218-
$tableName =>
219-
$this->addModuleAssigment($tableDeclaration, $entityType, $moduleName)
220-
]
229+
[self::SCHEMA_ENTITY_TABLE => [
230+
$tableName => $this->addModuleAssigment($tableDeclaration, $entityType, $moduleName)
231+
]
221232
]
222233
);
223234
}
@@ -236,7 +247,7 @@ private function getDeclarativeSchema(): array
236247
* @param string $entityType
237248
* @param null|string $entityName
238249
* @return array
239-
* @throws \Exception
250+
* @throws \Magento\Framework\Exception\LocalizedException
240251
*/
241252
private function resolveEntityDependencies(string $tableName, string $entityType, ?string $entityName = null): array
242253
{
@@ -319,7 +330,7 @@ private function getDependenciesFromFiles($file)
319330
*
320331
* @param array $moduleDeclaration
321332
* @return array
322-
* @throws \Exception
333+
* @throws \Magento\Framework\Exception\LocalizedException
323334
*/
324335
private function getDisabledDependencies(array $moduleDeclaration): array
325336
{
@@ -532,7 +543,7 @@ public static function decodeDependencyId(string $id): array
532543
* @param array $dependencies
533544
* @return array
534545
*/
535-
private function collectDependencies($currentModuleName, $dependencies = [])
546+
private function collectDependencies($currentModuleName, $dependencies = []): array
536547
{
537548
if (empty($dependencies)) {
538549
return [];
@@ -541,7 +552,11 @@ private function collectDependencies($currentModuleName, $dependencies = [])
541552
$this->collectDependency($dependencyName, $dependency, $currentModuleName);
542553
}
543554

544-
return $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_FOUND);
555+
return $this->dependencyProvider->getDeclaredDependencies(
556+
$currentModuleName,
557+
DependencyProvider::TYPE_HARD,
558+
DependencyProvider::MAP_TYPE_FOUND
559+
);
545560
}
546561

547562
/**
@@ -556,31 +571,22 @@ private function collectDependency(
556571
array $dependency,
557572
string $currentModule
558573
) {
559-
$declared = $this->getDeclaredDependencies($currentModule, self::TYPE_HARD, self::MAP_TYPE_DECLARED);
574+
$declared = $this->dependencyProvider->getDeclaredDependencies(
575+
$currentModule,
576+
DependencyProvider::TYPE_HARD,
577+
DependencyProvider::MAP_TYPE_DECLARED
578+
);
560579
$checkResult = array_intersect($declared, $dependency);
561580

562581
if (empty($checkResult)) {
563-
$this->addDependencies(
582+
$this->dependencyProvider->addDependencies(
564583
$currentModule,
565-
self::TYPE_HARD,
566-
self::MAP_TYPE_FOUND,
584+
DependencyProvider::TYPE_HARD,
585+
DependencyProvider::MAP_TYPE_FOUND,
567586
[
568587
$dependencyName => $dependency,
569588
]
570589
);
571590
}
572591
}
573-
574-
/**
575-
* Retrieve array of dependency items.
576-
*
577-
* @param $module
578-
* @param $type
579-
* @param $mapType
580-
* @return array
581-
*/
582-
protected function getDeclaredDependencies(string $module, string $type, string $mapType)
583-
{
584-
return $this->mapDependencies[$module][$type][$mapType] ?? [];
585-
}
586592
}

0 commit comments

Comments
 (0)