Skip to content

Commit 47b8b38

Browse files
committed
MC-33674: Global config applying makes a huge influence on tests performance
1 parent 4ffe058 commit 47b8b38

File tree

28 files changed

+95
-175
lines changed

28 files changed

+95
-175
lines changed

dev/tests/integration/framework/Magento/TestFramework/Annotation/ConfigFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ protected function setScopeConfigValue(
117117
): void {
118118
$config = $this->getMutableScopeConfig();
119119
if (strpos($configPath, 'default/') === 0) {
120-
$configPath = substr($configPath, 8);
121-
$config->setValue($configPath, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
120+
$configPath = substr($configPath, 8);
121+
$config->setValue($configPath, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
122122
} else {
123123
$config->setValue($configPath, $value, $scopeType, $scopeCode);
124124
}

dev/tests/integration/framework/Magento/TestFramework/SuiteLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function load(string $suiteClassFile): \ReflectionClass
4949
{
5050
$resultClass = $this->suiteLoader->load($suiteClassFile);
5151

52-
if ($this->testsConfig->hasConfiguration($resultClass->getName())
52+
if ($this->testsConfig->hasSkippedTest($resultClass->getName())
5353
&& !in_array(SkippableInterface::class, $resultClass->getInterfaceNames(), true)
5454
) {
5555
$resultClass = new \ReflectionClass($this->generator->generateTestWrapper($resultClass));

dev/tests/integration/framework/Magento/TestFramework/Workaround/Override/Config.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,32 @@ public function getSkipConfiguration(TestCase $test): array
7474
* @param string $className
7575
* @return bool
7676
*/
77-
public function hasConfiguration(string $className): bool
77+
public function hasSkippedTest(string $className): bool
7878
{
79-
return !empty($this->config[$className]) || !empty($this->getGlobalConfig());
79+
$classConfig = $this->config[$className] ?? [];
80+
81+
return $this->isSkippedByConfig($classConfig);
82+
}
83+
84+
/**
85+
* Check that class has even one test skipped
86+
*
87+
* @param array $config
88+
* @return bool
89+
*/
90+
private function isSkippedByConfig(array $config): bool
91+
{
92+
if (isset($config['skip']) && $config['skip']) {
93+
return true;
94+
}
95+
96+
foreach ($config as $lowerLevelConfig) {
97+
if (is_array($lowerLevelConfig)) {
98+
return $this->isSkippedByConfig($lowerLevelConfig);
99+
}
100+
}
101+
102+
return false;
80103
}
81104

82105
/**
@@ -133,22 +156,6 @@ public static function getInstance(): self
133156
return self::$instance;
134157
}
135158

136-
/**
137-
* Get config from global node
138-
*
139-
* @param string|null $fixtureType
140-
* @return array
141-
*/
142-
public function getGlobalConfig(?string $fixtureType = null): array
143-
{
144-
$result = $this->config['global'] ?? [];
145-
if ($fixtureType) {
146-
$result = $result[$fixtureType] ?? [];
147-
}
148-
149-
return $result;
150-
}
151-
152159
/**
153160
* Get config from class node
154161
*
@@ -222,6 +229,6 @@ private function prepareSkipConfig(array $config): array
222229
return [
223230
'skip' => $config['skip'],
224231
'skipMessage' => $config['skipMessage'] ?: 'Skipped according to override configurations',
225-
];
232+
];
226233
}
227234
}

dev/tests/integration/framework/Magento/TestFramework/Workaround/Override/Config/Converter.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Converter implements ConverterInterface
3434
public function convert($source)
3535
{
3636
$this->xpath = new \DOMXPath($source);
37-
$config = $this->getGlobalConfig($this->xpath);
37+
$config = [];
3838
foreach ($this->xpath->query('//test') as $testOverride) {
3939
$className = ltrim($testOverride->getAttribute('class'), '\\');
4040
$config[$className] = $this->getTestConfigByFixtureType($testOverride);
@@ -73,39 +73,6 @@ private function fillSkipSection(\DOMElement $node, array $config): array
7373
return $config;
7474
}
7575

76-
/**
77-
* Get global configurations
78-
*
79-
* @param \DOMXPath $xpath
80-
* @return array
81-
*/
82-
private function getGlobalConfig(\DOMXPath $xpath): array
83-
{
84-
foreach ($xpath->query('//global') as $globalOverride) {
85-
$config = $this->fillGlobalConfigByFixtureType($globalOverride);
86-
}
87-
88-
return $config ?? [];
89-
}
90-
91-
/**
92-
* Fill global configurations node
93-
*
94-
* @param \DOMElement $node
95-
* @return array
96-
*/
97-
private function fillGlobalConfigByFixtureType(\DOMElement $node): array
98-
{
99-
$config = [];
100-
foreach (self::FIXTURE_TYPES as $fixtureType) {
101-
foreach ($node->getElementsByTagName($fixtureType) as $fixture) {
102-
$config['global'][$fixtureType][] = $this->fillAttributes($fixture);
103-
}
104-
}
105-
106-
return $config;
107-
}
108-
10976
/**
11077
* Fill test config for all fixture types
11178
*

dev/tests/integration/framework/Magento/TestFramework/Workaround/Override/Fixture/Applier/Base.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*/
1313
abstract class Base implements ApplierInterface
1414
{
15-
/** @var array */
16-
private $globalConfig;
17-
1815
/** @var array */
1916
private $classConfig;
2017

@@ -24,27 +21,6 @@ abstract class Base implements ApplierInterface
2421
/** @var array */
2522
private $dataSetConfig;
2623

27-
/**
28-
* Get global node config
29-
*
30-
* @return array
31-
*/
32-
public function getGlobalConfig(): array
33-
{
34-
return $this->globalConfig;
35-
}
36-
37-
/**
38-
* Set global node config
39-
*
40-
* @param array $globalConfig
41-
* @return void
42-
*/
43-
public function setGlobalConfig(array $globalConfig): void
44-
{
45-
$this->globalConfig = $globalConfig;
46-
}
47-
4824
/**
4925
* Get class node config
5026
*
@@ -77,7 +53,7 @@ public function getMethodConfig(): array
7753
}
7854

7955
/**
80-
* Set global node config
56+
* Set method node config
8157
*
8258
* @param array $methodConfig
8359
* @return void
@@ -116,7 +92,6 @@ public function setDataSetConfig(array $dataSetConfig): void
11692
protected function getPrioritizedConfig(): array
11793
{
11894
return [
119-
$this->getGlobalConfig(),
12095
$this->getClassConfig(),
12196
$this->getMethodConfig(),
12297
$this->getDataSetConfig(),

dev/tests/integration/framework/Magento/TestFramework/Workaround/Override/Fixture/Resolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ private function getApplier(TestCase $test, string $fixtureType): ApplierInterfa
179179
}
180180
/** @var Base $applier */
181181
$applier = $this->appliersList[$fixtureType];
182-
$applier->setGlobalConfig($this->config->getGlobalConfig($fixtureType));
183182
$applier->setClassConfig($this->config->getClassConfig($test, $fixtureType));
184183
$applier->setMethodConfig($this->config->getMethodConfig($test, $fixtureType));
185184
$applier->setDataSetConfig(

dev/tests/integration/framework/Magento/TestFramework/Workaround/etc/overrides.xsd

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<xs:complexType>
1111
<xs:sequence minOccurs="0" maxOccurs="unbounded">
1212
<xs:element name="test" type="test" minOccurs="0" maxOccurs="unbounded" />
13-
<xs:element name="global" type="global" minOccurs="0" maxOccurs="unbounded" />
1413
</xs:sequence>
1514
</xs:complexType>
1615
</xs:element>
@@ -78,12 +77,4 @@
7877
<xs:attribute name="newValue" type="xs:string"/>
7978
<xs:attribute name="remove" type="xs:boolean"/>
8079
</xs:complexType>
81-
<xs:complexType name="global">
82-
<xs:sequence minOccurs="0" maxOccurs="unbounded">
83-
<xs:element name="magentoDataFixture" type="dataFixture" minOccurs="0" maxOccurs="unbounded" />
84-
<xs:element name="magentoDataFixtureBeforeTransaction" type="dataFixture" minOccurs="0" maxOccurs="unbounded" />
85-
<xs:element name="magentoConfigFixture" type="configFixture" minOccurs="0" maxOccurs="unbounded" />
86-
<xs:element name="magentoAdminConfigFixture" type="adminConfigFixture" minOccurs="0" maxOccurs="unbounded" />
87-
</xs:sequence>
88-
</xs:complexType>
8980
</xs:schema>

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Workaround/Override/Fixture/Applier/AdminConfigFixtureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AdminConfigFixtureTest extends TestCase
2121
/**
2222
* @inheritdoc
2323
*/
24-
protected function setUp()
24+
protected function setUp(): void
2525
{
2626
parent::setUp();
2727

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Workaround/Override/Fixture/Applier/ConfigFixtureTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConfigFixtureTest extends TestCase
2121
/**
2222
* @inheritdoc
2323
*/
24-
protected function setUp()
24+
protected function setUp(): void
2525
{
2626
parent::setUp();
2727

@@ -484,7 +484,6 @@ private function processApply(array $existingFixtures, array $config): array
484484
*/
485485
private function setConfig(array $config): void
486486
{
487-
$this->object->setGlobalConfig([]);
488487
$this->object->setClassConfig([]);
489488
$this->object->setDataSetConfig([]);
490489
$this->object->setMethodConfig($config);

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Workaround/Override/Fixture/Applier/DataFixtureTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DataFixtureTest extends TestCase
2121
/**
2222
* @inheritdoc
2323
*/
24-
protected function setUp()
24+
protected function setUp(): void
2525
{
2626
parent::setUp();
2727

@@ -34,11 +34,8 @@ protected function setUp()
3434
public function testGetPrioritizedConfig(): void
3535
{
3636
$this->object = $this->getMockBuilder(DataFixture::class)
37-
->setMethods(['getGlobalConfig', 'getClassConfig', 'getMethodConfig', 'getDataSetConfig'])
37+
->setMethods(['getClassConfig', 'getMethodConfig', 'getDataSetConfig'])
3838
->getMock();
39-
$this->object->expects($this->once())
40-
->method('getGlobalConfig')
41-
->willReturn(['global_config']);
4239
$this->object->expects($this->once())
4340
->method('getClassConfig')
4441
->willReturn(['class_config']);
@@ -49,7 +46,6 @@ public function testGetPrioritizedConfig(): void
4946
->method('getDataSetConfig')
5047
->willReturn(['data_set_config']);
5148
$expectedResult = [
52-
['global_config'],
5349
['class_config'],
5450
['method_config'],
5551
['data_set_config'],
@@ -275,7 +271,6 @@ private function processApply(array $existingFixtures, array $config): array
275271
*/
276272
private function setConfig(array $config): void
277273
{
278-
$this->object->setGlobalConfig([]);
279274
$this->object->setClassConfig([]);
280275
$this->object->setDataSetConfig([]);
281276
$this->object->setMethodConfig($config);

0 commit comments

Comments
 (0)