Skip to content

Commit 70b04c6

Browse files
committed
MQE-550: [Unit Test] ActionObject.php
- CR Fixes.
1 parent 0ad8a98 commit 70b04c6

File tree

1 file changed

+24
-39
lines changed

1 file changed

+24
-39
lines changed

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

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public function testResolveElementInSelector()
5151
'userInput' => 'Hello world'
5252
]);
5353
$elementObject = new ElementObject('elementObject', 'button', '#replacementSelector', null, '42', false);
54-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
55-
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
56-
->make(); // bypass the private constructor
57-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
54+
$this->mockSectionHandlerWithElement($elementObject);
5855

5956
// Call the method under test
6057
$actionObject->resolveReferences();
@@ -77,10 +74,7 @@ public function testResolveSelectorWithOneStringLiteral()
7774
'userInput' => 'Input'
7875
]);
7976
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
80-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
81-
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
82-
->make(); // bypass the private constructor
83-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
77+
$this->mockSectionHandlerWithElement($elementObject);
8478

8579
// Call the method under test
8680
$actionObject->resolveReferences();
@@ -105,16 +99,11 @@ public function testResolveSelectorWithOneDataReference()
10599

106100
// Mock SectionHandler
107101
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
108-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
109-
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
110-
->make(); // bypass the private constructor
111-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
102+
$this->mockSectionHandlerWithElement($elementObject);
112103

113104
// Mock DataHandler
114105
$dataObject = new EntityDataObject('dataObject', 'dataType', ["key" => 'myValue'], null, null, null);
115-
$dataInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $dataObject])
116-
->make();
117-
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
106+
$this->mockDataHandlerWithElement($dataObject);
118107

119108
// Call the method under test
120109
$actionObject->resolveReferences();
@@ -139,10 +128,7 @@ public function testResolveSelectorWithOnePersistedReference()
139128

140129
// Mock SectionHandler
141130
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
142-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
143-
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
144-
->make(); // bypass the private constructor
145-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
131+
$this->mockSectionHandlerWithElement($elementObject);
146132

147133
// Call the method under test
148134
$actionObject->resolveReferences();
@@ -167,16 +153,11 @@ public function testResolveSelectorWithManyParams()
167153

168154
// Mock SectionHandler
169155
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}[{{var2}},{{var3}}]', null, '42', true);
170-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
171-
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
172-
->make(); // bypass the private constructor
173-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
156+
$this->mockSectionHandlerWithElement($elementObject);
174157

175158
// Mock DataHandler
176159
$dataObject = new EntityDataObject('dataObject', 'dataType', ["key" => 'myValue'], null, null, null);
177-
$dataInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $dataObject])
178-
->make();
179-
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
160+
$this->mockDataHandlerWithElement($dataObject);
180161

181162
// Call the method under test
182163
$actionObject->resolveReferences();
@@ -199,10 +180,7 @@ public function testTimeoutFromElement()
199180
'selector' => '{{SectionObject.elementObject}}'
200181
]);
201182
$elementObject = new ElementObject('elementObject', 'button', '#replacementSelector', null, '42', false);
202-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
203-
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
204-
->make(); // bypass the private constructor
205-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
183+
$this->mockSectionHandlerWithElement($elementObject);
206184

207185
// Call the method under test
208186
$actionObject->resolveReferences();
@@ -264,9 +242,7 @@ public function testResolveDataInUserInput()
264242
$entityDataObject = new EntityDataObject('EntityDataObject', 'test', [
265243
'key' => 'replacementData'
266244
], [], '', '');
267-
$instance = AspectMock::double(DataObjectHandler::class, ['getObject' => $entityDataObject])
268-
->make(); // bypass the private constructor
269-
AspectMock::double(DataObjectHandler::class, ['getInstance' => $instance]);
245+
$this->mockDataHandlerWithElement($entityDataObject);
270246

271247
// Call the method under test
272248
$actionObject->resolveReferences();
@@ -291,10 +267,7 @@ public function testTooFewArgumentException()
291267
'userInput' => 'Input'
292268
]);
293269
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}} {{var2}}', null, '42', true);
294-
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
295-
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
296-
->make(); // bypass the private constructor
297-
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
270+
$this->mockSectionHandlerWithElement($elementObject);
298271

299272
// Call the method under test
300273
$actionObject->resolveReferences();
@@ -312,12 +285,24 @@ public function testTooManyArgumentException()
312285
'userInput' => 'Input'
313286
]);
314287
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
288+
$this->mockSectionHandlerWithElement($elementObject);
289+
290+
// Call the method under test
291+
$actionObject->resolveReferences();
292+
}
293+
294+
private function mockSectionHandlerWithElement($elementObject)
295+
{
315296
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
316297
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
317298
->make(); // bypass the private constructor
318299
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
300+
}
319301

320-
// Call the method under test
321-
$actionObject->resolveReferences();
302+
private function mockDataHandlerWithElement($dataObject)
303+
{
304+
$dataInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $dataObject])
305+
->make();
306+
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
322307
}
323308
}

0 commit comments

Comments
 (0)