Skip to content

Commit 84a1c48

Browse files
authored
Merge branch 'develop' into ACQE-5089
2 parents 28f2979 + 96e4d9a commit 84a1c48

File tree

8 files changed

+340
-5
lines changed

8 files changed

+340
-5
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Magento Functional Testing Framework Changelog
22
================================================
33

4+
4.3.2
5+
---------
6+
### Enhancements
7+
* 'bootstrap' argument added to indicate that no additional background processes will be run and the jobs complete in the foreground process.
8+
9+
### Fixes
10+
* Fixed serialization of weakmap exception thrown for every internal exception after codeception upgrade.
11+
* Fixed suites no longer separated by MFTF Suite.
12+
413
4.3.1
514
---------
615
### Fixes

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento2-functional-testing-framework",
33
"description": "Magento2 Functional Testing Framework",
44
"type": "library",
5-
"version": "4.3.1",
5+
"version": "4.3.2",
66
"license": "AGPL-3.0",
77
"keywords": ["magento", "automation", "functional", "testing"],
88
"config": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,60 @@ protected function setUp(): void
4040
TestLoggingUtil::getInstance()->setMockLoggingUtil();
4141
}
4242

43+
/**
44+
* Tests generating a suite given a set of parsed test data.
45+
*
46+
* @return void
47+
* @throws Exception
48+
*/
49+
public function testGenerateTestgroupmembership(): void
50+
{
51+
$suiteDataArrayBuilder = new SuiteDataArrayBuilder();
52+
$mockSuiteData = $suiteDataArrayBuilder
53+
->withName('mockSuite')
54+
->includeGroups(['group1'])
55+
->build();
56+
$testDataArrayBuilder = new TestDataArrayBuilder();
57+
$mockSimpleTest1 = $testDataArrayBuilder
58+
->withName('simpleTest1')
59+
->withAnnotations(['group' => [['value' => 'group1']]])
60+
->withTestReference("NonExistantTest")
61+
->withTestActions()
62+
->build();
63+
$mockSimpleTest2 = $testDataArrayBuilder
64+
->withName('simpleTest2')
65+
->withAnnotations(['group' => [['value' => 'group1']]])
66+
->withTestActions()
67+
->build();
68+
$mockSimpleTest3 = $testDataArrayBuilder
69+
->withName('simpleTest3')
70+
->withAnnotations(['group' => [['value' => 'group1']]])
71+
->withTestActions()
72+
->build();
73+
$mockTestData = array_merge($mockSimpleTest1, $mockSimpleTest2, $mockSimpleTest3);
74+
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockSuiteData);
75+
76+
// Make manifest for split suites
77+
$suiteConfig = [
78+
'mockSuite' => [
79+
'mockSuite_0_G' => ['simpleTest1', 'simpleTest2'],
80+
'mockSuite_1_G' => ['simpleTest3'],
81+
],
82+
];
83+
$manifest = TestManifestFactory::makeManifest('default', $suiteConfig);
84+
85+
// parse and generate suite object with mocked data and manifest
86+
$mockSuiteGenerator = SuiteGenerator::getInstance();
87+
$mockSuiteGenerator->generateAllSuites($manifest);
88+
89+
// assert last split suite group generated
90+
TestLoggingUtil::getInstance()->validateMockLogStatement(
91+
'info',
92+
'suite generated',
93+
['suite' => 'mockSuite_1_G', 'relative_path' => '_generated' . DIRECTORY_SEPARATOR . 'mockSuite_1_G']
94+
);
95+
}
96+
4397
/**
4498
* Tests generating a single suite given a set of parsed test data.
4599
*

dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use ReflectionProperty;
2525
use tests\unit\Util\MagentoTestCase;
2626
use tests\unit\Util\TestLoggingUtil;
27+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
2728

2829
class TestGeneratorTest extends MagentoTestCase
2930
{
@@ -299,6 +300,104 @@ function ($filename) use (&$generatedTests) {
299300
$this->assertArrayNotHasKey('test2Cest', $generatedTests);
300301
}
301302

303+
/**
304+
* Test for exception thrown when duplicate arguments found
305+
*
306+
* @return void
307+
* @throws TestFrameworkException
308+
*/
309+
public function testIfExceptionThrownWhenDuplicateArgumentsFound()
310+
{
311+
$fileContents = '<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
312+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
313+
<actionGroup name="ActionGroupReturningValueActionGroup">
314+
<arguments>
315+
<argument name="count" type="string"/>
316+
<argument name="count" type="string"/>
317+
</arguments>
318+
<grabMultiple selector="selector" stepKey="grabProducts1"/>
319+
<assertCount stepKey="assertCount">
320+
<expectedResult type="int">{{count}}</expectedResult>
321+
<actualResult type="variable">grabProducts1</actualResult>
322+
</assertCount>
323+
<return value="{$grabProducts1}" stepKey="returnProducts1"/>
324+
</actionGroup>
325+
</actionGroups>';
326+
$actionInput = 'fakeInput';
327+
$actionObject = new ActionObject('fakeAction', 'comment', [
328+
'userInput' => $actionInput
329+
]);
330+
$annotation1 = ['group' => ['someGroupValue']];
331+
332+
$test1 = new TestObject(
333+
'test1',
334+
['fakeAction' => $actionObject],
335+
$annotation1,
336+
[],
337+
'filename'
338+
);
339+
$annotation2 = ['group' => ['someOtherGroupValue']];
340+
341+
$test2 = new TestObject(
342+
'test2',
343+
['fakeAction' => $actionObject],
344+
$annotation2,
345+
[],
346+
'filename'
347+
);
348+
$testGeneratorObject = TestGenerator::getInstance('', ['sampleTest' => $test1, 'test2' => $test2]);
349+
$result = $testGeneratorObject->throwExceptionIfDuplicateArgumentsFound($testGeneratorObject);
350+
$this->assertEquals($result, "");
351+
}
352+
353+
/**
354+
* Test for exception not thrown when duplicate arguments not found
355+
*
356+
* @return void
357+
*/
358+
public function testIfExceptionNotThrownWhenDuplicateArgumentsNotFound()
359+
{
360+
$fileContents = '<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
361+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
362+
<actionGroup name="ActionGroupReturningValueActionGroup">
363+
<arguments>
364+
<argument name="count" type="string"/>
365+
</arguments>
366+
<grabMultiple selector="selector" stepKey="grabProducts1"/>
367+
<assertCount stepKey="assertCount">
368+
<expectedResult type="int">{{count}}</expectedResult>
369+
<actualResult type="variable">grabProducts1</actualResult>
370+
</assertCount>
371+
<return value="{$grabProducts1}" stepKey="returnProducts1"/>
372+
</actionGroup>
373+
</actionGroups>';
374+
$actionInput = 'fakeInput';
375+
$actionObject = new ActionObject('fakeAction', 'comment', [
376+
'userInput' => $actionInput
377+
]);
378+
$annotation1 = ['group' => ['someGroupValue']];
379+
380+
$test1 = new TestObject(
381+
'test1',
382+
['fakeAction' => $actionObject],
383+
$annotation1,
384+
[],
385+
'filename'
386+
);
387+
$annotation2 = ['group' => ['someOtherGroupValue']];
388+
389+
$test2 = new TestObject(
390+
'test2',
391+
['fakeAction' => $actionObject],
392+
$annotation2,
393+
[],
394+
'filename'
395+
);
396+
$testGeneratorObject = TestGenerator::getInstance('', ['sampleTest' => $test1, 'test2' => $test2]);
397+
$result = $testGeneratorObject->throwExceptionIfDuplicateArgumentsFound($testGeneratorObject);
398+
$this->assertEquals($result, "");
399+
}
400+
302401
/**
303402
* Tests that TestGenerator createAllTestFiles correctly filters based on group.
304403
*

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
231231
$testManifest->createTestGroups($configNumber);
232232
}
233233

234-
SuiteGenerator::getInstance()->generateAllSuites($testManifest);
235-
236234
$testManifest->generate();
235+
236+
SuiteGenerator::getInstance()->generateAllSuites($testManifest);
237237
} catch (\Exception $e) {
238238
if (!empty(GenerationErrorHandler::getInstance()->getAllErrors())) {
239239
GenerationErrorHandler::getInstance()->printErrorSummary();

src/Magento/FunctionalTestingFramework/Suite/SuiteGenerator.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public static function getInstance(): SuiteGenerator
9595
*/
9696
public function generateAllSuites($testManifest)
9797
{
98+
$this->generateTestgroupmembership($testManifest);
9899
$suites = $testManifest->getSuiteConfig();
99100

100101
foreach ($suites as $suiteName => $suiteContent) {
@@ -139,6 +140,108 @@ public function generateSuite($suiteName)
139140
$this->generateSuiteFromTest($suiteName, []);
140141
}
141142

143+
/**
144+
* Function which generate Testgroupmembership file.
145+
*
146+
* @param object $testManifest
147+
* @return void
148+
* @throws \Exception
149+
*/
150+
public function generateTestgroupmembership($testManifest): void
151+
{
152+
$suites = $this->getSuitesDetails($testManifest);
153+
154+
// Path to groups folder
155+
$baseDir = FilePathFormatter::format(TESTS_MODULE_PATH);
156+
$path = $baseDir .'_generated/groups';
157+
158+
$allGroupsContent = $this->readAllGroupFiles($path);
159+
160+
// Output file path
161+
$memberShipFilePath = $baseDir.'_generated/testgroupmembership.txt';
162+
$testCaseNumber = 0;
163+
164+
if (!empty($allGroupsContent)) {
165+
foreach ($allGroupsContent as $groupId => $groupInfo) {
166+
foreach ($groupInfo as $testName) {
167+
// If file has -g then it is test suite
168+
if (str_contains($testName, '-g')) {
169+
$suitename = explode(" ", $testName);
170+
$suitename[1] = trim($suitename[1]);
171+
172+
if (!empty($suites[$suitename[1]])) {
173+
foreach ($suites[$suitename[1]] as $key => $test) {
174+
$suiteTest = sprintf('%s:%s:%s:%s', $groupId, $key, $suitename[1], $test);
175+
file_put_contents($memberShipFilePath, $suiteTest . PHP_EOL, FILE_APPEND);
176+
}
177+
}
178+
} else {
179+
$defaultSuiteTest = sprintf('%s:%s:%s', $groupId, $testCaseNumber, $testName);
180+
file_put_contents($memberShipFilePath, $defaultSuiteTest, FILE_APPEND);
181+
}
182+
$testCaseNumber++;
183+
}
184+
$testCaseNumber = 0;
185+
}
186+
}
187+
}
188+
189+
/**
190+
* Function to format suites details
191+
*
192+
* @param object $testManifest
193+
* @return array $suites
194+
*/
195+
private function getSuitesDetails($testManifest): array
196+
{
197+
// Get suits and subsuites data array
198+
$suites = $testManifest->getSuiteConfig();
199+
200+
// Add subsuites array[2nd dimension] to main array[1st dimension] to access it directly later
201+
if (!empty($suites)) {
202+
foreach ($suites as $subSuites) {
203+
if (!empty($subSuites)) {
204+
foreach ($subSuites as $subSuiteName => $suiteTestNames) {
205+
if (!is_numeric($subSuiteName)) {
206+
$suites[$subSuiteName] = $suiteTestNames;
207+
} else {
208+
continue;
209+
}
210+
}
211+
}
212+
}
213+
}
214+
return $suites;
215+
}
216+
217+
/**
218+
* Function to read all group* text files inside /groups folder
219+
*
220+
* @param object $path
221+
* @return array $allGroupsContent
222+
*/
223+
private function readAllGroupFiles($path): array
224+
{
225+
// Read all group files
226+
if (is_dir($path)) {
227+
$groupFiles = glob("$path/group*.txt");
228+
if ($groupFiles === false) {
229+
throw new RuntimeException("glob(): error with '$path'");
230+
}
231+
sort($groupFiles, SORT_NATURAL);
232+
}
233+
234+
// Read each file in the reverse order and form an array with groupId as key
235+
$groupNumber = 0;
236+
$allGroupsContent = [];
237+
while (!empty($groupFiles)) {
238+
$group = array_pop($groupFiles);
239+
$allGroupsContent[$groupNumber] = file($group);
240+
$groupNumber++;
241+
}
242+
return $allGroupsContent;
243+
}
244+
142245
/**
143246
* Function which takes a suite name and a set of test names. The function then generates all relevant supporting
144247
* files and classes for the suite. The function takes an optional argument for suites which are split by a parallel

0 commit comments

Comments
 (0)