Skip to content

Commit d64ef3d

Browse files
committed
#28579:DependencyTest does not analyze GraphQL schema files - fixed reaquested changes
1 parent 8c4cff4 commit d64ef3d

File tree

7 files changed

+120
-77
lines changed

7 files changed

+120
-77
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88

99
namespace Magento\Test\Integrity;
1010

11-
use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\Utility\AggregateInvoker;
1213
use Magento\Framework\App\Utility\Files;
1314
use Magento\Framework\Component\ComponentRegistrar;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider;
17+
use Magento\TestFramework\Inspection\Exception as InspectionException;
18+
use PHPUnit\Framework\TestCase;
1419

1520
/**
1621
* Class DeclarativeDependencyTest
1722
* Test for undeclared dependencies in declarative schema
1823
*/
19-
class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase
24+
class DeclarativeDependencyTest extends TestCase
2025
{
2126
/**
2227
* @var DeclarativeSchemaDependencyProvider
@@ -26,7 +31,7 @@ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase
2631
/**
2732
* Sets up data
2833
*
29-
* @throws \Magento\TestFramework\Inspection\Exception
34+
* @throws InspectionException
3035
*/
3136
protected function setUp(): void
3237
{
@@ -38,16 +43,16 @@ protected function setUp(): void
3843
'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.'
3944
);
4045
}
41-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
46+
$objectManager = ObjectManager::getInstance();
4247
$this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class);
4348
}
4449

4550
/**
46-
* @throws \Magento\Framework\Exception\LocalizedException
51+
* @throws LocalizedException
4752
*/
4853
public function testUndeclaredDependencies()
4954
{
50-
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
55+
$invoker = new AggregateInvoker($this);
5156
$invoker(
5257
/**
5358
* Check undeclared modules dependencies for specified file
@@ -109,7 +114,7 @@ private function prepareFiles(array $files): array
109114
*/
110115
private function getErrorMessage(string $id): string
111116
{
112-
$decodedId = $this->dependencyProvider->decodeDependencyId($id);
117+
$decodedId = DeclarativeSchemaDependencyProvider::decodeDependencyId($id);
113118
$entityType = $decodedId['entityType'];
114119
if ($entityType === DeclarativeSchemaDependencyProvider::SCHEMA_ENTITY_TABLE) {
115120
$message = sprintf(
@@ -133,14 +138,13 @@ private function getErrorMessage(string $id): string
133138
*
134139
* @param string $file
135140
* @return mixed
136-
* @throws \Magento\TestFramework\Inspection\Exception
141+
* @throws InspectionException
137142
*/
138143
private function readJsonFile(string $file, bool $asArray = false)
139144
{
140145
$decodedJson = json_decode(file_get_contents($file), $asArray);
141146
if (null == $decodedJson) {
142-
//phpcs:ignore Magento2.Exceptions.DirectThrow
143-
throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file");
147+
throw new InspectionException("Invalid Json: $file");
144148
}
145149

146150
return $decodedJson;

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\App\Utility\Files;
1212
use Magento\Framework\Component\ComponentRegistrar;
1313
use Magento\Framework\Setup\Declaration\Schema\Config\Converter;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\TestFramework\Inspection\Exception as InspectionException;
1416

1517
/**
1618
* Provide information on the dependency between the modules according to the declarative schema.
@@ -22,22 +24,22 @@ class DeclarativeSchemaDependencyProvider
2224
/**
2325
* Declarative name for table entity of the declarative schema.
2426
*/
25-
const SCHEMA_ENTITY_TABLE = 'table';
27+
public const SCHEMA_ENTITY_TABLE = 'table';
2628

2729
/**
2830
* Declarative name for column entity of the declarative schema.
2931
*/
30-
const SCHEMA_ENTITY_COLUMN = 'column';
32+
public const SCHEMA_ENTITY_COLUMN = 'column';
3133

3234
/**
3335
* Declarative name for constraint entity of the declarative schema.
3436
*/
35-
const SCHEMA_ENTITY_CONSTRAINT = 'constraint';
37+
public const SCHEMA_ENTITY_CONSTRAINT = 'constraint';
3638

3739
/**
3840
* Declarative name for index entity of the declarative schema.
3941
*/
40-
const SCHEMA_ENTITY_INDEX = 'index';
42+
public const SCHEMA_ENTITY_INDEX = 'index';
4143

4244
/**
4345
* @var array
@@ -55,10 +57,9 @@ class DeclarativeSchemaDependencyProvider
5557
private $dependencyProvider;
5658

5759
/**
58-
* DeclarativeSchemaDependencyProvider constructor.
59-
* @param \Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider
60+
* @param DependencyProvider $dependencyProvider
6061
*/
61-
public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider)
62+
public function __construct(DependencyProvider $dependencyProvider)
6263
{
6364
$this->dependencyProvider = $dependencyProvider;
6465
}
@@ -116,7 +117,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array
116117
*
117118
* @param string $module
118119
* @return string
119-
* @throws \Magento\Framework\Exception\LocalizedException
120+
* @throws LocalizedException
120121
*/
121122
private function getSchemaFileNameByModuleName(string $module): string
122123
{
@@ -194,7 +195,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar
194195
* Retrieve declarative schema declaration.
195196
*
196197
* @return array
197-
* @throws \Magento\Framework\Exception\LocalizedException
198+
* @throws LocalizedException
198199
*/
199200
private function getDeclarativeSchema(): array
200201
{
@@ -249,7 +250,7 @@ private function getDeclarativeSchema(): array
249250
* @param string $entityType
250251
* @param null|string $entityName
251252
* @return array
252-
* @throws \Magento\Framework\Exception\LocalizedException
253+
* @throws LocalizedException
253254
*/
254255
private function resolveEntityDependencies(string $tableName, string $entityType, ?string $entityName = null): array
255256
{
@@ -332,7 +333,7 @@ private function getDependenciesFromFiles($file)
332333
*
333334
* @param array $moduleDeclaration
334335
* @return array
335-
* @throws \Magento\Framework\Exception\LocalizedException
336+
* @throws LocalizedException
336337
*/
337338
private function getDisabledDependencies(array $moduleDeclaration): array
338339
{
@@ -445,7 +446,7 @@ private function getConstraintDependencies(array $moduleDeclaration): array
445446
* @param string $tableName
446447
* @param array $entityDeclaration
447448
* @return array
448-
* @throws \Exception
449+
* @throws LocalizedException
449450
*/
450451
private function getComplexDependency(string $tableName, array $entityDeclaration): array
451452
{
@@ -471,7 +472,7 @@ private function getComplexDependency(string $tableName, array $entityDeclaratio
471472
*
472473
* @param array $moduleDeclaration
473474
* @return array
474-
* @throws \Exception
475+
* @throws LocalizedException
475476
*/
476477
private function getIndexDependencies(array $moduleDeclaration): array
477478
{
@@ -541,9 +542,11 @@ public static function decodeDependencyId(string $id): array
541542
/**
542543
* Collect module dependencies.
543544
*
544-
* @param string $currentModuleName
545+
* @param $currentModuleName
545546
* @param array $dependencies
546547
* @return array
548+
* @throws InspectionException
549+
* @throws LocalizedException
547550
*/
548551
private function collectDependencies($currentModuleName, $dependencies = []): array
549552
{
@@ -562,11 +565,13 @@ private function collectDependencies($currentModuleName, $dependencies = []): ar
562565
}
563566

564567
/**
565-
* Collect a module dependency.
568+
* Collect a module dependency.
566569
*
567570
* @param string $dependencyName
568571
* @param array $dependency
569572
* @param string $currentModule
573+
* @throws LocalizedException
574+
* @throws InspectionException
570575
*/
571576
private function collectDependency(
572577
string $dependencyName,

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@
1010

1111
use Magento\Framework\App\Utility\Files;
1212
use Magento\Framework\Component\ComponentRegistrar;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Config\Composer\Package;
15+
use Magento\TestFramework\Inspection\Exception as InspectionException;
1316

1417
class DependencyProvider
1518
{
1619
/**
1720
* Types of dependency between modules.
1821
*/
19-
const TYPE_HARD = 'hard';
22+
public const TYPE_HARD = 'hard';
2023

2124
/**
2225
* The identifier of dependency for mapping.
2326
*/
24-
const MAP_TYPE_DECLARED = 'declared';
27+
public const MAP_TYPE_DECLARED = 'declared';
2528

2629
/**
2730
* The identifier of dependency for mapping.
2831
*/
29-
const MAP_TYPE_FOUND = 'found';
32+
public const MAP_TYPE_FOUND = 'found';
3033

3134
/**
3235
* @var array
@@ -39,14 +42,9 @@ class DependencyProvider
3942
private $packageModuleMapping = [];
4043

4144
/**
42-
* DependencyProvider constructor.
43-
* @throws \Magento\Framework\Exception\LocalizedException
44-
* @throws \Magento\TestFramework\Inspection\Exception
45+
* @var bool
4546
*/
46-
public function __construct()
47-
{
48-
$this->initDeclaredDependencies();
49-
}
47+
private $isInited = false;
5048

5149
/**
5250
* Add dependency map items.
@@ -55,9 +53,14 @@ public function __construct()
5553
* @param $type
5654
* @param $mapType
5755
* @param $dependencies
56+
* @throws LocalizedException
57+
* @throws InspectionException
5858
*/
5959
public function addDependencies(string $module, string $type, string $mapType, array $dependencies)
6060
{
61+
if (!$this->isInited) {
62+
$this->initDeclaredDependencies();
63+
}
6164
$this->mapDependencies[$module][$type][$mapType] = array_merge_recursive(
6265
$this->getDeclaredDependencies($module, $type, $mapType),
6366
$dependencies
@@ -71,24 +74,30 @@ public function addDependencies(string $module, string $type, string $mapType, a
7174
* @param $type
7275
* @param $mapType
7376
* @return array
77+
* @throws LocalizedException
78+
* @throws InspectionException
7479
*/
7580
public function getDeclaredDependencies(string $module, string $type, string $mapType): array
7681
{
82+
if (!$this->isInited) {
83+
$this->initDeclaredDependencies();
84+
}
7785
return $this->mapDependencies[$module][$type][$mapType] ?? [];
7886
}
7987

8088
/**
8189
* Initialise map of dependencies.
8290
*
83-
* @throws \Magento\TestFramework\Inspection\Exception
84-
* @throws \Magento\Framework\Exception\LocalizedException
91+
* @throws InspectionException
92+
* @throws LocalizedException
8593
*/
8694
private function initDeclaredDependencies()
8795
{
96+
$this->isInited = true;
8897
if (empty($this->mapDependencies)) {
8998
$jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false);
9099
foreach ($jsonFiles as $file) {
91-
$json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file));
100+
$json = new Package($this->readJsonFile($file));
92101
$moduleName = $this->convertModuleName($json->get('name'));
93102
$require = array_keys((array)$json->get('require'));
94103
$this->presetDependencies($moduleName, $require, self::TYPE_HARD);
@@ -104,8 +113,8 @@ private function initDeclaredDependencies()
104113
* @param string $type
105114
*
106115
* @return void
107-
* @throws \Magento\TestFramework\Inspection\Exception
108-
* @throws \Magento\Framework\Exception\LocalizedException
116+
* @throws InspectionException
117+
* @throws LocalizedException
109118
*/
110119
private function presetDependencies(string $moduleName, array $packageNames, string $type): void
111120
{
@@ -127,8 +136,8 @@ private function presetDependencies(string $moduleName, array $packageNames, str
127136
/**
128137
* @param string $jsonName
129138
* @return string
130-
* @throws \Magento\TestFramework\Inspection\Exception
131-
* @throws \Magento\Framework\Exception\LocalizedException
139+
* @throws InspectionException
140+
* @throws LocalizedException
132141
*/
133142
private function convertModuleName(string $jsonName): string
134143
{
@@ -158,13 +167,13 @@ private function convertModuleName(string $jsonName): string
158167
*
159168
* @param string $file
160169
* @return mixed
161-
* @throws \Magento\TestFramework\Inspection\Exception
170+
* @throws InspectionException
162171
*/
163172
private function readJsonFile(string $file, bool $asArray = false)
164173
{
165174
$decodedJson = json_decode(file_get_contents($file), $asArray);
166175
if (null == $decodedJson) {
167-
throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file");
176+
throw new InspectionException("Invalid Json: $file");
168177
}
169178

170179
return $decodedJson;
@@ -175,8 +184,8 @@ private function readJsonFile(string $file, bool $asArray = false)
175184
*
176185
* @param string $packageName
177186
* @return null|string
178-
* @throws \Magento\TestFramework\Inspection\Exception
179-
* @throws \Magento\Framework\Exception\LocalizedException
187+
* @throws InspectionException
188+
* @throws LocalizedException
180189
*/
181190
private function getModuleName(string $packageName): ?string
182191
{
@@ -187,8 +196,8 @@ private function getModuleName(string $packageName): ?string
187196
* Returns package name on module name mapping.
188197
*
189198
* @return array
190-
* @throws \Magento\TestFramework\Inspection\Exception
191-
* @throws \Magento\Framework\Exception\LocalizedException
199+
* @throws InspectionException
200+
* @throws LocalizedException
192201
*/
193202
private function getPackageModuleMapping(): array
194203
{

0 commit comments

Comments
 (0)