Skip to content

Commit cf94261

Browse files
authored
Merge branch 'develop' into MQE-2212
2 parents 044341a + 20af7fd commit cf94261

22 files changed

+739
-185
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/DataObjectHandlerTest.php

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\FunctionalTestingFramework\ObjectManager;
1414
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1515
use tests\unit\Util\MagentoTestCase;
16+
use tests\unit\Util\ObjectHandlerUtil;
1617
use tests\unit\Util\TestLoggingUtil;
1718

1819
/**
@@ -148,7 +149,7 @@ public function setUp(): void
148149
*/
149150
public function testGetAllObjects()
150151
{
151-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
152+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);
152153

153154
// Call the method under test
154155
$actual = DataObjectHandler::getInstance()->getAllObjects();
@@ -164,7 +165,7 @@ public function testGetAllObjects()
164165
*/
165166
public function testDeprecatedDataObject()
166167
{
167-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_DEPRECATED);
168+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_DEPRECATED);
168169

169170
// Call the method under test
170171
$actual = DataObjectHandler::getInstance()->getAllObjects();
@@ -182,7 +183,7 @@ public function testDeprecatedDataObject()
182183
*/
183184
public function testGetObject()
184185
{
185-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
186+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);
186187

187188
// Call the method under test
188189
$actual = DataObjectHandler::getInstance()->getObject('EntityOne');
@@ -197,7 +198,7 @@ public function testGetObject()
197198
*/
198199
public function testGetObjectNull()
199200
{
200-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
201+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);
201202

202203
$actual = DataObjectHandler::getInstance()->getObject('h953u789h0g73t521'); // doesnt exist
203204
$this->assertNull($actual);
@@ -208,7 +209,7 @@ public function testGetObjectNull()
208209
*/
209210
public function testGetAllObjectsWithDataExtends()
210211
{
211-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND);
212+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND);
212213

213214
// Call the method under test
214215
$actual = DataObjectHandler::getInstance()->getAllObjects();
@@ -232,7 +233,7 @@ public function testGetAllObjectsWithDataExtends()
232233
*/
233234
public function testGetObjectWithDataExtends()
234235
{
235-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND);
236+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND);
236237

237238
// Call the method under test
238239
$actual = DataObjectHandler::getInstance()->getObject('EntityTwo');
@@ -255,7 +256,7 @@ public function testGetObjectWithDataExtends()
255256
*/
256257
public function testGetAllObjectsWithDataExtendsItself()
257258
{
258-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
259+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
259260

260261
$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException::class);
261262
$this->expectExceptionMessage(
@@ -272,7 +273,7 @@ public function testGetAllObjectsWithDataExtendsItself()
272273
*/
273274
public function testGetObjectWithDataExtendsItself()
274275
{
275-
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
276+
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
276277

277278
$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException::class);
278279
$this->expectExceptionMessage(
@@ -286,33 +287,6 @@ public function testGetObjectWithDataExtendsItself()
286287
);
287288
}
288289

289-
/**
290-
* Set up everything required to mock DataObjectHander::getInstance()
291-
* The first call to getInstance() uses these mocks to emulate the parser, initializing internal state
292-
* according to the PARSER_OUTPUT value
293-
*
294-
* @param array $entityDataArray
295-
*/
296-
private function setUpMockDataObjectHander($entityDataArray)
297-
{
298-
// Clear DataObjectHandler singleton if already set
299-
$property = new \ReflectionProperty(DataObjectHandler::class, "INSTANCE");
300-
$property->setAccessible(true);
301-
$property->setValue(null);
302-
303-
$mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
304-
'readDataProfiles' => $entityDataArray
305-
])->make();
306-
307-
$mockObjectManager = AspectMock::double(ObjectManager::class, [
308-
'create' => $mockDataProfileSchemaParser
309-
])->make();
310-
311-
AspectMock::double(ObjectManagerFactory::class, [
312-
'getObjectManager' => $mockObjectManager
313-
]);
314-
}
315-
316290
/**
317291
* clean up function runs after all tests
318292
*/

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/OperationDefinitionObjectHandlerTest.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
1515
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\OperationDefinitionParser;
1616
use tests\unit\Util\MagentoTestCase;
17+
use tests\unit\Util\ObjectHandlerUtil;
1718
use tests\unit\Util\TestLoggingUtil;
1819

1920
/**
@@ -72,7 +73,7 @@ public function testGetMultipleObjects()
7273
],
7374
]
7475
]]];
75-
$this->setMockParserOutput($mockData);
76+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
7677

7778
//Perform Assertions
7879
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -109,7 +110,7 @@ public function testDeprecatedOperation()
109110
],
110111
OperationDefinitionObjectHandler::OBJ_DEPRECATED => 'deprecation message'
111112
]]];
112-
$this->setMockParserOutput($mockData);
113+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
113114

114115
//Perform Assertions
115116
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -239,7 +240,7 @@ public function testObjectCreation()
239240
);
240241

241242
// Set up mocked data output
242-
$this->setMockParserOutput($mockData);
243+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
243244

244245
// Get Operation
245246
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -337,7 +338,7 @@ public function testObjectArrayCreation()
337338
);
338339

339340
// Set up mocked data output
340-
$this->setMockParserOutput($mockData);
341+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
341342

342343
// Get Operation
343344
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -405,7 +406,7 @@ public function testLooseJsonCreation()
405406
);
406407

407408
// Set up mocked data output
408-
$this->setMockParserOutput($mockData);
409+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
409410

410411
// get Operations
411412
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -416,29 +417,6 @@ public function testLooseJsonCreation()
416417
$this->assertEquals($array, $operation->getOperationMetadata()[1]);
417418
}
418419

419-
/**
420-
* Function used to set mock for parser return and force init method to run between tests.
421-
*
422-
* @param array $data
423-
*/
424-
private function setMockParserOutput($data)
425-
{
426-
// clear Operation object handler value to inject parsed content
427-
$property = new \ReflectionProperty(
428-
OperationDefinitionObjectHandler::class,
429-
'INSTANCE'
430-
);
431-
$property->setAccessible(true);
432-
$property->setValue(null);
433-
434-
$mockOperationParser = AspectMock::double(
435-
OperationDefinitionParser::class,
436-
["readOperationMetadata" => $data]
437-
)->make();
438-
$instance = AspectMock::double(ObjectManager::class, ['create' => $mockOperationParser])->make();
439-
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
440-
}
441-
442420
/**
443421
* clean up function runs after all tests
444422
*/

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\FunctionalTestingFramework\ObjectManager;
1717
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1818
use tests\unit\Util\MagentoTestCase;
19+
use tests\unit\Util\ObjectHandlerUtil;
1920
use tests\unit\Util\TestLoggingUtil;
2021

2122
/**
@@ -84,7 +85,7 @@ public function testCreateSimpleEntity()
8485
";
8586

8687
// Mock Classes
87-
$this->mockDataHandlerWithOutput($parserOutput);
88+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
8889
$this->mockCurlHandler($jsonResponse);
8990
$handler = PersistedObjectHandler::getInstance();
9091

@@ -127,7 +128,7 @@ public function testDeleteSimpleEntity()
127128
";
128129

129130
// Mock Classes
130-
$this->mockDataHandlerWithOutput($parserOutput);
131+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
131132
$this->mockCurlHandler($jsonResponse);
132133
$handler = PersistedObjectHandler::getInstance();
133134

@@ -175,7 +176,7 @@ public function testGetSimpleEntity()
175176
";
176177

177178
// Mock Classes
178-
$this->mockDataHandlerWithOutput($parserOutput);
179+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
179180
$this->mockCurlHandler($jsonResponse);
180181
$handler = PersistedObjectHandler::getInstance();
181182

@@ -235,7 +236,7 @@ public function testUpdateSimpleEntity()
235236
";
236237

237238
// Mock Classes
238-
$this->mockDataHandlerWithOutput($parserOutput);
239+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
239240
$this->mockCurlHandler($jsonResponse);
240241
$handler = PersistedObjectHandler::getInstance();
241242
$handler->createEntity(
@@ -322,7 +323,7 @@ public function testRetrieveEntityAcrossScopes()
322323
// Mock Classes and Create Entities
323324
$handler = PersistedObjectHandler::getInstance();
324325

325-
$this->mockDataHandlerWithOutput($parserOutputOne);
326+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
326327
$this->mockCurlHandler($jsonReponseOne);
327328
$handler->createEntity(
328329
$entityStepKeyOne,
@@ -399,7 +400,7 @@ public function testRetrieveEntityValidField($name, $key, $value, $type, $scope,
399400
// Mock Classes and Create Entities
400401
$handler = PersistedObjectHandler::getInstance();
401402

402-
$this->mockDataHandlerWithOutput($parserOutputOne);
403+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
403404
$this->mockCurlHandler($jsonReponseOne);
404405
$handler->createEntity($stepKey, $scope, $name);
405406

@@ -447,8 +448,7 @@ public function testRetrieveEntityInValidField($name, $key, $value, $type, $scop
447448

448449
// Mock Classes and Create Entities
449450
$handler = PersistedObjectHandler::getInstance();
450-
451-
$this->mockDataHandlerWithOutput($parserOutputOne);
451+
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
452452
$this->mockCurlHandler($jsonReponseOne);
453453
$handler->createEntity($stepKey, $scope, $name);
454454

@@ -475,31 +475,6 @@ public static function entityDataProvider()
475475
];
476476
}
477477

478-
/**
479-
* Mocks DataObjectHandler to use given output to create
480-
* @param $parserOutput
481-
* @throws \Exception
482-
*/
483-
public function mockDataHandlerWithOutput($parserOutput)
484-
{
485-
// Clear DataObjectHandler singleton if already set
486-
$property = new \ReflectionProperty(DataObjectHandler::class, "INSTANCE");
487-
$property->setAccessible(true);
488-
$property->setValue(null);
489-
490-
$mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
491-
'readDataProfiles' => $parserOutput
492-
])->make();
493-
494-
$mockObjectManager = AspectMock::double(ObjectManager::class, [
495-
'create' => $mockDataProfileSchemaParser
496-
])->make();
497-
498-
AspectMock::double(ObjectManagerFactory::class, [
499-
'getObjectManager' => $mockObjectManager
500-
]);
501-
}
502-
503478
public function mockCurlHandler($response)
504479
{
505480
AspectMock::double(CurlHandler::class, [

dev/tests/unit/Magento/FunctionalTestFramework/Page/Handlers/PageObjectHandlerTest.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
1313
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
1414
use tests\unit\Util\MagentoTestCase;
15+
use tests\unit\Util\ObjectHandlerUtil;
1516
use tests\unit\Util\TestLoggingUtil;
1617

1718
class PageObjectHandlerTest extends MagentoTestCase
@@ -45,7 +46,7 @@ public function testGetPageObject()
4546
],
4647
"area" => "test"
4748
]];
48-
$this->setMockParserOutput($mockData);
49+
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);
4950

5051
// get pages
5152
$pageHandler = PageObjectHandler::getInstance();
@@ -70,7 +71,7 @@ public function testGetEmptyPage()
7071
],
7172
"area" => "test"
7273
]];
73-
$this->setMockParserOutput($mockData);
74+
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);
7475

7576
// get pages
7677
$page = PageObjectHandler::getInstance()->getObject('testPage1');
@@ -91,7 +92,7 @@ public function testDeprecatedPage()
9192
"deprecated" => "deprecation message",
9293
"filename" => "filename.xml"
9394
]];
94-
$this->setMockParserOutput($mockData);
95+
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);
9596

9697
// get pages
9798
$page = PageObjectHandler::getInstance()->getObject('testPage1');
@@ -103,23 +104,6 @@ public function testDeprecatedPage()
103104
);
104105
}
105106

106-
/**
107-
* Function used to set mock for parser return and force init method to run between tests.
108-
*
109-
* @param array $data
110-
*/
111-
private function setMockParserOutput($data)
112-
{
113-
// clear section object handler value to inject parsed content
114-
$property = new \ReflectionProperty(PageObjectHandler::class, 'INSTANCE');
115-
$property->setAccessible(true);
116-
$property->setValue(null);
117-
118-
$mockSectionParser = AspectMock::double(PageParser::class, ["getData" => $data])->make();
119-
$instance = AspectMock::double(ObjectManager::class, ['get' => $mockSectionParser])->make();
120-
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
121-
}
122-
123107
/**
124108
* clean up function runs after all tests
125109
*/

0 commit comments

Comments
 (0)