Skip to content

Commit 80c731b

Browse files
authored
ENGCOM-7795: #28579:DependencyTest does not analyze GraphQL schema… #28747
2 parents dd10f7a + f82ed7d commit 80c731b

File tree

10 files changed

+685
-263
lines changed

10 files changed

+685
-263
lines changed

app/code/Magento/SwatchesGraphQl/composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"php": "~7.3.0||~7.4.0",
77
"magento/framework": "*",
88
"magento/module-swatches": "*",
9-
"magento/module-catalog": "*"
10-
},
11-
"suggest": {
9+
"magento/module-catalog": "*",
1210
"magento/module-catalog-graph-ql": "*"
1311
},
1412
"license": [

dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ protected function setUp(): void
4747
$fileResolverMock = $this->getMockBuilder(
4848
\Magento\Framework\Config\FileResolverInterface::class
4949
)->disableOriginalConstructor()->getMock();
50+
$filePath1 = __DIR__ . '/../_files/schemaA.graphqls';
51+
$filePath2 = __DIR__ . '/../_files/schemaB.graphqls';
5052
$fileList = [
51-
file_get_contents(__DIR__ . '/../_files/schemaA.graphqls'),
52-
file_get_contents(__DIR__ . '/../_files/schemaB.graphqls')
53+
$filePath1 => file_get_contents($filePath1),
54+
$filePath2 => file_get_contents($filePath2)
5355
];
5456
$fileResolverMock->expects($this->any())->method('get')->willReturn($fileList);
5557
$graphQlReader = $this->objectManager->create(
@@ -219,31 +221,25 @@ function ($a, $b) {
219221
}
220222
//Checks to make sure that the given description exists in the expectedOutput array
221223
$this->assertArrayHasKey(
222-
223-
array_search(
224-
'Comment for empty PhysicalProductInterface',
225-
array_column($expectedOutput, 'description')
226-
),
227-
$expectedOutput
228-
224+
array_search(
225+
'Comment for empty PhysicalProductInterface',
226+
array_column($expectedOutput, 'description')
227+
),
228+
$expectedOutput
229229
);
230230
$this->assertArrayHasKey(
231-
232-
array_search(
233-
'Comment for empty Enum',
234-
array_column($expectedOutput, 'description')
235-
),
236-
$expectedOutput
237-
231+
array_search(
232+
'Comment for empty Enum',
233+
array_column($expectedOutput, 'description')
234+
),
235+
$expectedOutput
238236
);
239237
$this->assertArrayHasKey(
240-
241-
array_search(
242-
'Comment for SearchResultPageInfo',
243-
array_column($expectedOutput, 'description')
244-
),
245-
$expectedOutput
246-
238+
array_search(
239+
'Comment for SearchResultPageInfo',
240+
array_column($expectedOutput, 'description')
241+
),
242+
$expectedOutput
247243
);
248244
}
249245
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ 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(
4547
\Magento\Framework\GraphQlSchemaStitching\GraphQlReader::class,
4648
['fileResolver' => $fileResolverMock]
4749
);
4850
$reader = $objectManager->create(
51+
// phpstan:ignore
4952
\Magento\Framework\GraphQlSchemaStitching\Reader::class,
5053
['readers' => ['graphql_reader' => $graphQlReader]]
5154
);
5255
$data = $objectManager->create(
56+
// phpstan:ignore
5357
\Magento\Framework\GraphQl\Config\Data ::class,
5458
['reader' => $reader]
5559
);

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +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
22+
* Test for undeclared dependencies in declarative schema
1723
*/
18-
class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase
24+
class DeclarativeDependencyTest extends TestCase
1925
{
2026
/**
2127
* @var DeclarativeSchemaDependencyProvider
@@ -25,7 +31,7 @@ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase
2531
/**
2632
* Sets up data
2733
*
28-
* @throws \Exception
34+
* @throws InspectionException
2935
*/
3036
protected function setUp(): void
3137
{
@@ -37,15 +43,16 @@ protected function setUp(): void
3743
'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.'
3844
);
3945
}
40-
$this->dependencyProvider = new DeclarativeSchemaDependencyProvider();
46+
$objectManager = ObjectManager::getInstance();
47+
$this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class);
4148
}
4249

4350
/**
44-
* @throws \Exception
51+
* @throws LocalizedException
4552
*/
4653
public function testUndeclaredDependencies()
4754
{
48-
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
55+
$invoker = new AggregateInvoker($this);
4956
$invoker(
5057
/**
5158
* Check undeclared modules dependencies for specified file
@@ -107,7 +114,7 @@ private function prepareFiles(array $files): array
107114
*/
108115
private function getErrorMessage(string $id): string
109116
{
110-
$decodedId = $this->dependencyProvider->decodeDependencyId($id);
117+
$decodedId = DeclarativeSchemaDependencyProvider::decodeDependencyId($id);
111118
$entityType = $decodedId['entityType'];
112119
if ($entityType === DeclarativeSchemaDependencyProvider::SCHEMA_ENTITY_TABLE) {
113120
$message = sprintf(
@@ -131,14 +138,13 @@ private function getErrorMessage(string $id): string
131138
*
132139
* @param string $file
133140
* @return mixed
134-
* @throws \Exception
141+
* @throws InspectionException
135142
*/
136143
private function readJsonFile(string $file, bool $asArray = false)
137144
{
138145
$decodedJson = json_decode(file_get_contents($file), $asArray);
139146
if (null == $decodedJson) {
140-
//phpcs:ignore Magento2.Exceptions.DirectThrow
141-
throw new \Exception("Invalid Json: $file");
147+
throw new InspectionException("Invalid Json: $file");
142148
}
143149

144150
return $decodedJson;

0 commit comments

Comments
 (0)