Skip to content

Commit 091b10e

Browse files
committed
MQE-980: [Annotations] <features> tag defaults to module
- CR fixes, test updates
1 parent f0201e5 commit 091b10e

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Handlers/TestObjectHandlerTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,44 @@ public function testGetTestsByGroup()
141141
$this->assertArrayNotHasKey('excludeTest', $tests);
142142
}
143143

144+
/**
145+
* Tests the function used to parse and determine a test's Module (used in allure Features annotation)
146+
*
147+
* @throws \Exception
148+
*/
149+
public function testGetTestWithModuleName()
150+
{
151+
// set up Test Data
152+
$moduleExpected = "SomeTestModule";
153+
$filepath = DIRECTORY_SEPARATOR .
154+
"user" .
155+
"magento2ce" . DIRECTORY_SEPARATOR .
156+
"dev" . DIRECTORY_SEPARATOR .
157+
"tests" . DIRECTORY_SEPARATOR .
158+
"acceptance" . DIRECTORY_SEPARATOR .
159+
"tests" . DIRECTORY_SEPARATOR .
160+
$moduleExpected . DIRECTORY_SEPARATOR .
161+
"Tests" . DIRECTORY_SEPARATOR .
162+
"text.xml";
163+
// set up mock data
164+
$testDataArrayBuilder = new TestDataArrayBuilder();
165+
$mockData = $testDataArrayBuilder
166+
->withAnnotations()
167+
->withFailedHook()
168+
->withAfterHook()
169+
->withBeforeHook()
170+
->withTestActions()
171+
->withFileName($filepath)
172+
->build();
173+
$this->setMockParserOutput(['tests' => $mockData]);
174+
// Execute Test Method
175+
$toh = TestObjectHandler::getInstance();
176+
$actualTestObject = $toh->getObject($testDataArrayBuilder->testName);
177+
$moduleName = $actualTestObject->getAnnotations()["features"][0];
178+
//performAsserts
179+
$this->assertEquals($moduleExpected, $moduleName);
180+
}
181+
144182
/**
145183
* Function used to set mock for parser return and force init method to run between tests.
146184
*

src/Magento/FunctionalTestingFramework/Test/Util/TestObjectExtractor.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@ public function extractTestData($testData)
134134
*/
135135
private function extractModuleName($path)
136136
{
137-
if ($path === "") {
137+
if (empty($path)) {
138138
return "NO MODULE DETECTED";
139139
}
140140
$paths = explode(DIRECTORY_SEPARATOR, $path);
141-
if ($paths[count($paths)-3] == "Mftf") {
141+
if (!isset($paths[count($paths)-3])) {
142+
return "NO MODULE DETECTED";
143+
} elseif ($paths[count($paths)-3] == "Mftf") {
142144
// app/code/Magento/[Analytics]/Test/Mftf/Test/SomeText.xml
143145
return $paths[count($paths)-5];
144146
}

0 commit comments

Comments
 (0)