88
99use AspectMock \Test as AspectMock ;
1010
11+ use Go \Aop \Aspect ;
1112use Magento \FunctionalTestingFramework \ObjectManager ;
1213use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
1314use Magento \FunctionalTestingFramework \Test \Handlers \CestObjectHandler ;
1819use Magento \FunctionalTestingFramework \Test \Parsers \TestDataParser ;
1920use Magento \FunctionalTestingFramework \Test \Util \ActionObjectExtractor ;
2021use Magento \FunctionalTestingFramework \Test \Util \CestObjectExtractor ;
22+ use Magento \FunctionalTestingFramework \Test \Util \TestObjectExtractor ;
2123use PHPUnit \Framework \TestCase ;
2224
2325class CestObjectHandlerTest extends TestCase
2426{
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+
2569 /**
2670 * Basic test to validate array => test object conversion
2771 */
2872 public function testGetCestObject ()
2973 {
3074 // set up mock data
31- $ testCestName = 'testCest ' ;
32- $ testTestName = 'testTest ' ;
33- $ testActionBeforeName = 'testActionBefore ' ;
34- $ testActionAfterName = 'testActionAfter ' ;
35- $ testTestActionName = 'testActionInTest ' ;
36- $ testActionType = 'testAction ' ;
37-
3875 $ 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
5188
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- ],
6289 ]
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+ ],
6399 ]
64100 ]
101+ ]
65102 ];
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 );
70105
71106 // run object handler method
72107 $ coh = CestObjectHandler::getInstance ();
73- $ actualCestObject = $ coh ->getObject ($ testCestName );
108+ $ actualCestObject = $ coh ->getObject ($ this -> testCestName );
74109
75110 // 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 , []);
78113 $ expectedBeforeHookObject = new CestHookObject (
79114 CestObjectExtractor::CEST_BEFORE_HOOK ,
80- $ testCestName ,
115+ $ this -> testCestName ,
81116 [$ expectedBeforeActionObject ],
82117 []
83118 );
84119 $ expectedAfterHookObject = new CestHookObject (
85120 CestObjectExtractor::CEST_AFTER_HOOK ,
86- $ testCestName ,
121+ $ this -> testCestName ,
87122 [$ expectedAfterActionObject ],
88123 []
89124 );
90125
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 ], [], []);
93128
94129 $ expectedCestObject = new CestObject (
95- $ testCestName ,
130+ $ this -> testCestName ,
96131 [
97132 'group ' => ['test ' ]
98133 ],
99134 [
100- $ testTestName => $ expectedTestObject
135+ $ this -> testTestName => $ expectedTestObject
101136 ],
102137 [
103138 CestObjectExtractor::CEST_BEFORE_HOOK => $ expectedBeforeHookObject ,
@@ -107,4 +142,76 @@ public function testGetCestObject()
107142
108143 $ this ->assertEquals ($ expectedCestObject , $ actualCestObject );
109144 }
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+ }
110217}
0 commit comments