Skip to content

Commit 87460cf

Browse files
committed
Merge branch 'PR846' into kevin-unit-test-prs
2 parents a4d7c33 + 648f8b2 commit 87460cf

File tree

1 file changed

+97
-34
lines changed

1 file changed

+97
-34
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionGroupObjectTest.php

+97-34
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace tests\unit\Magento\FunctionalTestFramework\Test\Objects;
89

9-
use AspectMock\Test as AspectMock;
1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
1111
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
1212
use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler;
@@ -15,28 +15,33 @@
1515
use Magento\FunctionalTestingFramework\Test\Objects\ActionGroupObject;
1616
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1717
use Magento\FunctionalTestingFramework\Test\Objects\ArgumentObject;
18-
use tests\unit\Util\MagentoTestCase;
18+
use ReflectionProperty;
1919
use tests\unit\Util\ActionGroupObjectBuilder;
2020
use tests\unit\Util\EntityDataObjectBuilder;
21+
use tests\unit\Util\MagentoTestCase;
2122
use tests\unit\Util\TestLoggingUtil;
2223

2324
class ActionGroupObjectTest extends MagentoTestCase
2425
{
2526
const ACTION_GROUP_MERGE_KEY = 'TestKey';
2627

2728
/**
28-
* Before test functionality
29+
* Before test functionality.
30+
*
2931
* @return void
3032
*/
31-
public function setUp(): void
33+
protected function setUp(): void
3234
{
3335
TestLoggingUtil::getInstance()->setMockLoggingUtil();
3436
}
3537

3638
/**
37-
* Tests a string literal in an action group
39+
* Tests a string literal in an action group.
40+
*
41+
* @return void
42+
* @throws TestReferenceException
3843
*/
39-
public function testGetStepsWithDefaultCase()
44+
public function testGetStepsWithDefaultCase(): void
4045
{
4146
$entity = (new EntityDataObjectBuilder())
4247
->withDataFields(['field1' => 'testValue'])
@@ -48,9 +53,12 @@ public function testGetStepsWithDefaultCase()
4853
}
4954

5055
/**
51-
* Tests a data reference in an action group, replaced by the user
56+
* Tests a data reference in an action group, replaced by the user.
57+
*
58+
* @return void
59+
* @throws TestReferenceException
5260
*/
53-
public function testGetStepsWithCustomArgs()
61+
public function testGetStepsWithCustomArgs(): void
5462
{
5563
$this->setEntityObjectHandlerReturn(function ($entityName) {
5664
if ($entityName == "data2") {
@@ -87,8 +95,11 @@ public function testGetStepsWithCustomArgs()
8795

8896
/**
8997
* Tests a data reference in an action group replaced with a persisted reference.
98+
*
99+
* @return void
100+
* @throws TestReferenceException
90101
*/
91-
public function testGetStepsWithPersistedArgs()
102+
public function testGetStepsWithPersistedArgs(): void
92103
{
93104
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
94105
->withActionObjects([new ActionObject('action1', 'testAction', ['userInput' => '{{arg1.field2}}'])])
@@ -110,8 +121,11 @@ public function testGetStepsWithPersistedArgs()
110121

111122
/**
112123
* Tests a data reference in an action group replaced with a data.field reference.
124+
*
125+
* @return void
126+
* @throws TestReferenceException
113127
*/
114-
public function testGetStepsWithNoFieldArg()
128+
public function testGetStepsWithNoFieldArg(): void
115129
{
116130
$this->setEntityObjectHandlerReturn(function ($entityName) {
117131
if ($entityName == "data2") {
@@ -130,8 +144,11 @@ public function testGetStepsWithNoFieldArg()
130144

131145
/**
132146
* Tests a data reference in an action group resolved with its default state.
147+
*
148+
* @return void
149+
* @throws TestReferenceException
133150
*/
134-
public function testGetStepsWithNoArgs()
151+
public function testGetStepsWithNoArgs(): void
135152
{
136153
$this->setEntityObjectHandlerReturn(function ($entityName) {
137154
if ($entityName == "data1") {
@@ -149,8 +166,11 @@ public function testGetStepsWithNoArgs()
149166

150167
/**
151168
* Tests a parameterized section reference in an action group resolved with user args.
169+
*
170+
* @return void
171+
* @throws TestReferenceException
152172
*/
153-
public function testGetStepsWithParameterizedArg()
173+
public function testGetStepsWithParameterizedArg(): void
154174
{
155175
// Mock Entity Object Handler
156176
$this->setEntityObjectHandlerReturn(function ($entityName) {
@@ -161,9 +181,14 @@ public function testGetStepsWithParameterizedArg()
161181
// mock the section object handler response
162182
$element = new ElementObject("element1", "textArea", ".selector {{var1}}", null, null, true);
163183
$section = new SectionObject("testSection", ["element1" => $element]);
184+
$sectionInstance = $this->createMock(SectionObjectHandler::class);
185+
$sectionInstance
186+
->method('getObject')
187+
->willReturn($section);
164188
// bypass the private constructor
165-
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $section])->make();
166-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
189+
$property = new ReflectionProperty(SectionObjectHandler::class, 'INSTANCE');
190+
$property->setAccessible(true);
191+
$property->setValue($sectionInstance);
167192

168193
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
169194
->withActionObjects(
@@ -183,8 +208,11 @@ public function testGetStepsWithParameterizedArg()
183208

184209
/**
185210
* Tests a parameterized section reference in an action group resolved with user simpleArgs.
211+
*
212+
* @return void
213+
* @throws TestReferenceException
186214
*/
187-
public function testGetStepsWithParameterizedSimpleArg()
215+
public function testGetStepsWithParameterizedSimpleArg(): void
188216
{
189217
// Mock Entity Object Handler
190218
$this->setEntityObjectHandlerReturn(function ($entityName) {
@@ -195,9 +223,15 @@ public function testGetStepsWithParameterizedSimpleArg()
195223
// mock the section object handler response
196224
$element = new ElementObject("element1", "textArea", ".selector {{var1}}", null, null, true);
197225
$section = new SectionObject("testSection", ["element1" => $element]);
226+
227+
$sectionInstance = $this->createMock(SectionObjectHandler::class);
228+
$sectionInstance
229+
->method('getObject')
230+
->willReturn($section);
198231
// bypass the private constructor
199-
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $section])->make();
200-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
232+
$property = new ReflectionProperty(SectionObjectHandler::class, 'INSTANCE');
233+
$property->setAccessible(true);
234+
$property->setValue($sectionInstance);
201235

202236
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
203237
->withActionObjects(
@@ -221,8 +255,11 @@ public function testGetStepsWithParameterizedSimpleArg()
221255

222256
/**
223257
* Tests a data reference in an action group resolved with a persisted reference used in another function.
258+
*
259+
* @return void
260+
* @throws TestReferenceException
224261
*/
225-
public function testGetStepsWithOuterScopePersistence()
262+
public function testGetStepsWithOuterScopePersistence(): void
226263
{
227264
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
228265
->withActionObjects([new ActionObject('action1', 'testAction', ['userInput' => '{{arg1.field1}}'])])
@@ -235,8 +272,10 @@ public function testGetStepsWithOuterScopePersistence()
235272

236273
/**
237274
* Tests an action group with mismatching args.
275+
*
276+
* @return void
238277
*/
239-
public function testExceptionOnMissingActions()
278+
public function testExceptionOnMissingActions(): void
240279
{
241280
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
242281
->withArguments([new ArgumentObject('arg1', null, 'entity')])
@@ -249,8 +288,10 @@ public function testExceptionOnMissingActions()
249288

250289
/**
251290
* Tests an action group with missing args.
291+
*
292+
* @return void
252293
*/
253-
public function testExceptionOnMissingArguments()
294+
public function testExceptionOnMissingArguments(): void
254295
{
255296
$actionGroupUnderTest = (new ActionGroupObjectBuilder())
256297
->withArguments([new ArgumentObject('arg1', null, 'entity')])
@@ -262,10 +303,12 @@ public function testExceptionOnMissingArguments()
262303
}
263304

264305
/**
265-
* Tests the stepKey replacement with "stepKey + invocationKey" process filter
266-
* Specific to actions that make it past a "require stepKey replacement" filter
306+
* Tests the stepKey replacement with "stepKey + invocationKey" process filter.
307+
* Specific to actions that make it past a "require stepKey replacement" filter.
308+
*
309+
* @return void
267310
*/
268-
public function testStepKeyReplacementFilteredIn()
311+
public function testStepKeyReplacementFilteredIn(): void
269312
{
270313
$createStepKey = "createDataStepKey";
271314
$updateStepKey = "updateDataStepKey";
@@ -293,10 +336,12 @@ public function testStepKeyReplacementFilteredIn()
293336
}
294337

295338
/**
296-
* Tests the stepKey replacement with "stepKey + invocationKey" process filter
297-
* Specific to actions that make are removed by a "require stepKey replacement" filter
339+
* Tests the stepKey replacement with "stepKey + invocationKey" process filter.
340+
* Specific to actions that make are removed by a "require stepKey replacement" filter.
341+
*
342+
* @return void
298343
*/
299-
public function testStepKeyReplacementFilteredOut()
344+
public function testStepKeyReplacementFilteredOut(): void
300345
{
301346
$clickStepKey = "clickStepKey";
302347
$fillFieldStepKey = "fillFieldStepKey";
@@ -322,13 +367,26 @@ public function testStepKeyReplacementFilteredOut()
322367
* duration of a single test case.
323368
*
324369
* @param mixed $return
370+
*
325371
* @return void
326372
*/
327-
private function setEntityObjectHandlerReturn($return)
373+
private function setEntityObjectHandlerReturn($return): void
328374
{
329-
$instance = AspectMock::double(DataObjectHandler::class, ['getObject' => $return])
330-
->make(); // bypass the private constructor
331-
AspectMock::double(DataObjectHandler::class, ['getInstance' => $instance]);
375+
$instance = $this->createMock(DataObjectHandler::class);
376+
377+
if (is_callable($return)) {
378+
$instance
379+
->method('getObject')
380+
->will($this->returnCallback($return));
381+
} else {
382+
$instance
383+
->method('getObject')
384+
->willReturn($return);
385+
}
386+
// bypass the private constructor
387+
$property = new ReflectionProperty(DataObjectHandler::class, 'INSTANCE');
388+
$property->setAccessible(true);
389+
$property->setValue($instance);
332390
}
333391

334392
/**
@@ -337,11 +395,15 @@ private function setEntityObjectHandlerReturn($return)
337395
*
338396
* @param array $actions
339397
* @param array $expectedValue
340-
* @param string $expectedMergeKey
398+
* @param string|null $expectedMergeKey
399+
*
341400
* @return void
342401
*/
343-
private function assertOnMergeKeyAndActionValue($actions, $expectedValue, $expectedMergeKey = null)
344-
{
402+
private function assertOnMergeKeyAndActionValue(
403+
array $actions,
404+
array $expectedValue,
405+
?string $expectedMergeKey = null
406+
): void {
345407
$expectedMergeKey = $expectedMergeKey ??
346408
ActionGroupObjectBuilder::DEFAULT_ACTION_OBJECT_NAME . self::ACTION_GROUP_MERGE_KEY;
347409
$this->assertArrayHasKey($expectedMergeKey, $actions);
@@ -352,7 +414,8 @@ private function assertOnMergeKeyAndActionValue($actions, $expectedValue, $expec
352414
}
353415

354416
/**
355-
* After class functionality
417+
* After class functionality.
418+
*
356419
* @return void
357420
*/
358421
public static function tearDownAfterClass(): void

0 commit comments

Comments
 (0)