Skip to content

Commit 73a5ad6

Browse files
committed
MQE-1964: MFTF Helper - Implementation
- fix static tests
1 parent 4a710d6 commit 73a5ad6

File tree

6 files changed

+88
-15
lines changed

6 files changed

+88
-15
lines changed
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
26

37
namespace MFTF\DevDocs\Helper;
48

59
use Magento\FunctionalTestingFramework\Helper\Helper;
610

711
class CustomHelper extends Helper
812
{
9-
public function goTo(string $url, $test, array $module = [], $superBla = null, $bla = 'blaValue', array $arraysomething = [])
10-
{
13+
/**
14+
* Custom helper.
15+
*
16+
* @param string $url
17+
* @param float $test
18+
* @param array $module
19+
* @param null $superBla
20+
* @param string $bla
21+
* @param array $arraysomething
22+
* @return void
23+
*/
24+
public function goTo(
25+
string $url,
26+
float $test,
27+
array $module = [],
28+
$superBla = null,
29+
$bla = 'blaValue',
30+
array $arraysomething = []
31+
) {
1132
print("this is it: " . $url . PHP_EOL);
33+
sleep(4);
1234
}
1335
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<?php
2-
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
36

47
namespace Magento\FunctionalTestingFramework\Helper;
58

6-
9+
/**
10+
* Class Helper to abstract Codeception module class and make possible to add own functionality if needed.
11+
*/
712
class Helper extends \Codeception\Module
813
{
914
//
10-
}
15+
}

src/Magento/FunctionalTestingFramework/Helper/HelperContainer.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
<?php
2-
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
36

47
namespace Magento\FunctionalTestingFramework\Helper;
58

6-
79
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
810

11+
/**
12+
* Class HelperContainer
13+
*/
914
class HelperContainer
1015
{
16+
/**
17+
* @var Helper[]
18+
*/
1119
private $helpers = [];
1220

21+
/**
22+
* HelperContainer constructor.
23+
* @param array $helpers
24+
*/
1325
public function __construct(array $helpers = [])
1426
{
1527
$this->helpers = $helpers;
1628
}
1729

30+
/**
31+
* Returns helper object by it's class name.
32+
*
33+
* @param string $className
34+
* @return Helper
35+
* @throws TestFrameworkException
36+
*/
1837
public function get(string $className)
1938
{
2039
if ($this->has($className)) {
@@ -23,6 +42,12 @@ public function get(string $className)
2342
throw new TestFrameworkException('Custom helper ' . $className . 'not found.');
2443
}
2544

45+
/**
46+
* Verifies that helper object exist.
47+
*
48+
* @param string $className
49+
* @return boolean
50+
*/
2651
public function has(string $className)
2752
{
2853
return array_key_exists($className, $this->helpers);

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ public function resolveReferences()
296296
}
297297

298298
/**
299+
* Resolves references for helpers.
300+
*
299301
* @throws TestReferenceException
300-
* @throws XmlException
302+
* @return void
301303
*/
302304
private function resolveHelperReferences()
303305
{
@@ -308,7 +310,10 @@ private function resolveHelperReferences()
308310

309311
try {
310312
foreach ($this->actionAttributes as $attrKey => $attrValue) {
311-
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(SectionObjectHandler::getInstance(), $attrValue);
313+
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(
314+
SectionObjectHandler::getInstance(),
315+
$attrValue
316+
);
312317
}
313318
$isResolved = true;
314319
} catch (\Exception $e) {
@@ -317,7 +322,10 @@ private function resolveHelperReferences()
317322

318323
try {
319324
foreach ($this->actionAttributes as $attrKey => $attrValue) {
320-
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(PageObjectHandler::getInstance(), $attrValue);
325+
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(
326+
PageObjectHandler::getInstance(),
327+
$attrValue
328+
);
321329
}
322330
$isResolved = true;
323331
} catch (\Exception $e) {
@@ -326,7 +334,10 @@ private function resolveHelperReferences()
326334

327335
try {
328336
foreach ($this->actionAttributes as $attrKey => $attrValue) {
329-
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(DataObjectHandler::getInstance(), $attrValue);
337+
$this->actionAttributes[$attrKey] = $this->findAndReplaceReferences(
338+
DataObjectHandler::getInstance(),
339+
$attrValue
340+
);
330341
}
331342
$isResolved = true;
332343
} catch (\Exception $e) {
@@ -339,7 +350,6 @@ private function resolveHelperReferences()
339350
. "in Action with stepKey \"{$this->getStepKey()}\"",
340351
["input" => $attrValue, "stepKey" => $this->getStepKey()]
341352
);
342-
343353
}
344354
}
345355

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private function processActionGroupArgs($actionType, $actionAttributeData)
176176
* @param string $actionType
177177
* @param array $actionAttributeData
178178
* @return array
179+
* @throws TestFrameworkException
179180
*/
180181
private function processHelperArgs($actionType, $actionAttributeData)
181182
{
@@ -187,9 +188,12 @@ private function processHelperArgs($actionType, $actionAttributeData)
187188
$actionAttributeArgData = [];
188189
foreach ($actionAttributeData as $attributeDataKey => $attributeDataValues) {
189190
if (isset($attributeDataValues['nodeName']) && $attributeDataValues['nodeName'] == 'argument') {
190-
if (isset($attributeDataValues['name']) && in_array($attributeDataValues['name'], $reservedHelperVariableNames)) {
191+
if (isset($attributeDataValues['name'])
192+
&& in_array($attributeDataValues['name'], $reservedHelperVariableNames)) {
193+
$message = 'Helper argument names ' . implode(',', $reservedHelperVariableNames);
194+
$message .= ' are reserved and can not be used.';
191195
throw new TestFrameworkException(
192-
'Helper argument names ' . implode(',', $reservedHelperVariableNames) . ' are reserved and can not be used.'
196+
$message
193197
);
194198
}
195199
$actionAttributeArgData[$attributeDataValues['name']] = $attributeDataValues['value'] ?? null;

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,21 @@ public function assembleTestPhp($testObject)
285285
return $cestPhp;
286286
}
287287

288+
/**
289+
* Generates _injectMethod based on $this->customHelpers.
290+
*
291+
* @return string
292+
*/
288293
private function generateInjectMethod()
289294
{
290295
if (empty($this->customHelpers)) {
291296
return "";
292297
}
293298

294299
$mustacheEngine = new Mustache_Engine([
295-
'loader' => new Mustache_Loader_FilesystemLoader(dirname(__DIR__) . DIRECTORY_SEPARATOR . "Helper" . DIRECTORY_SEPARATOR . 'views')
300+
'loader' => new Mustache_Loader_FilesystemLoader(
301+
dirname(__DIR__) . DIRECTORY_SEPARATOR . "Helper" . DIRECTORY_SEPARATOR . 'views'
302+
)
296303
]);
297304

298305
$argumentsWithType = [];

0 commit comments

Comments
 (0)