Skip to content

Commit 5b65095

Browse files
committed
#28579:DependencyTest does not analyze GraphQL schema files - fixed tests
1 parent e19d807 commit 5b65095

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ protected function setUp(): void
3636
$fileResolverMock = $this->getMockBuilder(
3737
\Magento\Framework\Config\FileResolverInterface::class
3838
)->disableOriginalConstructor()->getMock();
39+
$filePath1 = __DIR__ . '/_files/schemaC.graphqls';
40+
$filePath2 = __DIR__ . '/_files/schemaD.graphqls';
3941
$fileList = [
40-
file_get_contents(__DIR__ . '/_files/schemaC.graphqls'),
41-
file_get_contents(__DIR__ . '/_files/schemaD.graphqls')
42+
$filePath1 => file_get_contents($filePath1),
43+
$filePath2 => file_get_contents($filePath2)
4244
];
4345
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
4446
$graphQlReader = $objectManager->create(

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
28

39
namespace Magento\Test\Integrity\Dependency;
410

@@ -82,11 +88,7 @@ protected function initDeclaredDependencies()
8288
* @return void
8389
* @throws \Exception
8490
*/
85-
protected function presetDependencies(
86-
string $moduleName,
87-
array $packageNames,
88-
string $type
89-
): void
91+
protected function presetDependencies(string $moduleName, array $packageNames, string $type): void
9092
{
9193
$packageNames = array_filter($packageNames, function ($packageName) {
9294
return $this->getModuleName($packageName) ||

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
28

39
namespace Magento\Test\Integrity\Dependency;
410

511
use Magento\Framework\App\Bootstrap;
612

713
/**
8-
* Class GraphQlSchemaDependencyProvider
9-
* @package Magento\Test\Integrity\Dependency
14+
* Provide information on the dependency between the modules according to the GraphQL schema.
15+
*
16+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1017
*/
1118
class GraphQlSchemaDependencyProvider extends DependencyProvider
1219
{
@@ -98,10 +105,11 @@ private function getDependenciesFromSchema(string $moduleName): array
98105

99106
$dependencies = [];
100107

101-
foreach ($schema as $typeName => $type) {
108+
foreach ($schema as $type) {
102109
if (isset($type['module']) && $type['module'] == $moduleName && isset($type['implements'])) {
103-
foreach ($type['implements'] as $interfaceName => $interfaceData) {
104-
$dependOnModule = $schema[$interfaceName]['module'];
110+
$interfaces = array_keys($type['implements']);
111+
foreach ($interfaces as $interface) {
112+
$dependOnModule = $schema[$interface]['module'];
105113
if ($dependOnModule != $moduleName) {
106114
$dependencies[] = $dependOnModule;
107115
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
26

7+
declare(strict_types=1);
38

49
namespace Magento\Test\Integrity;
510

6-
711
use Magento\Framework\App\Utility\Files;
812
use Magento\Framework\Component\ComponentRegistrar;
913
use Magento\Test\Integrity\Dependency\GraphQlSchemaDependencyProvider;

lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\Framework\Component\ComponentRegistrar;
1111
use Magento\Framework\Config\FileResolverInterface;
12-
use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeMetaReaderInterface as TypeReaderComposite;
1312
use Magento\Framework\Config\ReaderInterface;
13+
use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeMetaReaderInterface as TypeReaderComposite;
1414

1515
/**
1616
* Reads *.graphqls files from modules and combines the results as array to be used with a library to configure objects
@@ -67,7 +67,10 @@ public function __construct(
6767
}
6868

6969
/**
70-
* {@inheritdoc}
70+
* @inheritdoc
71+
*
72+
* @param string|null $scope
73+
* @return array
7174
*/
7275
public function read($scope = null) : array
7376
{
@@ -335,8 +338,9 @@ private function addModuleNameToTypes(array $source, string $filePath): array
335338
{
336339
foreach ($source as $typeName => $type) {
337340
if (!isset($type['module']) && (
338-
($type['type'] == 'graphql_interface' && isset($type['typeResolver']))
339-
|| isset($type['implements']))
341+
($type['type'] == 'graphql_interface' && isset($type['typeResolver']))
342+
|| isset($type['implements'])
343+
)
340344
) {
341345
$source[$typeName]['module'] = self::getModuleNameForRelevantFile($filePath);
342346
}

0 commit comments

Comments
 (0)