Skip to content

Commit ce4b746

Browse files
committed
DEVOPS-2346: Fix static tests
1 parent 76c3cee commit ce4b746

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ private function checkProject()
433433
}
434434
}
435435
sort($dependenciesListed);
436-
$nonDeclaredDependencies = array_diff(self::$dependencies, $dependenciesListed);
436+
$nonDeclaredDependencies = array_diff(
437+
self::$dependencies,
438+
$dependenciesListed,
439+
self::$rootComposerModuleBlacklist
440+
);
437441
$nonexistentDependencies = array_diff($dependenciesListed, self::$dependencies);
438442
$this->assertEmpty(
439443
$nonDeclaredDependencies,

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,53 @@ class PublicCodeTest extends \PHPUnit\Framework\TestCase
2222
'$this', 'void', 'string', 'int', 'bool', 'boolean', 'integer', 'null'
2323
];
2424

25+
/**
26+
* @var string[]|null
27+
*/
28+
private $blockWhitelist;
29+
30+
/**
31+
* Return whitelist class names
32+
*
33+
* @return string[]
34+
*/
35+
private function getWhitelist(): array
36+
{
37+
if ($this->blockWhitelist === null) {
38+
$whiteListFiles = str_replace(
39+
'\\',
40+
'/',
41+
realpath(__DIR__) . '/_files/whitelist/public_code*.txt'
42+
);
43+
$whiteListItems = [];
44+
foreach (glob($whiteListFiles) as $fileName) {
45+
$whiteListItems = array_merge(
46+
$whiteListItems,
47+
file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
48+
);
49+
}
50+
$this->blockWhitelist = $whiteListItems;
51+
}
52+
return $this->blockWhitelist;
53+
}
54+
2555
/**
2656
* Since blocks can be referenced from templates, they should be stable not to break theme customizations.
2757
* So all blocks should be @api annotated. This test checks that all blocks declared in layout files are public
2858
*
2959
* @param $layoutFile
60+
* @throws \ReflectionException
3061
* @dataProvider layoutFilesDataProvider
3162
*/
3263
public function testAllBlocksReferencedInLayoutArePublic($layoutFile)
3364
{
34-
// A block can be whitelisted and thus not be required to be public
35-
$whiteListFiles = str_replace('\\', '/', realpath(__DIR__))
36-
. '/_files/whitelist/public_code*.txt';
37-
$whiteListBlocks = [];
38-
foreach (glob($whiteListFiles) as $fileName) {
39-
$whiteListBlocks = array_merge(
40-
$whiteListBlocks,
41-
file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
42-
);
43-
}
44-
4565
$nonPublishedBlocks = [];
4666
$xml = simplexml_load_file($layoutFile);
4767
$elements = $xml->xpath('//block | //referenceBlock') ?: [];
4868
/** @var $node \SimpleXMLElement */
4969
foreach ($elements as $node) {
5070
$class = (string) $node['class'];
51-
if ($class && \class_exists($class) && !in_array($class, $whiteListBlocks)) {
71+
if ($class && \class_exists($class) && !in_array($class, $this->getWhitelist())) {
5272
$reflection = (new \ReflectionClass($class));
5373
if (strpos($reflection->getDocComment(), '@api') === false) {
5474
$nonPublishedBlocks[] = $class;
@@ -67,6 +87,7 @@ public function testAllBlocksReferencedInLayoutArePublic($layoutFile)
6787
* Find all layout update files in magento modules and themes.
6888
*
6989
* @return array
90+
* @throws \Exception
7091
*/
7192
public function layoutFilesDataProvider()
7293
{
@@ -79,8 +100,8 @@ public function layoutFilesDataProvider()
79100
* This test walks through all public PHP types and makes sure that all their method arguments
80101
* and return values are public types.
81102
*
82-
*
83103
* @param string $class
104+
* @throws \ReflectionException
84105
* @dataProvider publicPHPTypesDataProvider
85106
*/
86107
public function testAllPHPClassesReferencedFromPublicClassesArePublic($class)
@@ -121,6 +142,7 @@ public function testAllPHPClassesReferencedFromPublicClassesArePublic($class)
121142
/**
122143
* Retrieve list of all interfaces and classes in Magento codebase that are marked with @api annotation.
123144
* @return array
145+
* @throws \Exception
124146
*/
125147
public function publicPHPTypesDataProvider()
126148
{
@@ -130,7 +152,9 @@ public function publicPHPTypesDataProvider()
130152
$fileContents = \file_get_contents($file);
131153
if (strpos($fileContents, '@api') !== false) {
132154
foreach ($this->getDeclaredClassesAndInterfaces($file) as $class) {
133-
if (class_exists($class->getName()) || interface_exists($class->getName())) {
155+
if (!in_array($class->getName(), $this->getWhitelist())
156+
&& (class_exists($class->getName()) || interface_exists($class->getName()))
157+
) {
134158
$result[$class->getName()] = [$class->getName()];
135159
}
136160
}

0 commit comments

Comments
 (0)