Skip to content

Commit 04a17f4

Browse files
authored
Merge branch 'develop' into master
2 parents 4b4214e + 36a47aa commit 04a17f4

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
use Codeception\Events;
1010
use Codeception\Step;
11+
use Codeception\Test\Test;
1112
use Magento\FunctionalTestingFramework\Allure\AllureHelper;
1213
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
14+
use Magento\FunctionalTestingFramework\Suite\Handlers\SuiteObjectHandler;
1315
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1416
use Qameta\Allure\Allure;
17+
use Qameta\Allure\AllureLifecycleInterface;
1518
use Qameta\Allure\Model\StepResult;
1619
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1720
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
@@ -158,6 +161,68 @@ function (TestResult $testResult) {
158161
$this->getFormattedSteps($testResult);
159162
}
160163
);
164+
165+
$this->addTestsInSuites($lifecycle, $cest);
166+
}
167+
168+
/**
169+
* Function to add test under the suites.
170+
*
171+
* @param object $lifecycle
172+
* @param object $cest
173+
*
174+
* @return void
175+
*/
176+
private function addTestsInSuites($lifecycle, $cest): void
177+
{
178+
$groupName = null;
179+
if ($this->options['groups'] !== null) {
180+
$group = $this->options['groups'][0];
181+
$groupName = $this->sanitizeGroupName($group);
182+
}
183+
$lifecycle->updateTest(
184+
function (TestResult $testResult) use ($groupName, $cest) {
185+
$labels = $testResult->getLabels();
186+
foreach ($labels as $label) {
187+
if ($groupName !== null && $label->getName() === "parentSuite") {
188+
$label->setValue(sprintf('%s\%s', $label->getValue(), $groupName));
189+
}
190+
if ($label->getName() === "package") {
191+
$className = $cest->getReportFields()['class'];
192+
$className = preg_replace('{_[0-9]*_G}', '', $className);
193+
$label->setValue($className);
194+
}
195+
}
196+
}
197+
);
198+
}
199+
200+
/**
201+
* Function which santizes any group names changed by the framework for execution in order to consolidate reporting.
202+
*
203+
* @param string $group
204+
* @return string
205+
*/
206+
private function sanitizeGroupName($group): string
207+
{
208+
$suiteNames = array_keys(SuiteObjectHandler::getInstance()->getAllObjects());
209+
$exactMatch = in_array($group, $suiteNames);
210+
211+
// if this is an existing suite name we dont' need to worry about changing it
212+
if ($exactMatch || strpos($group, "_") === false) {
213+
return $group;
214+
}
215+
216+
// if we can't find this group in the generated suites we have to assume that the group was split for generation
217+
$groupNameSplit = explode("_", $group);
218+
array_pop($groupNameSplit);
219+
array_pop($groupNameSplit);
220+
$originalName = implode("_", $groupNameSplit);
221+
222+
// confirm our original name is one of the existing suite names otherwise just return the original group name
223+
$originalName = in_array($originalName, $suiteNames) ? $originalName : $group;
224+
225+
return $originalName;
161226
}
162227

163228
/**

0 commit comments

Comments
 (0)