Skip to content

Commit c8d905c

Browse files
authored
MQE-672: Generate failed hook with after hook
- Modified the Object Extractor so it creates a "_failed" block when it generates an "_after" block.
1 parent 850d8b6 commit c8d905c

18 files changed

+294
-27
lines changed

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
class TestObjectHandlerTest extends TestCase
2525
{
2626
/**
27-
* Basic test to validate array => test object conversion
27+
* Basic test to validate array => test object conversion.
28+
*
29+
* @throws \Exception
2830
*/
2931
public function testGetTestObject()
3032
{
3133
// set up mock data
3234
$testDataArrayBuilder = new TestDataArrayBuilder();
3335
$mockData = $testDataArrayBuilder
3436
->withAnnotations()
37+
->withFailedHook()
3538
->withAfterHook()
3639
->withBeforeHook()
3740
->withTestActions()
@@ -54,17 +57,26 @@ public function testGetTestObject()
5457
$testDataArrayBuilder->testActionType,
5558
[]
5659
);
60+
$expectedFailedActionObject = new ActionObject(
61+
$testDataArrayBuilder->testActionAfterName,
62+
$testDataArrayBuilder->testActionType,
63+
[]
64+
);
65+
5766
$expectedBeforeHookObject = new TestHookObject(
5867
TestObjectExtractor::TEST_BEFORE_HOOK,
5968
$testDataArrayBuilder->testName,
60-
[$expectedBeforeActionObject],
61-
[]
69+
[$expectedBeforeActionObject]
6270
);
6371
$expectedAfterHookObject = new TestHookObject(
6472
TestObjectExtractor::TEST_AFTER_HOOK,
6573
$testDataArrayBuilder->testName,
66-
[$expectedAfterActionObject],
67-
[]
74+
[$expectedAfterActionObject]
75+
);
76+
$expectedFailedHookObject = new TestHookObject(
77+
TestObjectExtractor::TEST_FAILED_HOOK,
78+
$testDataArrayBuilder->testName,
79+
[$expectedFailedActionObject]
6880
);
6981

7082
$expectedTestActionObject = new ActionObject(
@@ -80,7 +92,8 @@ public function testGetTestObject()
8092
],
8193
[
8294
TestObjectExtractor::TEST_BEFORE_HOOK => $expectedBeforeHookObject,
83-
TestObjectExtractor::TEST_AFTER_HOOK => $expectedAfterHookObject
95+
TestObjectExtractor::TEST_AFTER_HOOK => $expectedAfterHookObject,
96+
TestObjectExtractor::TEST_FAILED_HOOK => $expectedFailedHookObject
8497
],
8598
[]
8699
);
@@ -89,7 +102,9 @@ public function testGetTestObject()
89102
}
90103

91104
/**
92-
* Tests the function used to get a series of relevant tests by group
105+
* Tests the function used to get a series of relevant tests by group.
106+
*
107+
* @throws \Exception
93108
*/
94109
public function testGetTestsByGroup()
95110
{
@@ -120,6 +135,7 @@ public function testGetTestsByGroup()
120135
* Function used to set mock for parser return and force init method to run between tests.
121136
*
122137
* @param array $data
138+
* @throws \Exception
123139
*/
124140
private function setMockParserOutput($data)
125141
{

dev/tests/unit/Util/TestDataArrayBuilder.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class TestDataArrayBuilder
3232
*/
3333
public $testActionAfterName = 'testActionAfter';
3434

35+
/**
36+
* Mock failed action name
37+
*
38+
* @var string
39+
*/
40+
public $testActionFailedName = 'testActionFailed';
41+
3542
/**
3643
* Mock test action in test name
3744
*
@@ -61,6 +68,11 @@ class TestDataArrayBuilder
6168
*/
6269
private $afterHook = [];
6370

71+
/**
72+
* @var array
73+
*/
74+
private $failedHook = [];
75+
6476
/**
6577
* @var array
6678
*/
@@ -134,6 +146,27 @@ public function withAfterHook($afterHook = null)
134146
return $this;
135147
}
136148

149+
/**
150+
* Add a failed hook passed in by arg (or default if no arg)
151+
*
152+
* @param null $failedHook
153+
* @return $this
154+
*/
155+
public function withFailedHook($failedHook = null)
156+
{
157+
if ($failedHook == null) {
158+
$this->failedHook = [$this->testActionFailedName => [
159+
ActionObjectExtractor::NODE_NAME => $this->testActionType,
160+
ActionObjectExtractor::TEST_STEP_MERGE_KEY => $this->testActionFailedName
161+
162+
]];
163+
} else {
164+
$this->failedHook = $failedHook;
165+
}
166+
167+
return $this;
168+
}
169+
137170
/**
138171
* Add test actions passed in by arg (or default if no arg)
139172
*
@@ -167,7 +200,8 @@ public function build()
167200
TestObjectExtractor::NAME => $this->testName,
168201
TestObjectExtractor::TEST_ANNOTATIONS => $this->annotations,
169202
TestObjectExtractor::TEST_BEFORE_HOOK => $this->beforeHook,
170-
TestObjectExtractor::TEST_AFTER_HOOK => $this->afterHook
203+
TestObjectExtractor::TEST_AFTER_HOOK => $this->afterHook,
204+
TestObjectExtractor::TEST_FAILED_HOOK => $this->failedHook
171205
],
172206
$this->testActions
173207
)];

dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ActionGroupWithDataOverrideTestCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ActionGroupWithDataOverrideTestCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

dev/tests/verification/Resources/ActionGroupWithDataTest.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ActionGroupWithDataTestCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ActionGroupWithDataTestCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ActionGroupWithNoDefaultTestCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ActionGroupWithNoDefaultTestCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

dev/tests/verification/Resources/ActionGroupWithPersistedData.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ActionGroupWithPersistedDataCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ActionGroupWithPersistedDataCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ActionGroupWithTopLevelPersistedDataCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ActionGroupWithTopLevelPersistedDataCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ class ArgumentWithSameNameAsElementCest
2525
{
2626
/**
2727
* @var DataPersistenceHandler $createPersonParam;
28-
*/
28+
*/
2929
protected $createPersonParam;
3030

31+
/**
32+
* @param AcceptanceTester $I
33+
* @throws \Exception
34+
*/
3135
public function _before(AcceptanceTester $I)
3236
{
3337
$I->amGoingTo("create entity that has the stepKey: createPersonParam");
@@ -38,12 +42,26 @@ class ArgumentWithSameNameAsElementCest
3842
$I->fillField("#bar", "myData2");
3943
}
4044

45+
/**
46+
* @param AcceptanceTester $I
47+
* @throws \Exception
48+
*/
4149
public function _after(AcceptanceTester $I)
4250
{
4351
$I->fillField("#foo", "myData1");
4452
$I->fillField("#bar", "myData2");
4553
}
4654

55+
/**
56+
* @param AcceptanceTester $I
57+
* @throws \Exception
58+
*/
59+
public function _failed(AcceptanceTester $I)
60+
{
61+
$I->fillField("#foo", "myData1");
62+
$I->fillField("#bar", "myData2");
63+
}
64+
4765
/**
4866
* @Severity(level = SeverityLevel::CRITICAL)
4967
* @Parameter(name = "AcceptanceTester", value="$I")

0 commit comments

Comments
 (0)