Skip to content

Commit 3c11181

Browse files
committed
Merge remote-tracking branch 'karyna/php8-compatibility/fix-static-tests-to-be-php8-compatible' into platform-health
2 parents fb5aa1c + 066b93c commit 3c11181

File tree

7 files changed

+44
-24
lines changed

7 files changed

+44
-24
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/Authentication/Rest/CurlClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class CurlClient extends \OAuth\Common\Http\Client\CurlClient
1414
{
1515
/**
16-
* {@inheritdoc}
16+
* @inheritdoc
1717
*/
1818
public function retrieveResponse(
1919
UriInterface $endpoint,

dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/StaticCalls.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ protected function getClassByStaticCall($staticCall)
8282
{
8383
$step = 1;
8484
$staticClassParts = [];
85+
86+
$token = $this->tokens->getTokenCodeByKey($staticCall - $step);
87+
if ($token === T_NAME_FULLY_QUALIFIED || $token === T_NAME_QUALIFIED) {
88+
return $this->tokens->getTokenValueByKey($staticCall - $step);
89+
}
90+
91+
// PHP 7 compatibility
8592
while ($this->tokens->getTokenCodeByKey(
8693
$staticCall - $step
8794
) == T_STRING || $this->tokens->getTokenCodeByKey(
@@ -90,6 +97,7 @@ protected function getClassByStaticCall($staticCall)
9097
$staticClassParts[] = $this->tokens->getTokenValueByKey($staticCall - $step);
9198
$step++;
9299
}
100+
93101
return implode(array_reverse($staticClassParts));
94102
}
95103

dev/tests/static/framework/Magento/TestFramework/Integrity/Library/PhpParser/Throws.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ public function getDependencies(Uses $uses)
5757
$class = '';
5858
if ($this->tokens->getTokenCodeByKey($throw + 2) == T_NEW) {
5959
$step = 4;
60-
while ($this->tokens->getTokenCodeByKey(
61-
$throw + $step
62-
) == T_STRING || $this->tokens->getTokenCodeByKey(
63-
$throw + $step
64-
) == T_NS_SEPARATOR) {
65-
$class .= trim($this->tokens->getTokenValueByKey($throw + $step));
66-
$step++;
60+
61+
$token = $this->tokens->getTokenCodeByKey($throw + $step);
62+
if ($token === T_NAME_FULLY_QUALIFIED || $token === T_NAME_QUALIFIED) {
63+
$class = $this->tokens->getTokenValueByKey($throw + $step);
64+
} else {
65+
// PHP 7 compatibility
66+
while ($this->tokens->getTokenCodeByKey($throw + $step) === T_STRING
67+
|| $this->tokens->getTokenCodeByKey($throw + $step) === T_NS_SEPARATOR) {
68+
$class .= trim($this->tokens->getTokenValueByKey($throw + $step));
69+
$step++;
70+
}
6771
}
72+
6873
if ($uses->hasUses()) {
6974
$class = $uses->getClassNameWithNamespace($class);
7075
}

dev/tests/static/testsuite/Magento/Test/Integrity/Di/CompilerTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,9 @@ private function getPluginBlacklist(): array
127127
);
128128
$blacklistItems = [];
129129
foreach (glob($blacklistFiles) as $fileName) {
130-
$blacklistItems = array_merge(
131-
$blacklistItems,
132-
file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
133-
);
130+
$blacklistItems[] = file($fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
134131
}
132+
$blacklistItems = array_merge([], ...$blacklistItems);
135133
$this->pluginBlacklist = $blacklistItems;
136134
}
137135
return $this->pluginBlacklist;
@@ -243,10 +241,10 @@ protected function _phpClassesDataProvider()
243241
$allowedFiles = array_keys($classes);
244242
foreach ($classes as $class) {
245243
if (!in_array($class, $output)) {
246-
$output = array_merge($output, $this->_buildInheritanceHierarchyTree($class, $allowedFiles));
247-
$output = array_unique($output);
244+
$output[] = $this->_buildInheritanceHierarchyTree($class, $allowedFiles);
248245
}
249246
}
247+
$output = array_unique(array_merge([], ...$output));
250248

251249
/** Convert data into data provider format */
252250
$outputClasses = [];
@@ -409,7 +407,7 @@ protected function pluginDataProvider()
409407
$plugin = $node->attributes->getNamedItem('type')->nodeValue;
410408
if (!in_array($plugin, $this->getPluginBlacklist())) {
411409
$plugin = \Magento\Framework\App\Utility\Classes::resolveVirtualType($plugin);
412-
$plugins[] = ['plugin' => $plugin, 'intercepted type' => $type];
410+
$plugins[] = [$plugin, $type];
413411
}
414412
}
415413
}

dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Framework/Api/ExtensibleInterfacesTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ private function checkSetExtensionAttributes(
135135
} else {
136136
// Get the parameter name via a regular expression capture because the class may
137137
// not exist which causes a fatal error
138-
preg_match('/\[\s\<\w+?>\s([\w]+)/s', $methodParameters[0]->__toString(), $matches);
138+
preg_match('/\[\s\<\w+?>\s([?]?[\w\\\]+)/s', $methodParameters[0]->__toString(), $matches);
139139
$isCorrectParameter = false;
140-
if (isset($matches[1]) && '\\' . $matches[1] != $extensionInterfaceName) {
140+
if (isset($matches[1])
141+
&& ('\\' . ltrim($matches[1], '?')) === $extensionInterfaceName) {
141142
$isCorrectParameter = true;
142143
}
143144

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPUnit\Framework\TestCase;
1212
use ReflectionClass;
1313
use ReflectionException;
14+
use ReflectionMethod;
1415
use ReflectionParameter;
1516

1617
/**
@@ -111,9 +112,9 @@ public function testAllPHPClassesReferencedFromPublicClassesArePublic($class)
111112
{
112113
$nonPublishedClasses = [];
113114
$reflection = new \ReflectionClass($class);
114-
$filter = \ReflectionMethod::IS_PUBLIC;
115+
$filter = ReflectionMethod::IS_PUBLIC;
115116
if ($reflection->isAbstract()) {
116-
$filter = $filter | \ReflectionMethod::IS_PROTECTED;
117+
$filter = $filter | ReflectionMethod::IS_PROTECTED;
117118
}
118119
$methods = $reflection->getMethods($filter);
119120
foreach ($methods as $method) {
@@ -125,8 +126,11 @@ public function testAllPHPClassesReferencedFromPublicClassesArePublic($class)
125126
is written on early php 7 when return types are not actively used */
126127
$returnTypes = [];
127128
if ($method->hasReturnType()) {
128-
if (!$method->getReturnType()->isBuiltin()) {
129-
$returnTypes = [trim($method->getReturnType()->getName(), '?[]')];
129+
$methodReturnType = $method->getReturnType();
130+
// For PHP 8.0 - ReflectionUnionType doesn't have isBuiltin method.
131+
if (method_exists($methodReturnType, 'isBuiltin')
132+
&& !$methodReturnType->isBuiltin()) {
133+
$returnTypes = [trim($methodReturnType->getName(), '?[]')];
130134
}
131135
} else {
132136
$returnTypes = $this->getReturnTypesFromDocComment($method->getDocComment());
@@ -260,16 +264,20 @@ private function checkReturnValues($class, array $returnTypes, array $nonPublish
260264

261265
/**
262266
* Check if all method parameters are public
267+
*
263268
* @param string $class
264-
* @param \ReflectionMethod $method
269+
* @param ReflectionMethod $method
265270
* @param array $nonPublishedClasses
271+
*
266272
* @return array
273+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
267274
*/
268-
private function checkParameters($class, \ReflectionMethod $method, array $nonPublishedClasses)
275+
private function checkParameters($class, ReflectionMethod $method, array $nonPublishedClasses)
269276
{
270277
/* Ignoring docblocks for argument types */
271278
foreach ($method->getParameters() as $parameter) {
272279
if ($parameter->hasType()
280+
&& method_exists($parameter->getType(), 'isBuiltin')
273281
&& !$parameter->getType()->isBuiltin()
274282
&& !$this->isGenerated($parameter->getType()->getName())
275283
) {

dev/tests/static/testsuite/Magento/Test/Integrity/Readme/ReadmeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private function getDirectories()
5757
$directories = [];
5858
foreach ($this->scanList as $dir) {
5959
if (!$this->isInBlacklist($dir)) {
60-
$directories[][$dir] = $dir;
60+
$directories[][] = $dir;
6161
}
6262
}
6363

0 commit comments

Comments
 (0)