Skip to content

Commit 4e21292

Browse files
KevinBKozanjilu1
authored andcommitted
MQE-211: Implement exception handling in TestObject.
1 parent 33823bc commit 4e21292

File tree

7 files changed

+51
-19
lines changed

7 files changed

+51
-19
lines changed

entryPoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
require_once 'bootstrap.php';
44

55
/** @var Magento\AcceptanceTestFramework\Dummy $dummy */
6-
$dummy = $objectManager->create(\Magento\AcceptanceTestFramework\Dummy::class);
7-
$dummy->readPageObjects();
6+
//$dummy = $objectManager->create(\Magento\AcceptanceTestFramework\Dummy::class);
7+
//$dummy->readPageObjects();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Magento\AcceptanceTestFramework\Exceptions;
4+
5+
use Exception;
6+
7+
class XmlException extends Exception
8+
{
9+
public function __construct($message)
10+
{
11+
parent::__construct($message);
12+
}
13+
14+
}

src/Magento/AcceptanceTestFramework/Test/ActionObject.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function __construct($name, $actor, $function, $selector, $parameter, $or
2121
$this->function = $function;
2222
$this->selector = $selector;
2323
$this->parameter = $parameter;
24-
$this->linkedAction = $linkedAction;
2524
$this->returnVariable = $returnVariable;
2625
$this->userInput = $userInput;
26+
$this->linkedAction = $linkedAction;
2727

2828
if ($order == 'after') {
2929
$this->orderOffset = 1;
@@ -55,11 +55,6 @@ public function getSelector()
5555
return $this->selector;
5656
}
5757

58-
public function getLinkedAction()
59-
{
60-
return $this->linkedAction;
61-
}
62-
6358
public function getReturnVariable()
6459
{
6560
return $this->returnVariable;
@@ -70,7 +65,12 @@ public function getUserInput()
7065
return $this->userInput;
7166
}
7267

73-
public function getOrderOffset()
68+
public function getLinkedAction()
69+
{
70+
return $this->linkedAction;
71+
}
72+
73+
public function getOrderOffset(): int
7474
{
7575
return $this->orderOffset;
7676
}

src/Magento/AcceptanceTestFramework/Test/CestDataConstants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class CestDataConstants
2323
const TEST_ACTION_ACTOR = 'actor';
2424
const TEST_ACTION_PARAMETER = 'parameter';
2525
const TEST_ACTION_SELECTOR = 'selector';
26-
const TEST_ACTION_ORDER = 'order';
27-
const TEST_ACTION_LINK = 'linkedAction';
26+
const TEST_ACTION_BEFORE = 'before';
27+
const TEST_ACTION_AFTER = 'after';
2828
const TEST_ACTION_USER_INPUT = 'userInput';
2929
const TEST_ACTION_RETURN_VARIABLE = 'returnVariable';
3030

src/Magento/AcceptanceTestFramework/Test/CestDataManager.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Magento\AcceptanceTestFramework\Test;
44

55
use Magento\AcceptanceTestFramework\ObjectManagerFactory;
6+
use Magento\AcceptanceTestFramework\Exceptions\XmlException;
67

78
class CestDataManager
89
{
10+
const BEFORE_AFTER_ERROR_MSG = "Merge Error - Steps cannot have both before and after attributes.\tTestStep='%s'";
11+
912
public static function getCestData()
1013
{
1114
$cestDataParser = ObjectManagerFactory::getObjectManager()->create(TestDataParser::class);
@@ -135,9 +138,9 @@ private static function extractTestActions($testActions)
135138
$actor = null;
136139
$parameter = null;
137140
$selector = null;
138-
$linkedAction = null;
139141
$userInput = null;
140142
$returnVariable = null;
143+
$linkedAction = null;
141144
$order = null;
142145

143146
if (array_key_exists(CestDataConstants::TEST_ACTION_ACTOR, $actionData)) {
@@ -150,9 +153,17 @@ private static function extractTestActions($testActions)
150153
$selector = $actionData[CestDataConstants::TEST_ACTION_SELECTOR];
151154
}
152155

153-
if (array_key_exists(CestDataConstants::TEST_ACTION_LINK, $actionData)) {
154-
$linkedAction = $actionData[CestDataConstants::TEST_ACTION_LINK];
155-
$order = $actionData [CestDataConstants::TEST_ACTION_ORDER];
156+
if (array_key_exists(CestDataConstants::TEST_ACTION_BEFORE, $actionData)
157+
and array_key_exists(CestDataConstants::TEST_ACTION_AFTER, $actionData)) {
158+
throw new XmlException(sprintf(self::BEFORE_AFTER_ERROR_MSG, $actionName));
159+
}
160+
161+
if (array_key_exists(CestDataConstants::TEST_ACTION_BEFORE, $actionData)) {
162+
$linkedAction = $actionData[CestDataConstants::TEST_ACTION_BEFORE];
163+
$order = "before";
164+
} elseif (array_key_exists(CestDataConstants::TEST_ACTION_AFTER, $actionData)) {
165+
$linkedAction = $actionData[CestDataConstants::TEST_ACTION_AFTER];
166+
$order = "after";
156167
}
157168

158169
if (array_key_exists(CestDataConstants::TEST_ACTION_USER_INPUT, $actionData)) {

src/Magento/AcceptanceTestFramework/Test/TestObject.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Magento\AcceptanceTestFramework\Test;
44

5+
use Magento\AcceptanceTestFramework\Exceptions\XmlException;
6+
57
class TestObject
68
{
79
private $name;
@@ -10,6 +12,7 @@ class TestObject
1012
private $parsedSteps = [];
1113
private $dependencies = [];
1214
private $annotations = [];
15+
private const STEP_MISSING_ERROR_MSG = "Merge Error - Step could not be found in either TestXML or DeltaXML.\tTest = '%s'\tTestStep='%s'\tLinkedStep'%s'";
1316

1417
public function __construct($name, $dependencies, $parsedSteps, $annotations)
1518
{
@@ -47,6 +50,7 @@ public function getOrderedActions()
4750
/**
4851
* This method takes the steps from the parser and splits steps which need merge from steps that are ordered.
4952
* @return void
53+
* @throws XmlException
5054
*/
5155
private function sortActions()
5256
{
@@ -79,14 +83,17 @@ private function mergeActions()
7983
/**
8084
* Recursively merges in each step and its dependencies
8185
* @param ActionObject $stepToMerge
86+
* @throws XmlException
8287
* @return void
8388
*/
8489
private function mergeAction($stepToMerge)
8590
{
8691
$linkedStep = $stepToMerge->getLinkedAction();
8792

88-
if (!array_key_exists($linkedStep, $this->orderedSteps)) {
89-
$this->mergeAction($this->stepsToMerge[$stepToMerge->getLinkedAction()]);
93+
if (!array_key_exists($linkedStep, $this->orderedSteps) and !array_key_exists($linkedStep, $this->stepsToMerge)) {
94+
throw new XmlException(sprintf(self::STEP_MISSING_ERROR_MSG, $this->getName(), $stepToMerge->getName(), $linkedStep));
95+
} elseif (!array_key_exists($linkedStep, $this->orderedSteps)) {
96+
$this->mergeAction($this->stepsToMerge[$linkedStep]);
9097
}
9198

9299
$position = array_search($linkedStep, array_keys($this->orderedSteps)) + $stepToMerge->getOrderOffset();

src/Magento/AcceptanceTestFramework/Test/etc/testSchema.xsd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
<xs:attribute name="returnVariable" type="xs:string" use="optional"></xs:attribute>
5151
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
5252
<xs:attribute name="userInput" type="xs:string" use="optional"></xs:attribute>
53-
<xs:attribute name="order" type="xs:string" use="optional"></xs:attribute>
54-
<xs:attribute name="linkedAction" type="xs:string" use="optional"></xs:attribute>
53+
<xs:attribute name="before" type="xs:string" use="optional"></xs:attribute>
54+
<xs:attribute name="after" type="xs:string" use="optional"></xs:attribute>
5555
<xs:attributeGroup ref="removeAttribute"/>
5656
</xs:complexType>
5757

0 commit comments

Comments
 (0)