Skip to content

Commit 4d0fd88

Browse files
authored
Merge pull request #707 from magento/MQE-2130
MQE-2130: All PayPal SmartButton tests fail with error even though th…
2 parents 2e1f815 + 369cb63 commit 4d0fd88

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

src/Magento/FunctionalTestingFramework/Helper/HelperContainer.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types = 1);
67

78
namespace Magento\FunctionalTestingFramework\Helper;
89

@@ -11,20 +12,30 @@
1112
/**
1213
* Class HelperContainer
1314
*/
14-
class HelperContainer
15+
class HelperContainer extends \Codeception\Module
1516
{
1617
/**
1718
* @var Helper[]
1819
*/
1920
private $helpers = [];
2021

2122
/**
22-
* HelperContainer constructor.
23-
* @param array $helpers
23+
* Create custom helper class.
24+
*
25+
* @param string $helperClass
26+
* @return Helper
27+
* @throws \Exception
2428
*/
25-
public function __construct(array $helpers = [])
29+
public function create(string $helperClass): Helper
2630
{
27-
$this->helpers = $helpers;
31+
if (get_parent_class($helperClass) !== Helper::class) {
32+
throw new \Exception("Helper class must extend " . Helper::class);
33+
}
34+
if (!isset($this->helpers[$helperClass])) {
35+
$this->helpers[$helperClass] = $this->moduleContainer->create($helperClass);
36+
}
37+
38+
return $this->helpers[$helperClass];
2839
}
2940

3041
/**
@@ -34,7 +45,7 @@ public function __construct(array $helpers = [])
3445
* @return Helper
3546
* @throws TestFrameworkException
3647
*/
37-
public function get(string $className)
48+
public function get(string $className): Helper
3849
{
3950
if ($this->has($className)) {
4051
return $this->helpers[$className];
@@ -48,7 +59,7 @@ public function get(string $className)
4859
* @param string $className
4960
* @return boolean
5061
*/
51-
public function has(string $className)
62+
public function has(string $className): bool
5263
{
5364
return array_key_exists($className, $this->helpers);
5465
}

src/Magento/FunctionalTestingFramework/Helper/views/TestInjectMethod.mustache

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
/**
77
* Special method which automatically creates the respective objects.
88
*/
9-
public function _inject(
10-
{{argumentsWithTypes}}
11-
) {
12-
$this->helperContainer = new \Magento\FunctionalTestingFramework\Helper\HelperContainer(
13-
[
14-
{{#arguments}}
15-
'{{type}}' => {{var}},
16-
{{/arguments}}
17-
]
18-
);
9+
public function _inject(\Magento\FunctionalTestingFramework\Helper\HelperContainer $helperContainer)
10+
{
11+
$this->helperContainer = $helperContainer;
12+
{{#arguments}}
13+
$this->helperContainer->create("{{type}}");
14+
{{/arguments}}
1915
}

src/Magento/FunctionalTestingFramework/ObjectManager/ObjectHandlerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function getInstance();
2424
* Function to return a single object by name
2525
*
2626
* @param string $objectName
27-
* @return object
27+
* @return mixed
2828
*/
2929
public function getObject($objectName);
3030

src/Magento/FunctionalTestingFramework/Suite/Generators/GroupClassGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,18 @@ private function buildHookMustacheArray($hookObj)
131131
{
132132
$actions = [];
133133
$mustacheHookArray['actions'][] = ['webDriverInit' => true];
134+
$mustacheHookArray['helpers'] = [];
134135

135136
foreach ($hookObj->getActions() as $action) {
136137
/** @var ActionObject $action */
137138
$index = count($actions);
139+
if ($action->getType() === ActionObject::ACTION_TYPE_HELPER) {
140+
$mustacheHookArray['helpers'][] = $action->getCustomActionAttributes()['class'];
141+
}
138142
//deleteData contains either url or createDataKey, if it contains the former it needs special formatting
139143
if ($action->getType() !== "createData"
140144
&& !array_key_exists(TestGenerator::REQUIRED_ENTITY_REFERENCE, $action->getCustomActionAttributes())) {
141-
$actions = $this->buildWebDriverActionsMustacheArray($action, $actions, $index);
145+
$actions = $this->buildWebDriverActionsMustacheArray($action, $actions);
142146
continue;
143147
}
144148

src/Magento/FunctionalTestingFramework/Suite/views/SuiteClass.mustache

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,25 @@ class {{suiteName}} extends \Codeception\GroupObject
2020
private $testCount = {{testCount}};
2121
private $preconditionFailure = null;
2222
private $currentTestRun = 0;
23+
{{#helpers}}
24+
/**
25+
* @var \Magento\FunctionalTestingFramework\Helper\HelperContainer $helperContainer
26+
*/
27+
private $helperContainer;
28+
{{/helpers}}
2329
private static $HOOK_EXECUTION_INIT = "\n/******** Beginning execution of {{suiteName}} suite %s block ********/\n";
2430
private static $HOOK_EXECUTION_END = "\n/******** Execution of {{suiteName}} suite %s block complete ********/\n";
2531

2632
{{#before}}
2733
public function _before(\Codeception\Event\TestEvent $e)
2834
{
35+
{{#helpers}}
36+
/** @var \Magento\FunctionalTestingFramework\Helper\HelperContainer $helperContainer */
37+
$this->helperContainer = $this->getModule('\Magento\FunctionalTestingFramework\Helper\HelperContainer');
38+
{{/helpers}}
39+
{{#helpers}}
40+
$this->helperContainer->create("{{ . }}");
41+
{{/helpers}}
2942
// increment test count per execution
3043
$this->currentTestRun++;
3144
$this->executePreConditions();

0 commit comments

Comments
 (0)