From 64b806ffd2ef7f9fdf90efe927541f6c27d8db42 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Tue, 16 Jun 2020 21:59:15 +0300 Subject: [PATCH 01/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - added tests and missing dependency for SwatchesGraphQl module --- .../Magento/SwatchesGraphQl/composer.json | 4 +- composer.lock | 2 +- .../DeclarativeSchemaDependencyProvider.php | 179 +-------------- .../Dependency/DependencyProvider.php | 205 ++++++++++++++++++ .../GraphQlSchemaDependencyProvider.php | 141 ++++++++++++ .../Magento/Test/Integrity/DependencyTest.php | 5 +- .../Test/Integrity/GraphQlDependencyTest.php | 123 +++++++++++ .../GraphQlSchemaStitching/GraphQlReader.php | 63 +++++- 8 files changed, 538 insertions(+), 184 deletions(-) create mode 100644 dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php create mode 100644 dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php create mode 100644 dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php diff --git a/app/code/Magento/SwatchesGraphQl/composer.json b/app/code/Magento/SwatchesGraphQl/composer.json index 383575302e6ae..1b98b4044a2ff 100644 --- a/app/code/Magento/SwatchesGraphQl/composer.json +++ b/app/code/Magento/SwatchesGraphQl/composer.json @@ -6,9 +6,7 @@ "php": "~7.3.0||~7.4.0", "magento/framework": "*", "magento/module-swatches": "*", - "magento/module-catalog": "*" - }, - "suggest": { + "magento/module-catalog": "*", "magento/module-catalog-graph-ql": "*" }, "license": [ diff --git a/composer.lock b/composer.lock index 6a47e7e44ab69..6a6c945b6416b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e86af25d9a4a1942c437cca58f9f1efb", + "content-hash": "f3674961f96b48fdd025a6c94610c8eb", "packages": [ { "name": "colinmollenhour/cache-backend-file", diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index 965bc6184144b..332e1b88a53fe 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -17,23 +17,8 @@ * * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ -class DeclarativeSchemaDependencyProvider +class DeclarativeSchemaDependencyProvider extends DependencyProvider { - /** - * Types of dependency between modules. - */ - const TYPE_HARD = 'hard'; - - /** - * The identifier of dependency for mapping. - */ - const MAP_TYPE_DECLARED = 'declared'; - - /** - * The identifier of dependency for mapping. - */ - const MAP_TYPE_FOUND = 'found'; - /** * Declarative name for table entity of the declarative schema. */ @@ -54,21 +39,11 @@ class DeclarativeSchemaDependencyProvider */ const SCHEMA_ENTITY_INDEX = 'index'; - /** - * @var array - */ - private $mapDependencies = []; - /** * @var array */ private $dbSchemaDeclaration = []; - /** - * @var array - */ - private $packageModuleMapping = []; - /** * @var array */ @@ -145,42 +120,6 @@ private function getSchemaFileNameByModuleName(string $module): string return $this->moduleSchemaFileMapping[$module] ?? ''; } - /** - * Initialise map of dependencies. - * - * @throws \Exception - */ - private function initDeclaredDependencies() - { - if (empty($this->mapDependencies)) { - $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); - foreach ($jsonFiles as $file) { - $json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file)); - $moduleName = $this->convertModuleName($json->get('name')); - $require = array_keys((array)$json->get('require')); - $this->presetDependencies($moduleName, $require, self::TYPE_HARD); - } - } - } - - /** - * Read data from json file. - * - * @param string $file - * @return mixed - * @throws \Exception - */ - private function readJsonFile(string $file, bool $asArray = false) - { - $decodedJson = json_decode(file_get_contents($file), $asArray); - if (null == $decodedJson) { - //phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Exception("Invalid Json: $file"); - } - - return $decodedJson; - } - /** * Remove self dependencies. * @@ -629,74 +568,6 @@ private function collectDependency( } } - /** - * Add dependencies to dependency list. - * - * @param string $moduleName - * @param array $packageNames - * @param string $type - * - * @return void - * @throws \Exception - */ - private function presetDependencies( - string $moduleName, - array $packageNames, - string $type - ): void { - $packageNames = array_filter($packageNames, function ($packageName) { - return $this->getModuleName($packageName) || - 0 === strpos($packageName, 'magento/') && 'magento/magento-composer-installer' != $packageName; - }); - - foreach ($packageNames as $packageName) { - $this->addDependencies( - $moduleName, - $type, - self::MAP_TYPE_DECLARED, - [$this->convertModuleName($packageName)] - ); - } - } - - /** - * Returns package name on module name mapping. - * - * @return array - * @throws \Exception - */ - private function getPackageModuleMapping(): array - { - if (!$this->packageModuleMapping) { - $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); - - $packageModuleMapping = []; - foreach ($jsonFiles as $file) { - $moduleXml = simplexml_load_file(dirname($file) . '/etc/module.xml'); - $moduleName = str_replace('_', '\\', (string)$moduleXml->module->attributes()->name); - $composerJson = $this->readJsonFile($file); - $packageName = $composerJson->name; - $packageModuleMapping[$packageName] = $moduleName; - } - - $this->packageModuleMapping = $packageModuleMapping; - } - - return $this->packageModuleMapping; - } - - /** - * Retrieve Magento style module name. - * - * @param string $packageName - * @return null|string - * @throws \Exception - */ - private function getModuleName(string $packageName): ?string - { - return $this->getPackageModuleMapping()[$packageName] ?? null; - } - /** * Retrieve array of dependency items. * @@ -705,54 +576,8 @@ private function getModuleName(string $packageName): ?string * @param $mapType * @return array */ - private function getDeclaredDependencies(string $module, string $type, string $mapType) + protected function getDeclaredDependencies(string $module, string $type, string $mapType) { return $this->mapDependencies[$module][$type][$mapType] ?? []; } - - /** - * Add dependency map items. - * - * @param $module - * @param $type - * @param $mapType - * @param $dependencies - */ - protected function addDependencies(string $module, string $type, string $mapType, array $dependencies) - { - $this->mapDependencies[$module][$type][$mapType] = array_merge_recursive( - $this->getDeclaredDependencies($module, $type, $mapType), - $dependencies - ); - } - - /** - * Converts a composer json component name into the Magento Module form. - * - * @param string $jsonName The name of a composer json component or dependency e.g. 'magento/module-theme' - * @return string The corresponding Magento Module e.g. 'Magento\Theme' - * @throws \Exception - */ - private function convertModuleName(string $jsonName): string - { - $moduleName = $this->getModuleName($jsonName); - if ($moduleName) { - return $moduleName; - } - - if (strpos($jsonName, 'magento/magento') !== false - || strpos($jsonName, 'magento/framework') !== false - ) { - $moduleName = str_replace('/', "\t", $jsonName); - $moduleName = str_replace('framework-', "Framework\t", $moduleName); - $moduleName = str_replace('-', ' ', $moduleName); - $moduleName = ucwords($moduleName); - $moduleName = str_replace("\t", '\\', $moduleName); - $moduleName = str_replace(' ', '', $moduleName); - } else { - $moduleName = $jsonName; - } - - return $moduleName; - } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php new file mode 100644 index 0000000000000..a29e39a31b9e5 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php @@ -0,0 +1,205 @@ +mapDependencies)) { + $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); + foreach ($jsonFiles as $file) { + $json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file)); + $moduleName = $this->convertModuleName($json->get('name')); + $require = array_keys((array)$json->get('require')); + $this->presetDependencies($moduleName, $require, self::TYPE_HARD); + } + } + } + + /** + * Add dependencies to dependency list. + * + * @param string $moduleName + * @param array $packageNames + * @param string $type + * + * @return void + * @throws \Exception + */ + protected function presetDependencies( + string $moduleName, + array $packageNames, + string $type + ): void + { + $packageNames = array_filter($packageNames, function ($packageName) { + return $this->getModuleName($packageName) || + 0 === strpos($packageName, 'magento/') && 'magento/magento-composer-installer' != $packageName; + }); + + foreach ($packageNames as $packageName) { + $this->addDependencies( + $moduleName, + $type, + self::MAP_TYPE_DECLARED, + [$this->convertModuleName($packageName)] + ); + } + } + + /** + * @param string $jsonName + * @return string + * @throws \Exception + */ + protected function convertModuleName(string $jsonName): string + { + $moduleName = $this->getModuleName($jsonName); + if ($moduleName) { + return $moduleName; + } + + if (strpos($jsonName, 'magento/magento') !== false + || strpos($jsonName, 'magento/framework') !== false + ) { + $moduleName = str_replace('/', "\t", $jsonName); + $moduleName = str_replace('framework-', "Framework\t", $moduleName); + $moduleName = str_replace('-', ' ', $moduleName); + $moduleName = ucwords($moduleName); + $moduleName = str_replace("\t", '\\', $moduleName); + $moduleName = str_replace(' ', '', $moduleName); + } else { + $moduleName = $jsonName; + } + + return $moduleName; + } + + /** + * Read data from json file. + * + * @param string $file + * @return mixed + * @throws \Exception + */ + protected function readJsonFile(string $file, bool $asArray = false) + { + $decodedJson = json_decode(file_get_contents($file), $asArray); + if (null == $decodedJson) { + //phpcs:ignore Magento2.Exceptions.DirectThrow + throw new \Exception("Invalid Json: $file"); + } + + return $decodedJson; + } + + /** + * Retrieve Magento style module name. + * + * @param string $packageName + * @return null|string + * @throws \Exception + */ + protected function getModuleName(string $packageName): ?string + { + return $this->getPackageModuleMapping()[$packageName] ?? null; + } + + /** + * Returns package name on module name mapping. + * + * @return array + * @throws \Exception + */ + protected function getPackageModuleMapping(): array + { + if (!$this->packageModuleMapping) { + $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); + + $packageModuleMapping = []; + foreach ($jsonFiles as $file) { + $moduleXml = simplexml_load_file(dirname($file) . '/etc/module.xml'); + $moduleName = str_replace('_', '\\', (string)$moduleXml->module->attributes()->name); + $composerJson = $this->readJsonFile($file); + $packageName = $composerJson->name; + $packageModuleMapping[$packageName] = $moduleName; + } + + $this->packageModuleMapping = $packageModuleMapping; + } + + return $this->packageModuleMapping; + } + + /** + * Add dependency map items. + * + * @param $module + * @param $type + * @param $mapType + * @param $dependencies + */ + protected function addDependencies(string $module, string $type, string $mapType, array $dependencies) + { + $this->mapDependencies[$module][$type][$mapType] = array_merge_recursive( + $this->getDeclaredDependencies($module, $type, $mapType), + $dependencies + ); + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php new file mode 100644 index 0000000000000..f210813c797c4 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -0,0 +1,141 @@ +getGraphQlSchemaDeclaration(); + } + + /** + * Provide declared dependencies between modules based on the declarative schema configuration. + * + * @param string $moduleName + * @return array + * @throws \Exception + */ + public function getDeclaredExistingModuleDependencies(string $moduleName): array + { + $this->initDeclaredDependencies(); + $dependencies = $this->getDependenciesFromSchema($moduleName); + $declared = $this->getDeclaredDependencies($moduleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + return array_unique(array_values(array_intersect($declared, $dependencies))); + } + + /** + * Provide undeclared dependencies between modules based on the declarative schema configuration. + * + * [ + * $dependencyId => [$module1, $module2, $module3 ...], + * ... + * ] + * + * @param string $moduleName + * @return array + * @throws \Exception + */ + public function getUndeclaredModuleDependencies(string $moduleName): array + { + $this->initDeclaredDependencies(); + $dependencies = $this->getDependenciesFromSchema($moduleName); + return $this->collectDependencies($moduleName, $dependencies); + } + + /** + * Retrieve array of dependency items. + * + * @param $module + * @param $type + * @param $mapType + * @return array + */ + protected function getDeclaredDependencies(string $module, string $type, string $mapType): array + { + return $this->mapDependencies[$module][$type][$mapType] ?? []; + } + + /** + * Get parsed GraphQl schema + * + * @return array + */ + private function getGraphQlSchemaDeclaration(): array + { + if (!$this->parsedSchema) { + $objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager(); + $reader = $objectManager->create(\Magento\Framework\GraphQlSchemaStitching\GraphQlReader::class); + $this->parsedSchema = $reader->read(); + } + + return $this->parsedSchema; + } + + /** + * Get dependencies from GraphQl schema + * + * @param string $moduleName + * @return array + */ + private function getDependenciesFromSchema(string $moduleName): array + { + $schema = $this->parsedSchema; + + $dependencies = []; + + foreach ($schema as $typeName => $type) { + if (isset($type['module']) && $type['module'] == $moduleName && isset($type['implements'])) { + foreach ($type['implements'] as $interfaceName => $interfaceData) { + $dependOnModule = $schema[$interfaceName]['module']; + if ($dependOnModule != $moduleName) { + $dependencies[] = $dependOnModule; + } + } + + } + } + return array_unique($dependencies); + } + + /** + * Collect module dependencies. + * + * @param string $currentModuleName + * @param array $dependencies + * @return array + */ + private function collectDependencies(string $currentModuleName, array $dependencies = []): array + { + if (empty($dependencies)) { + return []; + } + $declared = $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + $checkResult = array_intersect($declared, $dependencies); + + if (empty($checkResult)) { + $this->addDependencies( + $currentModuleName, + self::TYPE_HARD, + self::MAP_TYPE_FOUND, + [$currentModuleName => $dependencies] + ); + } + + return $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_FOUND); + } +} diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php index 6711de91200dd..5653069564e99 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php @@ -12,6 +12,7 @@ use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Exception\LocalizedException; use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider; +use Magento\Test\Integrity\Dependency\GraphQlSchemaDependencyProvider; use Magento\TestFramework\Dependency\DbRule; use Magento\TestFramework\Dependency\DiRule; use Magento\TestFramework\Dependency\LayoutRule; @@ -783,6 +784,7 @@ function (&$moduleName) { public function collectRedundant() { $schemaDependencyProvider = new DeclarativeSchemaDependencyProvider(); + $graphQlSchemaDependencyProvider = new GraphQlSchemaDependencyProvider(); foreach (array_keys(self::$mapDependencies) as $module) { $declared = $this->_getDependencies($module, self::TYPE_HARD, self::MAP_TYPE_DECLARED); @@ -790,7 +792,8 @@ public function collectRedundant() $found = array_merge( $this->_getDependencies($module, self::TYPE_HARD, self::MAP_TYPE_FOUND), $this->_getDependencies($module, self::TYPE_SOFT, self::MAP_TYPE_FOUND), - $schemaDependencyProvider->getDeclaredExistingModuleDependencies($module) + $schemaDependencyProvider->getDeclaredExistingModuleDependencies($module), + $graphQlSchemaDependencyProvider->getDeclaredExistingModuleDependencies($module) ); $found['Magento\Framework'] = 'Magento\Framework'; $this->_setDependencies($module, self::TYPE_HARD, self::MAP_TYPE_REDUNDANT, array_diff($declared, $found)); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php new file mode 100644 index 0000000000000..c9684a9a4be76 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php @@ -0,0 +1,123 @@ +readJsonFile($root . '/composer.json', true); + if (preg_match('/magento\/project-*/', $rootJson['name']) == 1) { + // The Dependency test is skipped for vendor/magento build + self::markTestSkipped( + 'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.' + ); + } + $this->dependencyProvider = new GraphQlSchemaDependencyProvider(); + } + + /** + * @throws \Exception + */ + public function testUndeclaredDependencies() + { + $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this); + $invoker( + /** + * Check undeclared modules dependencies for specified file + * + * @param string $fileType + * @param string $file + */ + function ($file) { + $componentRegistrar = new ComponentRegistrar(); + $foundModuleName = ''; + foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) { + if (strpos($file, $moduleDir . '/') !== false) { + $foundModuleName = str_replace('_', '\\', $moduleName); + break; + } + } + if (empty($foundModuleName)) { + return; + } + + $undeclaredDependency = $this->dependencyProvider->getUndeclaredModuleDependencies($foundModuleName); + + $result = []; + foreach ($undeclaredDependency as $name => $modules) { + $modules = array_unique($modules); + $result[] = $this->getErrorMessage($name) . "\n" . implode("\t\n", $modules) . "\n"; + } + if (!empty($result)) { + $this->fail( + 'Module ' . $moduleName . ' has undeclared dependencies: ' . "\n" . implode("\t\n", $result) + ); + } + }, + $this->prepareFiles(Files::init()->getDbSchemaFiles('schema.graphqls')) + ); + } + + /** + * Convert file list to data provider structure. + * + * @param string[] $files + * @return array + */ + private function prepareFiles(array $files): array + { + $result = []; + foreach ($files as $relativePath => $file) { + $absolutePath = reset($file); + $result[$relativePath] = [$absolutePath]; + } + return $result; + } + + /** + * Retrieve error message for dependency. + * + * @param string $id + * @return string + */ + private function getErrorMessage(string $id): string + { + return sprintf('%s has undeclared dependency on one of the following modules:', $id); + } + + /** + * Read data from json file. + * + * @param string $file + * @return mixed + * @throws \Exception + */ + private function readJsonFile(string $file, bool $asArray = false) + { + $decodedJson = json_decode(file_get_contents($file), $asArray); + if (null == $decodedJson) { + //phpcs:ignore Magento2.Exceptions.DirectThrow + throw new \Exception("Invalid Json: $file"); + } + + return $decodedJson; + } +} diff --git a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php index 91387d7b98469..fc922bced9003 100644 --- a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php +++ b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php @@ -7,6 +7,7 @@ namespace Magento\Framework\GraphQlSchemaStitching; +use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Config\FileResolverInterface; use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeMetaReaderInterface as TypeReaderComposite; use Magento\Framework\Config\ReaderInterface; @@ -42,6 +43,11 @@ class GraphQlReader implements ReaderInterface */ private $defaultScope; + /** + * @var ComponentRegistrar + */ + private static $componentRegistrar; + /** * @param FileResolverInterface $fileResolver * @param TypeReaderComposite $typeReader @@ -76,7 +82,7 @@ public function read($scope = null) : array * Compatible with @see GraphQlReader::parseTypes */ $knownTypes = []; - foreach ($schemaFiles as $partialSchemaContent) { + foreach ($schemaFiles as $filePath => $partialSchemaContent) { $partialSchemaTypes = $this->parseTypes($partialSchemaContent); // Keep declarations from current partial schema, add missing declarations from all previously read schemas @@ -84,8 +90,8 @@ public function read($scope = null) : array $schemaContent = implode("\n", $knownTypes); $partialResults = $this->readPartialTypes($schemaContent); - $results = array_replace_recursive($results, $partialResults); + $results = $this->addModuleNameToTypes($results, $filePath); } $results = $this->copyInterfaceFieldsToConcreteTypes($results); @@ -285,4 +291,57 @@ private function removePlaceholderFromResults(array $partialResults) : array } return $partialResults; } + + /** + * Get a module name by file path + * + * @param string $file + * @return string + */ + private static function getModuleNameForRelevantFile($file) + { + if (!isset(self::$componentRegistrar)) { + self::$componentRegistrar = new ComponentRegistrar(); + } + // Validates file when it belongs to default themes + foreach (self::$componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themeDir) { + if (strpos($file, $themeDir . '/') !== false) { + return ''; + } + } + + $foundModuleName = ''; + foreach (self::$componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) { + if (strpos($file, $moduleDir . '/') !== false) { + $foundModuleName = str_replace('_', '\\', $moduleName); + break; + } + } + if (empty($foundModuleName)) { + return ''; + } + + return $foundModuleName; + } + + /** + * Add a module name to types + * + * @param array $source + * @param string $filePath + * @return array + */ + private function addModuleNameToTypes(array $source, string $filePath): array + { + foreach ($source as $typeName => $type) { + if (!isset($type['module']) && ( + ($type['type'] == 'graphql_interface' && isset($type['typeResolver'])) + || isset($type['implements'])) + ) { + $source[$typeName]['module'] = self::getModuleNameForRelevantFile($filePath); + } + } + + return $source; + } } From 5b65095b557102c98d90530e8b0e4b388e16c190 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Wed, 17 Jun 2020 15:00:57 +0300 Subject: [PATCH 02/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - fixed tests --- .../Framework/GraphQl/GraphQlConfigTest.php | 6 ++++-- .../Dependency/DependencyProvider.php | 12 +++++++----- .../GraphQlSchemaDependencyProvider.php | 18 +++++++++++++----- .../Test/Integrity/GraphQlDependencyTest.php | 6 +++++- .../GraphQlSchemaStitching/GraphQlReader.php | 12 ++++++++---- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php index 5d4047b1456d5..5f62888596348 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php @@ -36,9 +36,11 @@ protected function setUp(): void $fileResolverMock = $this->getMockBuilder( \Magento\Framework\Config\FileResolverInterface::class )->disableOriginalConstructor()->getMock(); + $filePath1 = __DIR__ . '/_files/schemaC.graphqls'; + $filePath2 = __DIR__ . '/_files/schemaD.graphqls'; $fileList = [ - file_get_contents(__DIR__ . '/_files/schemaC.graphqls'), - file_get_contents(__DIR__ . '/_files/schemaD.graphqls') + $filePath1 => file_get_contents($filePath1), + $filePath2 => file_get_contents($filePath2) ]; $fileResolverMock->expects($this->any())->method('get')->willReturn($fileList); $graphQlReader = $objectManager->create( diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php index a29e39a31b9e5..a01a538e198a9 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php @@ -1,4 +1,10 @@ getModuleName($packageName) || diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index f210813c797c4..b43308513d5ec 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -1,12 +1,19 @@ $type) { + foreach ($schema as $type) { if (isset($type['module']) && $type['module'] == $moduleName && isset($type['implements'])) { - foreach ($type['implements'] as $interfaceName => $interfaceData) { - $dependOnModule = $schema[$interfaceName]['module']; + $interfaces = array_keys($type['implements']); + foreach ($interfaces as $interface) { + $dependOnModule = $schema[$interface]['module']; if ($dependOnModule != $moduleName) { $dependencies[] = $dependOnModule; } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php index c9684a9a4be76..edd611ad9fd0f 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php @@ -1,9 +1,13 @@ $type) { if (!isset($type['module']) && ( - ($type['type'] == 'graphql_interface' && isset($type['typeResolver'])) - || isset($type['implements'])) + ($type['type'] == 'graphql_interface' && isset($type['typeResolver'])) + || isset($type['implements']) + ) ) { $source[$typeName]['module'] = self::getModuleNameForRelevantFile($filePath); } From ce1464ed96766c0ab5b399e4574e784ea1e332cd Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Thu, 18 Jun 2020 01:22:49 +0300 Subject: [PATCH 03/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - fixed static and integration tests --- .../GraphQl/Config/GraphQlReaderTest.php | 18 ++++++++++-------- .../Framework/GraphQl/GraphQlConfigTest.php | 2 ++ .../DeclarativeSchemaDependencyProvider.php | 3 +++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php index 79c8765dd4220..6c20590bd23a6 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php @@ -47,9 +47,11 @@ protected function setUp(): void $fileResolverMock = $this->getMockBuilder( \Magento\Framework\Config\FileResolverInterface::class )->disableOriginalConstructor()->getMock(); + $filePath1 = __DIR__ . '/../_files/schemaA.graphqls'; + $filePath2 = __DIR__ . '/../_files/schemaB.graphqls'; $fileList = [ - file_get_contents(__DIR__ . '/../_files/schemaA.graphqls'), - file_get_contents(__DIR__ . '/../_files/schemaB.graphqls') + $filePath1 => file_get_contents($filePath1), + $filePath2 => file_get_contents($filePath2) ]; $fileResolverMock->expects($this->any())->method('get')->willReturn($fileList); $graphQlReader = $this->objectManager->create( @@ -219,31 +221,31 @@ function ($a, $b) { } //Checks to make sure that the given description exists in the expectedOutput array $this->assertArrayHasKey( - + array_search( 'Comment for empty PhysicalProductInterface', array_column($expectedOutput, 'description') ), $expectedOutput - + ); $this->assertArrayHasKey( - + array_search( 'Comment for empty Enum', array_column($expectedOutput, 'description') ), $expectedOutput - + ); $this->assertArrayHasKey( - + array_search( 'Comment for SearchResultPageInfo', array_column($expectedOutput, 'description') ), $expectedOutput - + ); } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php index 5f62888596348..f74d96bcc42a3 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/GraphQlConfigTest.php @@ -48,10 +48,12 @@ protected function setUp(): void ['fileResolver' => $fileResolverMock] ); $reader = $objectManager->create( + // phpstan:ignore \Magento\Framework\GraphQlSchemaStitching\Reader::class, ['readers' => ['graphql_reader' => $graphQlReader]] ); $data = $objectManager->create( + // phpstan:ignore \Magento\Framework\GraphQl\Config\Data ::class, ['reader' => $reader] ); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index 332e1b88a53fe..84b5533326b06 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -67,6 +67,7 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array foreach ($dependencies as $dependency) { $checkResult = array_intersect($declared, $dependency); if ($checkResult) { + //phpcs:ignore Magento2.Performance.ForeachArrayMerge $existingDeclared = array_merge($existingDeclared, array_values($checkResult)); } } @@ -161,6 +162,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar } else { foreach ($modules as $dependencySet) { if (array_search($moduleName, $dependencySet) === false) { + //phpcs:ignore Magento2.Performance.ForeachArrayMerge $resultDependencies = array_merge( $resultDependencies, $dependencySet @@ -406,6 +408,7 @@ private function getConstraintDependencies(array $moduleDeclaration): array $this->getDependencyId($tableName, self::SCHEMA_ENTITY_CONSTRAINT, $constraintName); switch ($constraintDeclaration['type']) { case 'foreign': + //phpcs:ignore Magento2.Performance.ForeachArrayMerge $constraintDependencies = array_merge( $constraintDependencies, $this->getFKDependencies($constraintDeclaration) From 6f62bea96c0521ac597b280f2fb8494e7982ca05 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Thu, 18 Jun 2020 10:13:53 +0300 Subject: [PATCH 04/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - fixed static code style test --- .../GraphQl/Config/GraphQlReaderTest.php | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php index 6c20590bd23a6..96e31a753adaa 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/GraphQl/Config/GraphQlReaderTest.php @@ -221,31 +221,25 @@ function ($a, $b) { } //Checks to make sure that the given description exists in the expectedOutput array $this->assertArrayHasKey( - - array_search( - 'Comment for empty PhysicalProductInterface', - array_column($expectedOutput, 'description') - ), - $expectedOutput - + array_search( + 'Comment for empty PhysicalProductInterface', + array_column($expectedOutput, 'description') + ), + $expectedOutput ); $this->assertArrayHasKey( - - array_search( - 'Comment for empty Enum', - array_column($expectedOutput, 'description') - ), - $expectedOutput - + array_search( + 'Comment for empty Enum', + array_column($expectedOutput, 'description') + ), + $expectedOutput ); $this->assertArrayHasKey( - - array_search( - 'Comment for SearchResultPageInfo', - array_column($expectedOutput, 'description') - ), - $expectedOutput - + array_search( + 'Comment for SearchResultPageInfo', + array_column($expectedOutput, 'description') + ), + $expectedOutput ); } } From 50639da7edd7e36d1c873060df789edd4f2a9d25 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Thu, 18 Jun 2020 11:00:46 +0300 Subject: [PATCH 05/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - composer.lock changes --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index e5614cfd0ac99..f792088841987 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3674961f96b48fdd025a6c94610c8eb", + "content-hash": "92dbe431360d97af80030834b46dd77d", "packages": [ { "name": "colinmollenhour/cache-backend-file", From b6ae25beb1cb683b55b0b308651ce65ffbb9c6a6 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Mon, 22 Jun 2020 15:39:31 +0300 Subject: [PATCH 06/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - fixed static test --- .../Integrity/Dependency/GraphQlSchemaDependencyProvider.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index b43308513d5ec..ada16c7a96bca 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -9,6 +9,8 @@ namespace Magento\Test\Integrity\Dependency; use Magento\Framework\App\Bootstrap; +use Magento\Framework\GraphQlSchemaStitching\GraphQlReader; +use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeReaderComposite; /** * Provide information on the dependency between the modules according to the GraphQL schema. @@ -86,7 +88,8 @@ private function getGraphQlSchemaDeclaration(): array { if (!$this->parsedSchema) { $objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager(); - $reader = $objectManager->create(\Magento\Framework\GraphQlSchemaStitching\GraphQlReader::class); + $typeReader = $objectManager->create(TypeReaderComposite::class); + $reader = $objectManager->create(GraphQlReader::class, ['typeReader' => $typeReader]); $this->parsedSchema = $reader->read(); } From e76f1c567296d4019cbc94a561e9a22f17a5f0e7 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Tue, 23 Jun 2020 15:35:18 +0300 Subject: [PATCH 07/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - added requested changes --- .../Integrity/DeclarativeDependencyTest.php | 11 +- .../DeclarativeSchemaDependencyProvider.php | 82 +++++++------- .../Dependency/DependencyProvider.php | 103 +++++++++--------- .../GraphQlSchemaDependencyProvider.php | 61 ++++++----- .../Magento/Test/Integrity/DependencyTest.php | 8 +- .../Test/Integrity/GraphQlDependencyTest.php | 15 ++- .../GraphQlSchemaStitching/GraphQlReader.php | 15 +-- 7 files changed, 152 insertions(+), 143 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php index a5d9f9be41d23..10ce22b8c026f 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php @@ -25,7 +25,7 @@ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase /** * Sets up data * - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception */ protected function setUp(): void { @@ -37,11 +37,12 @@ protected function setUp(): void 'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.' ); } - $this->dependencyProvider = new DeclarativeSchemaDependencyProvider(); + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class); } /** - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function testUndeclaredDependencies() { @@ -131,14 +132,14 @@ private function getErrorMessage(string $id): string * * @param string $file * @return mixed - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception */ private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { //phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Exception("Invalid Json: $file"); + throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); } return $decodedJson; diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index 84b5533326b06..84de29e316b95 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -17,7 +17,7 @@ * * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ -class DeclarativeSchemaDependencyProvider extends DependencyProvider +class DeclarativeSchemaDependencyProvider { /** * Declarative name for table entity of the declarative schema. @@ -49,6 +49,16 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider */ private $moduleSchemaFileMapping = []; + /** + * @var DependencyProvider + */ + private $dependencyProvider; + + public function __construct(DependencyProvider $dependencyProvider) + { + $this->dependencyProvider = $dependencyProvider; + } + /** * Provide declared dependencies between modules based on the declarative schema configuration. * @@ -58,10 +68,14 @@ class DeclarativeSchemaDependencyProvider extends DependencyProvider */ public function getDeclaredExistingModuleDependencies(string $moduleName): array { - $this->initDeclaredDependencies(); + $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName)); $dependencies = $this->filterSelfDependency($moduleName, $dependencies); - $declared = $this->getDeclaredDependencies($moduleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + $declared = $this->dependencyProvider->getDeclaredDependencies( + $moduleName, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_DECLARED + ); $existingDeclared = []; foreach ($dependencies as $dependency) { @@ -89,7 +103,7 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array */ public function getUndeclaredModuleDependencies(string $moduleName): array { - $this->initDeclaredDependencies(); + $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName)); $dependencies = $this->filterSelfDependency($moduleName, $dependencies); return $this->collectDependencies($moduleName, $dependencies); @@ -100,7 +114,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array * * @param string $module * @return string - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function getSchemaFileNameByModuleName(string $module): string { @@ -128,10 +142,10 @@ private function getSchemaFileNameByModuleName(string $module): string * @param array $dependencies * @return array */ - private function filterSelfDependency(string $moduleName, array $dependencies):array + private function filterSelfDependency(string $moduleName, array $dependencies): array { foreach ($dependencies as $id => $modules) { - $decodedId = $this->decodeDependencyId($id); + $decodedId = self::decodeDependencyId($id); $entityType = $decodedId['entityType']; if ($entityType === self::SCHEMA_ENTITY_TABLE || $entityType === "column") { if (array_search($moduleName, $modules) !== false) { @@ -178,7 +192,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar * Retrieve declarative schema declaration. * * @return array - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function getDeclarativeSchema(): array { @@ -201,10 +215,9 @@ private function getDeclarativeSchema(): array array_push($tableDeclaration['modules'], $moduleName); $moduleDeclaration = array_replace_recursive( $moduleDeclaration, - [self::SCHEMA_ENTITY_TABLE => - [ - $tableName => $tableDeclaration, - ] + [self::SCHEMA_ENTITY_TABLE => [ + $tableName => $tableDeclaration, + ] ] ); foreach ($entityTypes as $entityType) { @@ -213,11 +226,9 @@ private function getDeclarativeSchema(): array } $moduleDeclaration = array_replace_recursive( $moduleDeclaration, - [self::SCHEMA_ENTITY_TABLE => - [ - $tableName => - $this->addModuleAssigment($tableDeclaration, $entityType, $moduleName) - ] + [self::SCHEMA_ENTITY_TABLE => [ + $tableName => $this->addModuleAssigment($tableDeclaration, $entityType, $moduleName) + ] ] ); } @@ -236,7 +247,7 @@ private function getDeclarativeSchema(): array * @param string $entityType * @param null|string $entityName * @return array - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function resolveEntityDependencies(string $tableName, string $entityType, ?string $entityName = null): array { @@ -319,7 +330,7 @@ private function getDependenciesFromFiles($file) * * @param array $moduleDeclaration * @return array - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function getDisabledDependencies(array $moduleDeclaration): array { @@ -532,7 +543,7 @@ public static function decodeDependencyId(string $id): array * @param array $dependencies * @return array */ - private function collectDependencies($currentModuleName, $dependencies = []) + private function collectDependencies($currentModuleName, $dependencies = []): array { if (empty($dependencies)) { return []; @@ -541,7 +552,11 @@ private function collectDependencies($currentModuleName, $dependencies = []) $this->collectDependency($dependencyName, $dependency, $currentModuleName); } - return $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_FOUND); + return $this->dependencyProvider->getDeclaredDependencies( + $currentModuleName, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_FOUND + ); } /** @@ -556,31 +571,22 @@ private function collectDependency( array $dependency, string $currentModule ) { - $declared = $this->getDeclaredDependencies($currentModule, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + $declared = $this->dependencyProvider->getDeclaredDependencies( + $currentModule, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_DECLARED + ); $checkResult = array_intersect($declared, $dependency); if (empty($checkResult)) { - $this->addDependencies( + $this->dependencyProvider->addDependencies( $currentModule, - self::TYPE_HARD, - self::MAP_TYPE_FOUND, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_FOUND, [ $dependencyName => $dependency, ] ); } } - - /** - * Retrieve array of dependency items. - * - * @param $module - * @param $type - * @param $mapType - * @return array - */ - protected function getDeclaredDependencies(string $module, string $type, string $mapType) - { - return $this->mapDependencies[$module][$type][$mapType] ?? []; - } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php index a01a538e198a9..755d2dda0e08f 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php @@ -11,7 +11,7 @@ use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; -abstract class DependencyProvider +class DependencyProvider { /** * Types of dependency between modules. @@ -31,41 +31,20 @@ abstract class DependencyProvider /** * @var array */ - protected $mapDependencies = []; + private $mapDependencies = []; /** * @var array */ - protected $packageModuleMapping = []; - - /** - * Retrieve array of dependency items. - * - * @param $module - * @param $type - * @param $mapType - * @return array - */ - abstract protected function getDeclaredDependencies(string $module, string $type, string $mapType); - - /** - * @param string $moduleName - * @return array - */ - abstract public function getDeclaredExistingModuleDependencies(string $moduleName): array; - - /** - * @param string $moduleName - * @return array - */ - abstract public function getUndeclaredModuleDependencies(string $moduleName): array; + private $packageModuleMapping = []; /** * Initialise map of dependencies. * + * @throws \Magento\TestFramework\Inspection\Exception * @throws \Magento\Framework\Exception\LocalizedException */ - protected function initDeclaredDependencies() + public function initDeclaredDependencies() { if (empty($this->mapDependencies)) { $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); @@ -78,6 +57,35 @@ protected function initDeclaredDependencies() } } + /** + * Add dependency map items. + * + * @param $module + * @param $type + * @param $mapType + * @param $dependencies + */ + public function addDependencies(string $module, string $type, string $mapType, array $dependencies) + { + $this->mapDependencies[$module][$type][$mapType] = array_merge_recursive( + $this->getDeclaredDependencies($module, $type, $mapType), + $dependencies + ); + } + + /** + * Retrieve array of dependency items. + * + * @param $module + * @param $type + * @param $mapType + * @return array + */ + public function getDeclaredDependencies(string $module, string $type, string $mapType): array + { + return $this->mapDependencies[$module][$type][$mapType] ?? []; + } + /** * Add dependencies to dependency list. * @@ -86,9 +94,10 @@ protected function initDeclaredDependencies() * @param string $type * * @return void - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ - protected function presetDependencies(string $moduleName, array $packageNames, string $type): void + private function presetDependencies(string $moduleName, array $packageNames, string $type): void { $packageNames = array_filter($packageNames, function ($packageName) { return $this->getModuleName($packageName) || @@ -108,9 +117,10 @@ protected function presetDependencies(string $moduleName, array $packageNames, s /** * @param string $jsonName * @return string - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ - protected function convertModuleName(string $jsonName): string + private function convertModuleName(string $jsonName): string { $moduleName = $this->getModuleName($jsonName); if ($moduleName) { @@ -138,14 +148,13 @@ protected function convertModuleName(string $jsonName): string * * @param string $file * @return mixed - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception */ - protected function readJsonFile(string $file, bool $asArray = false) + private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { - //phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Exception("Invalid Json: $file"); + throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); } return $decodedJson; @@ -156,9 +165,10 @@ protected function readJsonFile(string $file, bool $asArray = false) * * @param string $packageName * @return null|string - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getModuleName(string $packageName): ?string + private function getModuleName(string $packageName): ?string { return $this->getPackageModuleMapping()[$packageName] ?? null; } @@ -167,9 +177,10 @@ protected function getModuleName(string $packageName): ?string * Returns package name on module name mapping. * * @return array - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ - protected function getPackageModuleMapping(): array + private function getPackageModuleMapping(): array { if (!$this->packageModuleMapping) { $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); @@ -188,20 +199,4 @@ protected function getPackageModuleMapping(): array return $this->packageModuleMapping; } - - /** - * Add dependency map items. - * - * @param $module - * @param $type - * @param $mapType - * @param $dependencies - */ - protected function addDependencies(string $module, string $type, string $mapType, array $dependencies) - { - $this->mapDependencies[$module][$type][$mapType] = array_merge_recursive( - $this->getDeclaredDependencies($module, $type, $mapType), - $dependencies - ); - } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index ada16c7a96bca..7d0b6f7c391a1 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -8,7 +8,6 @@ namespace Magento\Test\Integrity\Dependency; -use Magento\Framework\App\Bootstrap; use Magento\Framework\GraphQlSchemaStitching\GraphQlReader; use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeReaderComposite; @@ -17,18 +16,25 @@ * * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ -class GraphQlSchemaDependencyProvider extends DependencyProvider +class GraphQlSchemaDependencyProvider { /** * @var array */ private $parsedSchema = []; + /** + * @var DependencyProvider + */ + private $dependencyProvider; + /** * GraphQlSchemaDependencyProvider constructor. + * @param DependencyProvider $dependencyProvider */ - public function __construct() + public function __construct(DependencyProvider $dependencyProvider) { + $this->dependencyProvider = $dependencyProvider; $this->getGraphQlSchemaDeclaration(); } @@ -37,13 +43,18 @@ public function __construct() * * @param string $moduleName * @return array - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getDeclaredExistingModuleDependencies(string $moduleName): array { - $this->initDeclaredDependencies(); + $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromSchema($moduleName); - $declared = $this->getDeclaredDependencies($moduleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + $declared = $this->dependencyProvider->getDeclaredDependencies( + $moduleName, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_DECLARED + ); return array_unique(array_values(array_intersect($declared, $dependencies))); } @@ -57,28 +68,16 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array * * @param string $moduleName * @return array - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function getUndeclaredModuleDependencies(string $moduleName): array { - $this->initDeclaredDependencies(); + $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromSchema($moduleName); return $this->collectDependencies($moduleName, $dependencies); } - /** - * Retrieve array of dependency items. - * - * @param $module - * @param $type - * @param $mapType - * @return array - */ - protected function getDeclaredDependencies(string $module, string $type, string $mapType): array - { - return $this->mapDependencies[$module][$type][$mapType] ?? []; - } - /** * Get parsed GraphQl schema * @@ -87,7 +86,7 @@ protected function getDeclaredDependencies(string $module, string $type, string private function getGraphQlSchemaDeclaration(): array { if (!$this->parsedSchema) { - $objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager(); + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $typeReader = $objectManager->create(TypeReaderComposite::class); $reader = $objectManager->create(GraphQlReader::class, ['typeReader' => $typeReader]); $this->parsedSchema = $reader->read(); @@ -135,18 +134,26 @@ private function collectDependencies(string $currentModuleName, array $dependenc if (empty($dependencies)) { return []; } - $declared = $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_DECLARED); + $declared = $this->dependencyProvider->getDeclaredDependencies( + $currentModuleName, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_DECLARED + ); $checkResult = array_intersect($declared, $dependencies); if (empty($checkResult)) { - $this->addDependencies( + $this->dependencyProvider->addDependencies( $currentModuleName, - self::TYPE_HARD, - self::MAP_TYPE_FOUND, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_FOUND, [$currentModuleName => $dependencies] ); } - return $this->getDeclaredDependencies($currentModuleName, self::TYPE_HARD, self::MAP_TYPE_FOUND); + return $this->dependencyProvider->getDeclaredDependencies( + $currentModuleName, + DependencyProvider::TYPE_HARD, + DependencyProvider::MAP_TYPE_FOUND + ); } } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php index 5653069564e99..d79e94af2bc01 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php @@ -8,6 +8,7 @@ */ namespace Magento\Test\Integrity; +use Magento\Framework\App\Bootstrap; use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Exception\LocalizedException; @@ -765,7 +766,7 @@ function (&$moduleName) { $this->_setDependencies($currentModule, $type, self::MAP_TYPE_REDUNDANT, $moduleName); } - $this->addDependency($currentModule, $type, self::MAP_TYPE_FOUND, $moduleName); + self::addDependency($currentModule, $type, self::MAP_TYPE_FOUND, $moduleName); } if (empty($declaredDependencies)) { @@ -783,8 +784,9 @@ function (&$moduleName) { */ public function collectRedundant() { - $schemaDependencyProvider = new DeclarativeSchemaDependencyProvider(); - $graphQlSchemaDependencyProvider = new GraphQlSchemaDependencyProvider(); + $objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager(); + $schemaDependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class); + $graphQlSchemaDependencyProvider = $objectManager->create(GraphQlSchemaDependencyProvider::class); foreach (array_keys(self::$mapDependencies) as $module) { $declared = $this->_getDependencies($module, self::TYPE_HARD, self::MAP_TYPE_DECLARED); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php index edd611ad9fd0f..375f63ee1a61b 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php @@ -22,7 +22,7 @@ class GraphQlDependencyTest extends \PHPUnit\Framework\TestCase /** * Sets up data * - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception */ protected function setUp(): void { @@ -34,11 +34,12 @@ protected function setUp(): void 'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.' ); } - $this->dependencyProvider = new GraphQlSchemaDependencyProvider(); + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $this->dependencyProvider = $objectManager->create(GraphQlSchemaDependencyProvider::class); } /** - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ public function testUndeclaredDependencies() { @@ -49,6 +50,9 @@ public function testUndeclaredDependencies() * * @param string $fileType * @param string $file + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \PHPUnit\Framework\AssertionFailedError */ function ($file) { $componentRegistrar = new ComponentRegistrar(); @@ -112,14 +116,13 @@ private function getErrorMessage(string $id): string * * @param string $file * @return mixed - * @throws \Exception + * @throws \Magento\TestFramework\Inspection\Exception */ private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { - //phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Exception("Invalid Json: $file"); + throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); } return $decodedJson; diff --git a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php index c56b0256ca53b..d486a42e67ba6 100644 --- a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php +++ b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php @@ -21,6 +21,8 @@ class GraphQlReader implements ReaderInterface const GRAPHQL_SCHEMA_FILE = 'schema.graphqls'; + const GRAPHQL_INTERFACE = 'graphql_interface'; + /** * File locator * @@ -301,18 +303,11 @@ private function removePlaceholderFromResults(array $partialResults) : array * @param string $file * @return string */ - private static function getModuleNameForRelevantFile($file) + private static function getModuleNameForRelevantFile(string $file): string { if (!isset(self::$componentRegistrar)) { self::$componentRegistrar = new ComponentRegistrar(); } - // Validates file when it belongs to default themes - foreach (self::$componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themeDir) { - if (strpos($file, $themeDir . '/') !== false) { - return ''; - } - } - $foundModuleName = ''; foreach (self::$componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $moduleDir) { if (strpos($file, $moduleDir . '/') !== false) { @@ -321,7 +316,7 @@ private static function getModuleNameForRelevantFile($file) } } if (empty($foundModuleName)) { - return ''; + $foundModuleName = ''; } return $foundModuleName; @@ -338,7 +333,7 @@ private function addModuleNameToTypes(array $source, string $filePath): array { foreach ($source as $typeName => $type) { if (!isset($type['module']) && ( - ($type['type'] == 'graphql_interface' && isset($type['typeResolver'])) + ($type['type'] == self::GRAPHQL_INTERFACE && isset($type['typeResolver'])) || isset($type['implements']) ) ) { From 26df598a660ad6b7785db32505f1431be63ad105 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Tue, 23 Jun 2020 21:48:55 +0300 Subject: [PATCH 08/12] magento/magento2#27952: missing store_name in GraphQL resolver - static test fix --- .../Magento/Test/Integrity/DeclarativeDependencyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php index 10ce22b8c026f..281f672712f1d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php @@ -14,6 +14,7 @@ /** * Class DeclarativeDependencyTest + * Test for undeclared dependencies in declarative schema */ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase { From 0e32b44dcedb7550a494f48333d1a6e6e2241f3f Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Wed, 24 Jun 2020 17:45:51 +0300 Subject: [PATCH 09/12] magento/magento2#27952: missing store_name in GraphQL resolver - initDeclaredDependencies() fix --- .../DeclarativeSchemaDependencyProvider.php | 6 ++-- .../Dependency/DependencyProvider.php | 36 ++++++++++++------- .../GraphQlSchemaDependencyProvider.php | 2 -- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index 84de29e316b95..df8986d2a3c56 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -54,6 +54,10 @@ class DeclarativeSchemaDependencyProvider */ private $dependencyProvider; + /** + * DeclarativeSchemaDependencyProvider constructor. + * @param DependencyProvider $dependencyProvider + */ public function __construct(DependencyProvider $dependencyProvider) { $this->dependencyProvider = $dependencyProvider; @@ -68,7 +72,6 @@ public function __construct(DependencyProvider $dependencyProvider) */ public function getDeclaredExistingModuleDependencies(string $moduleName): array { - $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName)); $dependencies = $this->filterSelfDependency($moduleName, $dependencies); $declared = $this->dependencyProvider->getDeclaredDependencies( @@ -103,7 +106,6 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array */ public function getUndeclaredModuleDependencies(string $moduleName): array { - $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromFiles($this->getSchemaFileNameByModuleName($moduleName)); $dependencies = $this->filterSelfDependency($moduleName, $dependencies); return $this->collectDependencies($moduleName, $dependencies); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php index 755d2dda0e08f..ef05b91ba54d4 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php @@ -39,22 +39,13 @@ class DependencyProvider private $packageModuleMapping = []; /** - * Initialise map of dependencies. - * - * @throws \Magento\TestFramework\Inspection\Exception + * DependencyProvider constructor. * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\TestFramework\Inspection\Exception */ - public function initDeclaredDependencies() + public function __construct() { - if (empty($this->mapDependencies)) { - $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); - foreach ($jsonFiles as $file) { - $json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file)); - $moduleName = $this->convertModuleName($json->get('name')); - $require = array_keys((array)$json->get('require')); - $this->presetDependencies($moduleName, $require, self::TYPE_HARD); - } - } + $this->initDeclaredDependencies(); } /** @@ -86,6 +77,25 @@ public function getDeclaredDependencies(string $module, string $type, string $ma return $this->mapDependencies[$module][$type][$mapType] ?? []; } + /** + * Initialise map of dependencies. + * + * @throws \Magento\TestFramework\Inspection\Exception + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function initDeclaredDependencies() + { + if (empty($this->mapDependencies)) { + $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); + foreach ($jsonFiles as $file) { + $json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file)); + $moduleName = $this->convertModuleName($json->get('name')); + $require = array_keys((array)$json->get('require')); + $this->presetDependencies($moduleName, $require, self::TYPE_HARD); + } + } + } + /** * Add dependencies to dependency list. * diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index 7d0b6f7c391a1..b759649ac3151 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -48,7 +48,6 @@ public function __construct(DependencyProvider $dependencyProvider) */ public function getDeclaredExistingModuleDependencies(string $moduleName): array { - $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromSchema($moduleName); $declared = $this->dependencyProvider->getDeclaredDependencies( $moduleName, @@ -73,7 +72,6 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array */ public function getUndeclaredModuleDependencies(string $moduleName): array { - $this->dependencyProvider->initDeclaredDependencies(); $dependencies = $this->getDependenciesFromSchema($moduleName); return $this->collectDependencies($moduleName, $dependencies); } From 8c4cff429708f6f52ddd266220f53707308181c2 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Thu, 25 Jun 2020 14:11:42 +0300 Subject: [PATCH 10/12] magento/magento2#27952: missing store_name in GraphQL resolver - changed to proxy --- .../Dependency/DeclarativeSchemaDependencyProvider.php | 4 ++-- .../Integrity/Dependency/GraphQlSchemaDependencyProvider.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index df8986d2a3c56..a1e94f8baa66a 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -56,9 +56,9 @@ class DeclarativeSchemaDependencyProvider /** * DeclarativeSchemaDependencyProvider constructor. - * @param DependencyProvider $dependencyProvider + * @param \Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider */ - public function __construct(DependencyProvider $dependencyProvider) + public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider) { $this->dependencyProvider = $dependencyProvider; } diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index b759649ac3151..961d5e3d2e34b 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -30,9 +30,9 @@ class GraphQlSchemaDependencyProvider /** * GraphQlSchemaDependencyProvider constructor. - * @param DependencyProvider $dependencyProvider + * @param \Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider */ - public function __construct(DependencyProvider $dependencyProvider) + public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider) { $this->dependencyProvider = $dependencyProvider; $this->getGraphQlSchemaDeclaration(); From d64ef3df4c86ba6c3bcc45b2cd4bebd2c3daa299 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Fri, 26 Jun 2020 14:09:39 +0300 Subject: [PATCH 11/12] magento/magento2#28579:DependencyTest does not analyze GraphQL schema files - fixed reaquested changes --- .../Integrity/DeclarativeDependencyTest.php | 24 ++++---- .../DeclarativeSchemaDependencyProvider.php | 35 +++++++----- .../Dependency/DependencyProvider.php | 55 +++++++++++-------- .../GraphQlSchemaDependencyProvider.php | 27 +++++---- .../Test/Integrity/GraphQlDependencyTest.php | 26 +++++---- ...-1d21-444e-881d-40cea007b24f-testsuite.xml | 19 +++++++ .../GraphQlSchemaStitching/GraphQlReader.php | 11 ++-- 7 files changed, 120 insertions(+), 77 deletions(-) create mode 100644 dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php index 281f672712f1d..2f9d7f6fdac82 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/DeclarativeDependencyTest.php @@ -8,15 +8,20 @@ namespace Magento\Test\Integrity; -use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\Utility\AggregateInvoker; use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Exception\LocalizedException; +use Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider; +use Magento\TestFramework\Inspection\Exception as InspectionException; +use PHPUnit\Framework\TestCase; /** * Class DeclarativeDependencyTest * Test for undeclared dependencies in declarative schema */ -class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase +class DeclarativeDependencyTest extends TestCase { /** * @var DeclarativeSchemaDependencyProvider @@ -26,7 +31,7 @@ class DeclarativeDependencyTest extends \PHPUnit\Framework\TestCase /** * Sets up data * - * @throws \Magento\TestFramework\Inspection\Exception + * @throws InspectionException */ protected function setUp(): void { @@ -38,16 +43,16 @@ protected function setUp(): void 'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.' ); } - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); $this->dependencyProvider = $objectManager->create(DeclarativeSchemaDependencyProvider::class); } /** - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function testUndeclaredDependencies() { - $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this); + $invoker = new AggregateInvoker($this); $invoker( /** * Check undeclared modules dependencies for specified file @@ -109,7 +114,7 @@ private function prepareFiles(array $files): array */ private function getErrorMessage(string $id): string { - $decodedId = $this->dependencyProvider->decodeDependencyId($id); + $decodedId = DeclarativeSchemaDependencyProvider::decodeDependencyId($id); $entityType = $decodedId['entityType']; if ($entityType === DeclarativeSchemaDependencyProvider::SCHEMA_ENTITY_TABLE) { $message = sprintf( @@ -133,14 +138,13 @@ private function getErrorMessage(string $id): string * * @param string $file * @return mixed - * @throws \Magento\TestFramework\Inspection\Exception + * @throws InspectionException */ private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { - //phpcs:ignore Magento2.Exceptions.DirectThrow - throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); + throw new InspectionException("Invalid Json: $file"); } return $decodedJson; diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php index a1e94f8baa66a..e1d35431c5e1d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DeclarativeSchemaDependencyProvider.php @@ -11,6 +11,8 @@ use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; use Magento\Framework\Setup\Declaration\Schema\Config\Converter; +use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Inspection\Exception as InspectionException; /** * Provide information on the dependency between the modules according to the declarative schema. @@ -22,22 +24,22 @@ class DeclarativeSchemaDependencyProvider /** * Declarative name for table entity of the declarative schema. */ - const SCHEMA_ENTITY_TABLE = 'table'; + public const SCHEMA_ENTITY_TABLE = 'table'; /** * Declarative name for column entity of the declarative schema. */ - const SCHEMA_ENTITY_COLUMN = 'column'; + public const SCHEMA_ENTITY_COLUMN = 'column'; /** * Declarative name for constraint entity of the declarative schema. */ - const SCHEMA_ENTITY_CONSTRAINT = 'constraint'; + public const SCHEMA_ENTITY_CONSTRAINT = 'constraint'; /** * Declarative name for index entity of the declarative schema. */ - const SCHEMA_ENTITY_INDEX = 'index'; + public const SCHEMA_ENTITY_INDEX = 'index'; /** * @var array @@ -55,10 +57,9 @@ class DeclarativeSchemaDependencyProvider private $dependencyProvider; /** - * DeclarativeSchemaDependencyProvider constructor. - * @param \Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider + * @param DependencyProvider $dependencyProvider */ - public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider) + public function __construct(DependencyProvider $dependencyProvider) { $this->dependencyProvider = $dependencyProvider; } @@ -116,7 +117,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array * * @param string $module * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ private function getSchemaFileNameByModuleName(string $module): string { @@ -194,7 +195,7 @@ private function filterComplexDependency(string $moduleName, array $modules): ar * Retrieve declarative schema declaration. * * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ private function getDeclarativeSchema(): array { @@ -249,7 +250,7 @@ private function getDeclarativeSchema(): array * @param string $entityType * @param null|string $entityName * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ private function resolveEntityDependencies(string $tableName, string $entityType, ?string $entityName = null): array { @@ -332,7 +333,7 @@ private function getDependenciesFromFiles($file) * * @param array $moduleDeclaration * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ private function getDisabledDependencies(array $moduleDeclaration): array { @@ -445,7 +446,7 @@ private function getConstraintDependencies(array $moduleDeclaration): array * @param string $tableName * @param array $entityDeclaration * @return array - * @throws \Exception + * @throws LocalizedException */ private function getComplexDependency(string $tableName, array $entityDeclaration): array { @@ -471,7 +472,7 @@ private function getComplexDependency(string $tableName, array $entityDeclaratio * * @param array $moduleDeclaration * @return array - * @throws \Exception + * @throws LocalizedException */ private function getIndexDependencies(array $moduleDeclaration): array { @@ -541,9 +542,11 @@ public static function decodeDependencyId(string $id): array /** * Collect module dependencies. * - * @param string $currentModuleName + * @param $currentModuleName * @param array $dependencies * @return array + * @throws InspectionException + * @throws LocalizedException */ private function collectDependencies($currentModuleName, $dependencies = []): array { @@ -562,11 +565,13 @@ private function collectDependencies($currentModuleName, $dependencies = []): ar } /** - * Collect a module dependency. + * Collect a module dependency. * * @param string $dependencyName * @param array $dependency * @param string $currentModule + * @throws LocalizedException + * @throws InspectionException */ private function collectDependency( string $dependencyName, diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php index ef05b91ba54d4..fc1eb128db4ff 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/DependencyProvider.php @@ -10,23 +10,26 @@ use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Config\Composer\Package; +use Magento\TestFramework\Inspection\Exception as InspectionException; class DependencyProvider { /** * Types of dependency between modules. */ - const TYPE_HARD = 'hard'; + public const TYPE_HARD = 'hard'; /** * The identifier of dependency for mapping. */ - const MAP_TYPE_DECLARED = 'declared'; + public const MAP_TYPE_DECLARED = 'declared'; /** * The identifier of dependency for mapping. */ - const MAP_TYPE_FOUND = 'found'; + public const MAP_TYPE_FOUND = 'found'; /** * @var array @@ -39,14 +42,9 @@ class DependencyProvider private $packageModuleMapping = []; /** - * DependencyProvider constructor. - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\TestFramework\Inspection\Exception + * @var bool */ - public function __construct() - { - $this->initDeclaredDependencies(); - } + private $isInited = false; /** * Add dependency map items. @@ -55,9 +53,14 @@ public function __construct() * @param $type * @param $mapType * @param $dependencies + * @throws LocalizedException + * @throws InspectionException */ public function addDependencies(string $module, string $type, string $mapType, array $dependencies) { + if (!$this->isInited) { + $this->initDeclaredDependencies(); + } $this->mapDependencies[$module][$type][$mapType] = array_merge_recursive( $this->getDeclaredDependencies($module, $type, $mapType), $dependencies @@ -71,24 +74,30 @@ public function addDependencies(string $module, string $type, string $mapType, a * @param $type * @param $mapType * @return array + * @throws LocalizedException + * @throws InspectionException */ public function getDeclaredDependencies(string $module, string $type, string $mapType): array { + if (!$this->isInited) { + $this->initDeclaredDependencies(); + } return $this->mapDependencies[$module][$type][$mapType] ?? []; } /** * Initialise map of dependencies. * - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ private function initDeclaredDependencies() { + $this->isInited = true; if (empty($this->mapDependencies)) { $jsonFiles = Files::init()->getComposerFiles(ComponentRegistrar::MODULE, false); foreach ($jsonFiles as $file) { - $json = new \Magento\Framework\Config\Composer\Package($this->readJsonFile($file)); + $json = new Package($this->readJsonFile($file)); $moduleName = $this->convertModuleName($json->get('name')); $require = array_keys((array)$json->get('require')); $this->presetDependencies($moduleName, $require, self::TYPE_HARD); @@ -104,8 +113,8 @@ private function initDeclaredDependencies() * @param string $type * * @return void - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ private function presetDependencies(string $moduleName, array $packageNames, string $type): void { @@ -127,8 +136,8 @@ private function presetDependencies(string $moduleName, array $packageNames, str /** * @param string $jsonName * @return string - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ private function convertModuleName(string $jsonName): string { @@ -158,13 +167,13 @@ private function convertModuleName(string $jsonName): string * * @param string $file * @return mixed - * @throws \Magento\TestFramework\Inspection\Exception + * @throws InspectionException */ private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { - throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); + throw new InspectionException("Invalid Json: $file"); } return $decodedJson; @@ -175,8 +184,8 @@ private function readJsonFile(string $file, bool $asArray = false) * * @param string $packageName * @return null|string - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ private function getModuleName(string $packageName): ?string { @@ -187,8 +196,8 @@ private function getModuleName(string $packageName): ?string * Returns package name on module name mapping. * * @return array - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ private function getPackageModuleMapping(): array { diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php index 961d5e3d2e34b..b5a0b177b35fe 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Dependency/GraphQlSchemaDependencyProvider.php @@ -10,6 +10,9 @@ use Magento\Framework\GraphQlSchemaStitching\GraphQlReader; use Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeReaderComposite; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\LocalizedException; +use Magento\TestFramework\Inspection\Exception as InspectionException; /** * Provide information on the dependency between the modules according to the GraphQL schema. @@ -29,13 +32,11 @@ class GraphQlSchemaDependencyProvider private $dependencyProvider; /** - * GraphQlSchemaDependencyProvider constructor. - * @param \Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider + * @param DependencyProvider $dependencyProvider */ - public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider) + public function __construct(DependencyProvider $dependencyProvider) { $this->dependencyProvider = $dependencyProvider; - $this->getGraphQlSchemaDeclaration(); } /** @@ -43,8 +44,8 @@ public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvide * * @param string $moduleName * @return array - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException + * @throws InspectionException */ public function getDeclaredExistingModuleDependencies(string $moduleName): array { @@ -67,8 +68,8 @@ public function getDeclaredExistingModuleDependencies(string $moduleName): array * * @param string $moduleName * @return array - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \Magento\Framework\Exception\LocalizedException + * @throws InspectionException + * @throws LocalizedException */ public function getUndeclaredModuleDependencies(string $moduleName): array { @@ -84,7 +85,7 @@ public function getUndeclaredModuleDependencies(string $moduleName): array private function getGraphQlSchemaDeclaration(): array { if (!$this->parsedSchema) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); $typeReader = $objectManager->create(TypeReaderComposite::class); $reader = $objectManager->create(GraphQlReader::class, ['typeReader' => $typeReader]); $this->parsedSchema = $reader->read(); @@ -101,16 +102,16 @@ private function getGraphQlSchemaDeclaration(): array */ private function getDependenciesFromSchema(string $moduleName): array { - $schema = $this->parsedSchema; + $schema = $this->getGraphQlSchemaDeclaration(); $dependencies = []; foreach ($schema as $type) { - if (isset($type['module']) && $type['module'] == $moduleName && isset($type['implements'])) { + if (isset($type['module']) && $type['module'] === $moduleName && isset($type['implements'])) { $interfaces = array_keys($type['implements']); foreach ($interfaces as $interface) { $dependOnModule = $schema[$interface]['module']; - if ($dependOnModule != $moduleName) { + if ($dependOnModule !== $moduleName) { $dependencies[] = $dependOnModule; } } @@ -126,6 +127,8 @@ private function getDependenciesFromSchema(string $moduleName): array * @param string $currentModuleName * @param array $dependencies * @return array + * @throws InspectionException + * @throws LocalizedException */ private function collectDependencies(string $currentModuleName, array $dependencies = []): array { diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php index 375f63ee1a61b..9ef14d90a6f3b 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/GraphQlDependencyTest.php @@ -8,11 +8,17 @@ namespace Magento\Test\Integrity; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\Utility\AggregateInvoker; use Magento\Framework\App\Utility\Files; use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Exception\LocalizedException; use Magento\Test\Integrity\Dependency\GraphQlSchemaDependencyProvider; +use Magento\TestFramework\Inspection\Exception as InspectionException; +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\TestCase; -class GraphQlDependencyTest extends \PHPUnit\Framework\TestCase +class GraphQlDependencyTest extends TestCase { /** * @var GraphQlSchemaDependencyProvider @@ -22,7 +28,7 @@ class GraphQlDependencyTest extends \PHPUnit\Framework\TestCase /** * Sets up data * - * @throws \Magento\TestFramework\Inspection\Exception + * @throws InspectionException */ protected function setUp(): void { @@ -34,25 +40,25 @@ protected function setUp(): void 'MAGETWO-43654: The build is running from vendor/magento. DependencyTest is skipped.' ); } - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); $this->dependencyProvider = $objectManager->create(GraphQlSchemaDependencyProvider::class); } /** - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function testUndeclaredDependencies() { - $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this); + $invoker = new AggregateInvoker($this); $invoker( /** * Check undeclared modules dependencies for specified file * * @param string $fileType * @param string $file - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\TestFramework\Inspection\Exception - * @throws \PHPUnit\Framework\AssertionFailedError + * @throws LocalizedException + * @throws InspectionException + * @throws AssertionFailedError */ function ($file) { $componentRegistrar = new ComponentRegistrar(); @@ -116,13 +122,13 @@ private function getErrorMessage(string $id): string * * @param string $file * @return mixed - * @throws \Magento\TestFramework\Inspection\Exception + * @throws InspectionException */ private function readJsonFile(string $file, bool $asArray = false) { $decodedJson = json_decode(file_get_contents($file), $asArray); if (null == $decodedJson) { - throw new \Magento\TestFramework\Inspection\Exception("Invalid Json: $file"); + throw new InspectionException("Invalid Json: $file"); } return $decodedJson; diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml b/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml new file mode 100644 index 0000000000000..4c1edc9c7c8b5 --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml @@ -0,0 +1,19 @@ + + + Magento\Test\Integrity\DeclarativeDependencyTest + + + testUndeclaredDependencies + + Class 'Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider' not found + #0 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/Framework/TestCase.php(772): PHPUnit\Framework\TestResult->run(Object(Magento\Test\Integrity\DeclarativeDependencyTest)) +#1 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/Framework/TestSuite.php(639): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult)) +#2 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(653): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult)) +#3 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/Command.php(108): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true) +#4 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/Command.php(68): PHPUnit\TextUI\Command->run(Array, true) +#5 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main() +#6 {main} + + + + diff --git a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php index d486a42e67ba6..1e8b33f79854b 100644 --- a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php +++ b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php @@ -17,11 +17,11 @@ */ class GraphQlReader implements ReaderInterface { - const GRAPHQL_PLACEHOLDER_FIELD_NAME = 'placeholder_graphql_field'; + public const GRAPHQL_PLACEHOLDER_FIELD_NAME = 'placeholder_graphql_field'; - const GRAPHQL_SCHEMA_FILE = 'schema.graphqls'; + public const GRAPHQL_SCHEMA_FILE = 'schema.graphqls'; - const GRAPHQL_INTERFACE = 'graphql_interface'; + public const GRAPHQL_INTERFACE = 'graphql_interface'; /** * File locator @@ -315,9 +315,6 @@ private static function getModuleNameForRelevantFile(string $file): string break; } } - if (empty($foundModuleName)) { - $foundModuleName = ''; - } return $foundModuleName; } @@ -333,7 +330,7 @@ private function addModuleNameToTypes(array $source, string $filePath): array { foreach ($source as $typeName => $type) { if (!isset($type['module']) && ( - ($type['type'] == self::GRAPHQL_INTERFACE && isset($type['typeResolver'])) + ($type['type'] === self::GRAPHQL_INTERFACE && isset($type['typeResolver'])) || isset($type['implements']) ) ) { From 1305a3ed85b606ba992629ffad40d27eccc59b94 Mon Sep 17 00:00:00 2001 From: Oleksandr Melnyk Date: Fri, 26 Jun 2020 14:57:19 +0300 Subject: [PATCH 12/12] Delete 3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml --- ...-1d21-444e-881d-40cea007b24f-testsuite.xml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml b/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml deleted file mode 100644 index 4c1edc9c7c8b5..0000000000000 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/var/allure-results/3a0f0075-1d21-444e-881d-40cea007b24f-testsuite.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - Magento\Test\Integrity\DeclarativeDependencyTest - - - testUndeclaredDependencies - - Class 'Magento\Test\Integrity\Dependency\DeclarativeSchemaDependencyProvider' not found - #0 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/Framework/TestCase.php(772): PHPUnit\Framework\TestResult->run(Object(Magento\Test\Integrity\DeclarativeDependencyTest)) -#1 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/Framework/TestSuite.php(639): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult)) -#2 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(653): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult)) -#3 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/Command.php(108): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true) -#4 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/src/TextUI/Command.php(68): PHPUnit\TextUI\Command->run(Array, true) -#5 /Users/a1/Documents/local/magento2/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main() -#6 {main} - - - -