Skip to content

Commit cc7a6a7

Browse files
committed
MQE-610:
Refactored to keep Cyclomatic complexity <= 10. Added comments to below files to refactor later ** Config/FileResolver/Module.php ** Config/Converter.php ** Config/Dom.php
1 parent 3f6bb8c commit cc7a6a7

File tree

13 files changed

+250
-124
lines changed

13 files changed

+250
-124
lines changed

src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public function testError(FailEvent $failEvent)
219219
* Override of parent method, polls stepStorage for testcase and formats it according to actionGroup nesting.
220220
*
221221
* @return void
222-
* @SuppressWarnings(PHPMD)
223222
*/
224223
public function testEnd()
225224
{
@@ -245,11 +244,7 @@ public function testEnd()
245244

246245
$step->setName(str_replace(ActionGroupObject::ACTION_GROUP_CONTEXT_START, '', $step->getName()));
247246
$actionGroupStepContainer = $step;
248-
249-
preg_match(TestGenerator::ACTION_GROUP_STEP_KEY_REGEX, $step->getName(), $matches);
250-
if (!empty($matches['actionGroupStepKey'])) {
251-
$actionGroupStepKey = ucfirst($matches['actionGroupStepKey']);
252-
}
247+
$actionGroupStepKey = $this->retrieveActionGroupStepKey($step);
253248
continue;
254249
}
255250

@@ -289,6 +284,25 @@ function () use ($rootStep, $formattedSteps) {
289284
$this->getLifecycle()->fire(new TestCaseFinishedEvent());
290285
}
291286

287+
/**
288+
* Reads action group stepKey from step.
289+
*
290+
* @param $step
291+
* @return string|null
292+
*/
293+
private function retrieveActionGroupStepKey($step)
294+
{
295+
$actionGroupStepKey = null;
296+
297+
preg_match(TestGenerator::ACTION_GROUP_STEP_KEY_REGEX, $step->getName(), $matches);
298+
299+
if (!empty($matches['actionGroupStepKey'])) {
300+
$actionGroupStepKey = ucfirst($matches['actionGroupStepKey']);
301+
}
302+
303+
return $actionGroupStepKey;
304+
}
305+
292306
/**
293307
* Reading stepKey from file.
294308
*

src/Magento/FunctionalTestingFramework/Codeception/Subscriber/Console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Console extends \Codeception\Subscriber\Console
3838
* @param array $extensionOptions
3939
* @param array $options
4040
*
41-
* @SuppressWarnings(PHPMD)
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4242
*/
4343
public function __construct($extensionOptions = [], $options = [])
4444
{

src/Magento/FunctionalTestingFramework/Config/Converter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function convert($source)
8383
* @param \DOMNodeList|array $elements
8484
* @return array
8585
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
86+
* @TODO ported magento code to be refactored later
8687
*/
8788
protected function convertXml($elements)
8889
{

src/Magento/FunctionalTestingFramework/Config/Dom.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ protected function mergeNode(\DOMElement $node, $parentPath)
145145
* @return void
146146
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
147147
* @SuppressWarnings(PHPMD.NPathComplexity)
148+
* @TODO Ported magento code to be refactored later
148149
*/
149150
protected function mergeMatchingNode(\DomElement $node, $parentPath, $matchedNode, $path)
150151
{

src/Magento/FunctionalTestingFramework/Config/FileResolver/Module.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Module implements FileResolverInterface
2626
* Module constructor.
2727
* @param ModuleResolver|null $moduleResolver
2828
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29+
* @TODO ported magento code to be refactored later
2930
*/
3031
public function __construct(ModuleResolver $moduleResolver = null)
3132
{

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/EntityDataObject.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public function getAllData()
161161
* @param integer $uniquenessFormat
162162
* @return string|null
163163
* @throws TestFrameworkException
164-
* @SuppressWarnings(PHPMD)
165164
*/
166165
public function getDataByName($name, $uniquenessFormat)
167166
{
@@ -177,12 +176,25 @@ public function getDataByName($name, $uniquenessFormat)
177176
throw new TestFrameworkException($exceptionMessage);
178177
}
179178

180-
$name_lower = strtolower($name);
181-
182179
if ($this->data === null) {
183180
return null;
184181
}
182+
return $this->resolveDataReferences($name, $uniquenessFormat);
183+
}
185184

185+
/**
186+
* Resolves data references in entities while generating static test files.
187+
*
188+
* @param $name
189+
* @param $uniquenessFormat
190+
* @return string|null
191+
* @throws TestFrameworkException
192+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
193+
*/
194+
195+
private function resolveDataReferences($name, $uniquenessFormat)
196+
{
197+
$name_lower = strtolower($name);
186198
$dataReferenceResolver = new GenerationDataReferenceResolver();
187199
if (array_key_exists($name_lower, $this->data)) {
188200
if (is_array($this->data[$name_lower])) {

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/OperationDataArrayResolver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function __construct($dependentEntities = null)
6666
* @param boolean $fromArray
6767
* @return array
6868
* @throws \Exception
69-
* @SuppressWarnings(PHPMD)
7069
*/
7170
public function resolveOperationDataArray($entityObject, $operationMetadata, $operation, $fromArray = false)
7271
{
@@ -120,7 +119,20 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
120119
);
121120
}
122121
}
122+
return $this->resolveRunTimeDataReferences($operationDataArray, $entityObject);
123+
}
124+
125+
/**
126+
* Resolve data references at run time.
127+
* @param $operationDataArray
128+
* @param $entityObject
129+
* @return mixed
130+
* @throws TestFrameworkException
131+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
132+
*/
123133

134+
private function resolveRunTimeDataReferences($operationDataArray, $entityObject)
135+
{
124136
$dataReferenceResolver = new RuntimeDataReferenceResolver();
125137
foreach ($operationDataArray as $key => $operationDataValue) {
126138
if (is_array($operationDataValue)) {

src/Magento/FunctionalTestingFramework/Extension/PageReadinessExtension.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public function beforeTest(TestEvent $e)
106106
* @param StepEvent $e
107107
* @return void
108108
* @throws \Exception
109-
*
110-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
111109
*/
112110
public function beforeStep(StepEvent $e)
113111
{
@@ -117,7 +115,25 @@ public function beforeStep(StepEvent $e)
117115
return;
118116
}
119117

120-
// Check if page has changed and reset metric tracking if so
118+
$this->resetMetricTracker($step);
119+
120+
$metrics = $this->readinessMetrics;
121+
122+
$this->waitForReadiness($metrics);
123+
124+
/** @var AbstractMetricCheck $metric */
125+
foreach ($metrics as $metric) {
126+
$metric->finalizeForStep($step);
127+
}
128+
}
129+
130+
/**
131+
* Check if page has changed, if so reset metric tracking
132+
*
133+
* @param $step
134+
*/
135+
private function resetMetricTracker($step)
136+
{
121137
if ($this->pageChanged($step)) {
122138
$this->logDebug(
123139
'Page URI changed; resetting readiness metric failure tracking',
@@ -131,16 +147,22 @@ public function beforeStep(StepEvent $e)
131147
$metric->resetTracker();
132148
}
133149
}
150+
}
134151

152+
/**
153+
* Wait for page readiness.
154+
* @param $metrics
155+
* @throws \Codeception\Exception\ModuleRequireException
156+
* @throws \Facebook\WebDriver\Exception\NoSuchElementException
157+
*/
158+
private function waitForReadiness($metrics){
135159
// todo: Implement step parameter to override global timeout configuration
136160
if (isset($this->config['timeout'])) {
137161
$timeout = intval($this->config['timeout']);
138162
} else {
139163
$timeout = $this->getDriver()->_getConfig()['pageload_timeout'];
140164
}
141165

142-
$metrics = $this->readinessMetrics;
143-
144166
try {
145167
$this->getDriver()->webDriver->wait($timeout)->until(
146168
function () use ($metrics) {
@@ -160,11 +182,6 @@ function () use ($metrics) {
160182
);
161183
} catch (TimeoutException $exception) {
162184
}
163-
164-
/** @var AbstractMetricCheck $metric */
165-
foreach ($metrics as $metric) {
166-
$metric->finalizeForStep($step);
167-
}
168185
}
169186

170187
/**

src/Magento/FunctionalTestingFramework/ObjectManager/Config/Mapper/Dom.php

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public function __construct(
4848
* @return array
4949
* @throws \Exception
5050
* @todo this method has high cyclomatic complexity in order to avoid performance issues
51-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
52-
* @SuppressWarnings(PHPMD.NPathComplexity)
53-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
5451
*/
5552
public function convert($config)
5653
{
@@ -83,33 +80,7 @@ public function convert($config)
8380
$typeData['type'] = $attributeType->nodeValue;
8481
}
8582
}
86-
$typeArguments = [];
87-
/** @var \DOMNode $typeChildNode */
88-
foreach ($node->childNodes as $typeChildNode) {
89-
if ($typeChildNode->nodeType != XML_ELEMENT_NODE) {
90-
continue;
91-
}
92-
switch ($typeChildNode->nodeName) {
93-
case 'arguments':
94-
/** @var \DOMNode $argumentNode */
95-
foreach ($typeChildNode->childNodes as $argumentNode) {
96-
if ($argumentNode->nodeType != XML_ELEMENT_NODE) {
97-
continue;
98-
}
99-
$argumentName = $argumentNode->attributes->getNamedItem('name')->nodeValue;
100-
$argumentData = $this->argumentParser->parse($argumentNode);
101-
$typeArguments[$argumentName] = $this->argumentInterpreter->evaluate(
102-
$argumentData
103-
);
104-
}
105-
break;
106-
default:
107-
throw new \Exception(
108-
"Invalid application config. Unknown node: {$typeChildNode->nodeName}."
109-
);
110-
}
111-
}
112-
83+
$typeArguments = $this->parseTypeArguments($node);
11384
$typeData['arguments'] = $typeArguments;
11485
$output[$typeNodeAttributes->getNamedItem('name')->nodeValue] = $typeData;
11586
break;
@@ -120,4 +91,39 @@ public function convert($config)
12091

12192
return $output;
12293
}
94+
95+
/** Read typeChildNodes and set typeArguments
96+
* @param $node
97+
* @return mixed
98+
* @throws \Exception
99+
*/
100+
private function parseTypeArguments($node)
101+
{
102+
foreach ($node->childNodes as $typeChildNode) {
103+
/** @var \DOMNode $typeChildNode */
104+
if ($typeChildNode->nodeType != XML_ELEMENT_NODE) {
105+
continue;
106+
}
107+
switch ($typeChildNode->nodeName) {
108+
case 'arguments':
109+
/** @var \DOMNode $argumentNode */
110+
foreach ($typeChildNode->childNodes as $argumentNode) {
111+
if ($argumentNode->nodeType != XML_ELEMENT_NODE) {
112+
continue;
113+
}
114+
$argumentName = $argumentNode->attributes->getNamedItem('name')->nodeValue;
115+
$argumentData = $this->argumentParser->parse($argumentNode);
116+
$typeArguments[$argumentName] = $this->argumentInterpreter->evaluate(
117+
$argumentData
118+
);
119+
}
120+
return $typeArguments;
121+
122+
default:
123+
throw new \Exception(
124+
"Invalid application config. Unknown node: {$typeChildNode->nodeName}."
125+
);
126+
}
127+
}
128+
}
123129
}

src/Magento/FunctionalTestingFramework/ObjectManager/Factory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function prepareArguments($object, $method, array $arguments = [])
101101
* @throws \UnexpectedValueException
102102
* @throws \BadMethodCallException
103103
*
104-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
105104
* @SuppressWarnings(PHPMD.NPathComplexity)
106105
*/
107106
protected function resolveArguments($requestedType, array $parameters, array $arguments = [])

src/Magento/FunctionalTestingFramework/ObjectManager/Factory/Dynamic/Developer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ protected function parseArray(&$array)
171171
* @return object
172172
* @throws \Exception
173173
*
174-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
175174
* @SuppressWarnings(PHPCPD)
176175
*/
177176
public function create($requestedType, array $arguments = [])

0 commit comments

Comments
 (0)