Skip to content

Commit 8a5b472

Browse files
committed
DEVOPS-2346: Fix static tests
1 parent a001956 commit 8a5b472

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -309,37 +309,46 @@ private function assertPhpVersionInSync($name, $phpVersion)
309309
* Make sure requirements of components are reflected in root composer.json
310310
*
311311
* @param \StdClass $json
312-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
313312
*/
314313
private function assertRequireInSync(\StdClass $json)
315314
{
316315
if (preg_match('/magento\/project-*/', self::$rootJson['name']) == 1) {
317316
return;
318317
}
318+
if (!in_array($json->name, self::$rootComposerModuleBlacklist) && isset($json->require)) {
319+
$this->checkPackageInRootComposer($json);
320+
}
321+
}
322+
323+
/**
324+
* Check if package is reflected in root composer.json
325+
*
326+
* @param \StdClass $json
327+
*/
328+
private function checkPackageInRootComposer(\StdClass $json): void
329+
{
319330
$name = $json->name;
320-
if (!in_array($name, self::$rootComposerModuleBlacklist) && isset($json->require)) {
321-
$errors = [];
322-
foreach (array_keys((array)$json->require) as $depName) {
323-
if ($depName == 'magento/magento-composer-installer') {
324-
// Magento Composer Installer is not needed for already existing components
325-
continue;
326-
}
327-
if (!isset(self::$rootJson['require-dev'][$depName]) && !isset(self::$rootJson['require'][$depName])
328-
&& !isset(self::$rootJson['replace'][$depName])) {
329-
$errors[] = "'$name' depends on '$depName'";
330-
}
331+
$errors = [];
332+
foreach (array_keys((array)$json->require) as $depName) {
333+
if ($depName == 'magento/magento-composer-installer') {
334+
// Magento Composer Installer is not needed for already existing components
335+
continue;
331336
}
332-
if (!empty($errors)) {
333-
$this->fail(
334-
"The following dependencies are missing in root 'composer.json',"
335-
. " while declared in child components.\n"
336-
. "Consider adding them to 'require-dev' section (if needed for child components only),"
337-
. " to 'replace' section (if they are present in the project),"
338-
. " to 'require' section (if needed for the skeleton).\n"
339-
. join("\n", $errors)
340-
);
337+
if (!isset(self::$rootJson['require-dev'][$depName]) && !isset(self::$rootJson['require'][$depName])
338+
&& !isset(self::$rootJson['replace'][$depName])) {
339+
$errors[] = "'$name' depends on '$depName'";
341340
}
342341
}
342+
if (!empty($errors)) {
343+
$this->fail(
344+
"The following dependencies are missing in root 'composer.json',"
345+
. " while declared in child components.\n"
346+
. "Consider adding them to 'require-dev' section (if needed for child components only),"
347+
. " to 'replace' section (if they are present in the project),"
348+
. " to 'require' section (if needed for the skeleton).\n"
349+
. join("\n", $errors)
350+
);
351+
}
343352
}
344353

345354
/**

0 commit comments

Comments
 (0)