33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace tests \unit \Magento \FunctionalTestFramework \Test \Objects ;
89
9- use AspectMock \ Test as AspectMock ;
10+ use Exception ;
1011use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
1112use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
13+ use Magento \FunctionalTestingFramework \Exceptions \TestReferenceException ;
14+ use Magento \FunctionalTestingFramework \Exceptions \XmlException ;
1215use Magento \FunctionalTestingFramework \Page \Handlers \PageObjectHandler ;
16+ use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
1317use Magento \FunctionalTestingFramework \Page \Objects \ElementObject ;
1418use Magento \FunctionalTestingFramework \Page \Objects \PageObject ;
15- use Magento \FunctionalTestingFramework \Test \Objects \ActionObject ;
16- use Magento \FunctionalTestingFramework \Page \Handlers \SectionObjectHandler ;
1719use Magento \FunctionalTestingFramework \Page \Objects \SectionObject ;
18- use Magento \FunctionalTestingFramework \Exceptions \ TestReferenceException ;
19- use tests \ unit \ Util \ TestLoggingUtil ;
20+ use Magento \FunctionalTestingFramework \Test \ Objects \ ActionObject ;
21+ use ReflectionProperty ;
2022use tests \unit \Util \MagentoTestCase ;
23+ use tests \unit \Util \TestLoggingUtil ;
2124
2225/**
2326 * Class ActionObjectTest
2427 */
2528class ActionObjectTest extends MagentoTestCase
2629{
2730 /**
28- * Before test functionality
31+ * Before test functionality.
32+ *
2933 * @return void
3034 */
31- public function setUp (): void
35+ protected function setUp (): void
3236 {
3337 TestLoggingUtil::getInstance ()->setMockLoggingUtil ();
3438 }
3539
3640 /**
37- * The order offset should be 0 when the action is instantiated with 'before'
41+ * The order offset should be 0 when the action is instantiated with 'before'.
42+ *
43+ * @return void
3844 */
39- public function testConstructOrderBefore ()
45+ public function testConstructOrderBefore (): void
4046 {
4147 $ actionObject = new ActionObject ('stepKey ' , 'type ' , [], null , 'before ' );
4248 $ this ->assertEquals (0 , $ actionObject ->getOrderOffset ());
4349 }
4450
4551 /**
46- * The order offset should be 1 when the action is instantiated with 'after'
52+ * The order offset should be 1 when the action is instantiated with 'after'.
53+ *
54+ * @return void
4755 */
48- public function testConstructOrderAfter ()
56+ public function testConstructOrderAfter (): void
4957 {
5058 $ actionObject = new ActionObject ('stepKey ' , 'type ' , [], null , 'after ' );
5159 $ this ->assertEquals (1 , $ actionObject ->getOrderOffset ());
5260 }
5361
5462 /**
55- * {{Section.element}} should be replaced with #theElementSelector
63+ * {{Section.element}} should be replaced with #theElementSelector.
64+ *
65+ * @return void
66+ * @throws TestReferenceException
67+ * @throws XmlException
5668 */
57- public function testResolveElementInSelector ()
69+ public function testResolveElementInSelector (): void
5870 {
5971 // Set up mocks
6072 $ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -76,9 +88,13 @@ public function testResolveElementInSelector()
7688 }
7789
7890 /**
79- * {{Section.element(param)}} should replace correctly with 'stringLiterals'
91+ * {{Section.element(param)}} should replace correctly with 'stringLiterals'.
92+ *
93+ * @return void
94+ * @throws TestReferenceException
95+ * @throws XmlException
8096 */
81- public function testResolveSelectorWithOneStringLiteral ()
97+ public function testResolveSelectorWithOneStringLiteral (): void
8298 {
8399 $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
84100 'selector ' => "{{SectionObject.elementObject('stringliteral')}} " ,
@@ -99,9 +115,13 @@ public function testResolveSelectorWithOneStringLiteral()
99115 }
100116
101117 /**
102- * {{Section.element(param)}} should replace correctly with {{data.key}} references
118+ * {{Section.element(param)}} should replace correctly with {{data.key}} references.
119+ *
120+ * @return void
121+ * @throws TestReferenceException
122+ * @throws XmlException
103123 */
104- public function testResolveSelectorWithOneDataReference ()
124+ public function testResolveSelectorWithOneDataReference (): void
105125 {
106126 $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
107127 'selector ' => "{{SectionObject.elementObject(dataObject.key)}} " ,
@@ -128,9 +148,13 @@ public function testResolveSelectorWithOneDataReference()
128148 }
129149
130150 /**
131- * {{Section.element(param)}} should replace correctly with $data.key$ references
151+ * {{Section.element(param)}} should replace correctly with $data.key$ references.
152+ *
153+ * @return void
154+ * @throws TestReferenceException
155+ * @throws XmlException
132156 */
133- public function testResolveSelectorWithOnePersistedReference ()
157+ public function testResolveSelectorWithOnePersistedReference (): void
134158 {
135159 $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
136160 'selector ' => '{{SectionObject.elementObject($data.key$)}} ' ,
@@ -154,8 +178,12 @@ public function testResolveSelectorWithOnePersistedReference()
154178
155179 /**
156180 * {{Section.element(param1,param2,param3)}} should replace correctly with all 3 data types.
181+ *
182+ * @return void
183+ * @throws TestReferenceException
184+ * @throws XmlException
157185 */
158- public function testResolveSelectorWithManyParams ()
186+ public function testResolveSelectorWithManyParams (): void
159187 {
160188 $ actionObject = new ActionObject ('key123 ' , 'fillField ' , [
161189 'selector ' => "{{SectionObject.elementObject('stringLiteral', data.key, \$data.key \$)}} " ,
@@ -182,9 +210,13 @@ public function testResolveSelectorWithManyParams()
182210 }
183211
184212 /**
185- * Timeout property on the ActionObject should be set if the ElementObject has a timeout
213+ * Timeout property on the ActionObject should be set if the ElementObject has a timeout.
214+ *
215+ * @return void
216+ * @throws TestReferenceException
217+ * @throws XmlException
186218 */
187- public function testTimeoutFromElement ()
219+ public function testTimeoutFromElement (): void
188220 {
189221 // Set up mocks
190222 $ actionObject = new ActionObject ('merge123 ' , 'click ' , [
@@ -201,20 +233,27 @@ public function testTimeoutFromElement()
201233 }
202234
203235 /**
204- * {{PageObject.url}} should be replaced with someUrl.html
236+ * {{PageObject.url}} should be replaced with someUrl.html.
205237 *
206- * @throws /Exception
238+ * @return void
239+ * @throws Exception
207240 */
208- public function testResolveUrl ()
241+ public function testResolveUrl (): void
209242 {
210243 // Set up mocks
211244 $ actionObject = new ActionObject ('merge123 ' , 'amOnPage ' , [
212245 'url ' => '{{PageObject.url}} '
213246 ]);
214247 $ pageObject = new PageObject ('PageObject ' , '/replacement/url.html ' , 'Test ' , [], false , "test " );
215- $ instance = AspectMock::double (PageObjectHandler::class, ['getObject ' => $ pageObject ])
216- ->make (); // bypass the private constructor
217- AspectMock::double (PageObjectHandler::class, ['getInstance ' => $ instance ]);
248+
249+ $ instance = $ this ->createMock (PageObjectHandler::class);
250+ $ instance
251+ ->method ('getObject ' )
252+ ->willReturn ($ pageObject );
253+ // bypass the private constructor
254+ $ property = new ReflectionProperty (PageObjectHandler::class, 'INSTANCE ' );
255+ $ property ->setAccessible (true );
256+ $ property ->setValue ($ instance );
218257
219258 // Call the method under test
220259 $ actionObject ->resolveReferences ();
@@ -227,11 +266,12 @@ public function testResolveUrl()
227266 }
228267
229268 /**
230- * {{PageObject}} should not be replaced and should elicit a warning in console
269+ * {{PageObject}} should not be replaced and should elicit a warning in console.
231270 *
232- * @throws /Exception
271+ * @return void
272+ * @throws Exception
233273 */
234- public function testResolveUrlWithNoAttribute ()
274+ public function testResolveUrlWithNoAttribute (): void
235275 {
236276 $ this ->expectException (TestReferenceException::class);
237277
@@ -241,36 +281,51 @@ public function testResolveUrlWithNoAttribute()
241281 ]);
242282 $ pageObject = new PageObject ('PageObject ' , '/replacement/url.html ' , 'Test ' , [], false , "test " );
243283 $ pageObjectList = ["PageObject " => $ pageObject ];
244- $ instance = AspectMock::double (
245- PageObjectHandler::class,
246- ['getObject ' => $ pageObject , 'getAllObjects ' => $ pageObjectList ]
247- )->make (); // bypass the private constructor
248- AspectMock::double (PageObjectHandler::class, ['getInstance ' => $ instance ]);
284+
285+ $ instance = $ this ->createMock (PageObjectHandler::class);
286+ $ instance
287+ ->method ('getObject ' )
288+ ->willReturn ($ pageObject );
289+ $ instance
290+ ->method ('getAllObjects ' )
291+ ->willReturn ($ pageObjectList );
292+ // bypass the private constructor
293+ $ property = new ReflectionProperty (PageObjectHandler::class, 'INSTANCE ' );
294+ $ property ->setAccessible (true );
295+ $ property ->setValue ($ instance );
249296
250297 // Call the method under test
251298 $ actionObject ->resolveReferences ();
252299 }
253300
254301 /**
255- * {{PageObject.url(param)}} should be replaced
302+ * {{PageObject.url(param)}} should be replaced.
303+ *
304+ * @return void
256305 */
257- public function testResolveUrlWithOneParam ()
306+ public function testResolveUrlWithOneParam (): void
258307 {
259308 $ this ->markTestIncomplete ('TODO ' );
260309 }
261310
262311 /**
263- * {{PageObject.url(param1,param2,param3)}} should be replaced
312+ * {{PageObject.url(param1,param2,param3)}} should be replaced.
313+ *
314+ * @return void
264315 */
265- public function testResolveUrlWithManyParams ()
316+ public function testResolveUrlWithManyParams (): void
266317 {
267318 $ this ->markTestIncomplete ('TODO ' );
268319 }
269320
270321 /**
271- * {{EntityDataObject.key}} should be replaced with someDataValue
322+ * {{EntityDataObject.key}} should be replaced with someDataValue.
323+ *
324+ * @return void
325+ * @throws TestReferenceException
326+ * @throws XmlException
272327 */
273- public function testResolveDataInUserInput ()
328+ public function testResolveDataInUserInput (): void
274329 {
275330 // Set up mocks
276331 $ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -294,9 +349,13 @@ public function testResolveDataInUserInput()
294349 }
295350
296351 /**
297- * {{EntityDataObject.values}} should be replaced with ["value1","value2"]
352+ * {{EntityDataObject.values}} should be replaced with ["value1","value2"].
353+ *
354+ * @return void
355+ * @throws TestReferenceException
356+ * @throws XmlException
298357 */
299- public function testResolveArrayData ()
358+ public function testResolveArrayData (): void
300359 {
301360 // Set up mocks
302361 $ actionObject = new ActionObject ('merge123 ' , 'fillField ' , [
@@ -325,8 +384,12 @@ public function testResolveArrayData()
325384
326385 /**
327386 * Action object should throw an exception if a reference to a parameterized selector has too few given args.
387+ *
388+ * @return void
389+ * @throws TestReferenceException
390+ * @throws XmlException
328391 */
329- public function testTooFewArgumentException ()
392+ public function testTooFewArgumentException (): void
330393 {
331394 $ this ->expectException (TestReferenceException::class);
332395
@@ -343,8 +406,12 @@ public function testTooFewArgumentException()
343406
344407 /**
345408 * Action object should throw an exception if a reference to a parameterized selector has too many given args.
409+ *
410+ * @return void
411+ * @throws TestReferenceException
412+ * @throws XmlException
346413 */
347- public function testTooManyArgumentException ()
414+ public function testTooManyArgumentException (): void
348415 {
349416 $ this ->expectException (TestReferenceException::class);
350417
@@ -361,8 +428,12 @@ public function testTooManyArgumentException()
361428
362429 /**
363430 * Action object should throw an exception if the timezone provided is not valid.
431+ *
432+ * @return void
433+ * @throws TestReferenceException
434+ * @throws XmlException
364435 */
365- public function testInvalidTimezoneException ()
436+ public function testInvalidTimezoneException (): void
366437 {
367438 $ this ->expectException (TestReferenceException::class);
368439
@@ -374,23 +445,50 @@ public function testInvalidTimezoneException()
374445 $ actionObject ->resolveReferences ();
375446 }
376447
377- private function mockSectionHandlerWithElement ($ elementObject )
448+ /**
449+ * Mock section handler with the specified ElementObject.
450+ *
451+ * @param ElementObject $elementObject
452+ *
453+ * @return void
454+ * @throws Exception
455+ */
456+ private function mockSectionHandlerWithElement (ElementObject $ elementObject ): void
378457 {
379458 $ sectionObject = new SectionObject ('SectionObject ' , ['elementObject ' => $ elementObject ]);
380- $ instance = AspectMock::double (SectionObjectHandler::class, ['getObject ' => $ sectionObject ])
381- ->make (); // bypass the private constructor
382- AspectMock::double (SectionObjectHandler::class, ['getInstance ' => $ instance ]);
459+ $ instance = $ this ->createMock (SectionObjectHandler::class);
460+ $ instance
461+ ->method ('getObject ' )
462+ ->willReturn ($ sectionObject );
463+ // bypass the private constructor
464+ $ property = new ReflectionProperty (SectionObjectHandler::class, 'INSTANCE ' );
465+ $ property ->setAccessible (true );
466+ $ property ->setValue ($ instance );
383467 }
384468
385- private function mockDataHandlerWithData ($ dataObject )
469+ /**
470+ * Mock data handler with the specified EntityDataObject.
471+ *
472+ * @param EntityDataObject $dataObject
473+ *
474+ * @return void
475+ * @throws Exception
476+ */
477+ private function mockDataHandlerWithData (EntityDataObject $ dataObject ): void
386478 {
387- $ dataInstance = AspectMock::double (DataObjectHandler::class, ['getObject ' => $ dataObject ])
388- ->make ();
389- AspectMock::double (DataObjectHandler::class, ['getInstance ' => $ dataInstance ]);
479+ $ dataInstance = $ this ->createMock (DataObjectHandler::class);
480+ $ dataInstance
481+ ->method ('getObject ' )
482+ ->willReturn ($ dataObject );
483+ // bypass the private constructor
484+ $ property = new ReflectionProperty (DataObjectHandler::class, 'INSTANCE ' );
485+ $ property ->setAccessible (true );
486+ $ property ->setValue ($ dataInstance );
390487 }
391488
392489 /**
393- * After class functionality
490+ * After class functionality.
491+ *
394492 * @return void
395493 */
396494 public static function tearDownAfterClass (): void
0 commit comments