8
8
9
9
use AspectMock \Test as AspectMock ;
10
10
11
+ use Go \Aop \Aspect ;
11
12
use Magento \FunctionalTestingFramework \ObjectManager ;
12
13
use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
13
14
use Magento \FunctionalTestingFramework \Test \Handlers \CestObjectHandler ;
18
19
use Magento \FunctionalTestingFramework \Test \Parsers \TestDataParser ;
19
20
use Magento \FunctionalTestingFramework \Test \Util \ActionObjectExtractor ;
20
21
use Magento \FunctionalTestingFramework \Test \Util \CestObjectExtractor ;
22
+ use Magento \FunctionalTestingFramework \Test \Util \TestObjectExtractor ;
21
23
use PHPUnit \Framework \TestCase ;
22
24
23
25
class CestObjectHandlerTest extends TestCase
24
26
{
27
+ /**
28
+ * Mock cest name
29
+ *
30
+ * @var string
31
+ */
32
+ private $ testCestName = 'testCest ' ;
33
+
34
+ /**
35
+ * Mock test name
36
+ *
37
+ * @var string
38
+ */
39
+ private $ testTestName = 'testTest ' ;
40
+
41
+ /**
42
+ * Mock before action name
43
+ *
44
+ * @var string
45
+ */
46
+ private $ testActionBeforeName = 'testActionBefore ' ;
47
+
48
+ /**
49
+ * Mock after action name
50
+ *
51
+ * @var string
52
+ */
53
+ private $ testActionAfterName = 'testActionAfter ' ;
54
+
55
+ /**
56
+ * Mock test action in test name
57
+ *
58
+ * @var string
59
+ */
60
+ private $ testTestActionName = 'testActionInTest ' ;
61
+
62
+ /**
63
+ * Mock test action type
64
+ *
65
+ * @var string
66
+ */
67
+ private $ testActionType = 'testAction ' ;
68
+
25
69
/**
26
70
* Basic test to validate array => test object conversion
27
71
*/
28
72
public function testGetCestObject ()
29
73
{
30
74
// set up mock data
31
- $ testCestName = 'testCest ' ;
32
- $ testTestName = 'testTest ' ;
33
- $ testActionBeforeName = 'testActionBefore ' ;
34
- $ testActionAfterName = 'testActionAfter ' ;
35
- $ testTestActionName = 'testActionInTest ' ;
36
- $ testActionType = 'testAction ' ;
37
-
38
75
$ mockData = [CestObjectExtractor::CEST_ROOT => [
39
- $ testCestName => [
40
- CestObjectExtractor::NAME => $ testCestName ,
41
- CestObjectExtractor::CEST_BEFORE_HOOK => [
42
- $ testActionBeforeName => [
43
- ActionObjectExtractor::NODE_NAME => $ testActionType ,
44
- ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ testActionBeforeName
45
- ]
46
- ],
47
- CestObjectExtractor::CEST_AFTER_HOOK => [
48
- $ testActionAfterName => [
49
- ActionObjectExtractor::NODE_NAME => $ testActionType ,
50
- ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ testActionAfterName
76
+ $ this -> testCestName => [
77
+ CestObjectExtractor::NAME => $ this -> testCestName ,
78
+ CestObjectExtractor::CEST_BEFORE_HOOK => [
79
+ $ this -> testActionBeforeName => [
80
+ ActionObjectExtractor::NODE_NAME => $ this -> testActionType ,
81
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this -> testActionBeforeName
82
+ ]
83
+ ],
84
+ CestObjectExtractor::CEST_AFTER_HOOK => [
85
+ $ this -> testActionAfterName => [
86
+ ActionObjectExtractor::NODE_NAME => $ this -> testActionType ,
87
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this -> testActionAfterName
51
88
52
- ]
53
- ],
54
- CestObjectExtractor::CEST_ANNOTATIONS => [
55
- 'group ' => [['value ' => 'test ' ]]
56
- ],
57
- $ testTestName => [
58
- $ testTestActionName => [
59
- ActionObjectExtractor::NODE_NAME => $ testActionType ,
60
- ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ testTestActionName
61
- ],
62
89
]
90
+ ],
91
+ CestObjectExtractor::CEST_ANNOTATIONS => [
92
+ 'group ' => [['value ' => 'test ' ]]
93
+ ],
94
+ $ this ->testTestName => [
95
+ $ this ->testTestActionName => [
96
+ ActionObjectExtractor::NODE_NAME => $ this ->testActionType ,
97
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this ->testTestActionName
98
+ ],
63
99
]
64
100
]
101
+ ]
65
102
];
66
- $ mockDataParser = AspectMock::double (TestDataParser::class, ['readTestData ' => $ mockData ])->make ();
67
- $ instance = AspectMock::double (ObjectManager::class, ['create ' => $ mockDataParser ])
68
- ->make (); // bypass the private constructor
69
- AspectMock::double (ObjectManagerFactory::class, ['getObjectManager ' => $ instance ]);
103
+
104
+ $ this ->setMockParserOutput ($ mockData );
70
105
71
106
// run object handler method
72
107
$ coh = CestObjectHandler::getInstance ();
73
- $ actualCestObject = $ coh ->getObject ($ testCestName );
108
+ $ actualCestObject = $ coh ->getObject ($ this -> testCestName );
74
109
75
110
// perform asserts
76
- $ expectedBeforeActionObject = new ActionObject ($ testActionBeforeName , $ testActionType , []);
77
- $ expectedAfterActionObject = new ActionObject ($ testActionAfterName , $ testActionType , []);
111
+ $ expectedBeforeActionObject = new ActionObject ($ this -> testActionBeforeName , $ this -> testActionType , []);
112
+ $ expectedAfterActionObject = new ActionObject ($ this -> testActionAfterName , $ this -> testActionType , []);
78
113
$ expectedBeforeHookObject = new CestHookObject (
79
114
CestObjectExtractor::CEST_BEFORE_HOOK ,
80
- $ testCestName ,
115
+ $ this -> testCestName ,
81
116
[$ expectedBeforeActionObject ],
82
117
[]
83
118
);
84
119
$ expectedAfterHookObject = new CestHookObject (
85
120
CestObjectExtractor::CEST_AFTER_HOOK ,
86
- $ testCestName ,
121
+ $ this -> testCestName ,
87
122
[$ expectedAfterActionObject ],
88
123
[]
89
124
);
90
125
91
- $ expectedTestActionObject = new ActionObject ($ testTestActionName , $ testActionType , []);
92
- $ expectedTestObject = new TestObject ($ testTestName , [$ expectedTestActionObject ], [], []);
126
+ $ expectedTestActionObject = new ActionObject ($ this -> testTestActionName , $ this -> testActionType , []);
127
+ $ expectedTestObject = new TestObject ($ this -> testTestName , [$ expectedTestActionObject ], [], []);
93
128
94
129
$ expectedCestObject = new CestObject (
95
- $ testCestName ,
130
+ $ this -> testCestName ,
96
131
[
97
132
'group ' => ['test ' ]
98
133
],
99
134
[
100
- $ testTestName => $ expectedTestObject
135
+ $ this -> testTestName => $ expectedTestObject
101
136
],
102
137
[
103
138
CestObjectExtractor::CEST_BEFORE_HOOK => $ expectedBeforeHookObject ,
@@ -107,4 +142,76 @@ public function testGetCestObject()
107
142
108
143
$ this ->assertEquals ($ expectedCestObject , $ actualCestObject );
109
144
}
145
+
146
+ /**
147
+ * Tests the function used to get a series of relevant tests/cests by group
148
+ */
149
+ public function testGetCestsByGroup ()
150
+ {
151
+ // set up mock data
152
+ $ mockData = [CestObjectExtractor::CEST_ROOT => [
153
+ $ this ->testCestName => [
154
+ CestObjectExtractor::NAME => $ this ->testCestName ,
155
+ CestObjectExtractor::CEST_ANNOTATIONS => [
156
+ 'group ' => [['value ' => 'test ' ]]
157
+ ],
158
+ $ this ->testTestName => [
159
+ $ this ->testTestActionName => [
160
+ ActionObjectExtractor::NODE_NAME => $ this ->testActionType ,
161
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this ->testTestActionName
162
+ ],
163
+ ]
164
+ ],
165
+ $ this ->testCestName . '2 ' => [
166
+ CestObjectExtractor::NAME => $ this ->testCestName . '2 ' ,
167
+ $ this ->testTestName . 'Include ' => [
168
+ TestObjectExtractor::TEST_ANNOTATIONS => [
169
+ 'group ' => [['value ' => 'test ' ]]
170
+ ],
171
+ $ this ->testTestActionName => [
172
+ ActionObjectExtractor::NODE_NAME => $ this ->testActionType ,
173
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this ->testTestActionName
174
+ ],
175
+ ],
176
+ $ this ->testTestName . 'Exclude ' => [
177
+ $ this ->testTestActionName => [
178
+ ActionObjectExtractor::NODE_NAME => $ this ->testActionType ,
179
+ ActionObjectExtractor::TEST_STEP_MERGE_KEY => $ this ->testTestActionName
180
+ ],
181
+ ]
182
+ ]
183
+ ]];
184
+
185
+ $ this ->setMockParserOutput ($ mockData );
186
+
187
+ // execute test method
188
+ $ coh = CestObjectHandler::getInstance ();
189
+ $ cests = $ coh ->getCestsByGroup ('test ' );
190
+
191
+
192
+ // perform asserts
193
+ $ this ->assertCount (2 , $ cests );
194
+ $ this ->assertArrayHasKey ($ this ->testCestName . '2 ' , $ cests );
195
+ $ actualTests = $ cests [$ this ->testCestName . '2 ' ]->getTests ();
196
+ $ this ->assertArrayHasKey ($ this ->testTestName . 'Include ' , $ actualTests );
197
+ $ this ->assertArrayNotHasKey ($ this ->testTestName . 'Exclude ' , $ actualTests );
198
+ }
199
+
200
+ /**
201
+ * Function used to set mock for parser return and force init method to run between tests.
202
+ *
203
+ * @param array $data
204
+ */
205
+ private function setMockParserOutput ($ data )
206
+ {
207
+ // clear cest object handler value to inject parsed content
208
+ $ property = new \ReflectionProperty (CestObjectHandler::class, 'cestObjectHandler ' );
209
+ $ property ->setAccessible (true );
210
+ $ property ->setValue (null );
211
+
212
+ $ mockDataParser = AspectMock::double (TestDataParser::class, ['readTestData ' => $ data ])->make ();
213
+ $ instance = AspectMock::double (ObjectManager::class, ['create ' => $ mockDataParser ])
214
+ ->make (); // bypass the private constructor
215
+ AspectMock::double (ObjectManagerFactory::class, ['getObjectManager ' => $ instance ]);
216
+ }
110
217
}
0 commit comments