Skip to content

Commit 4d54ae4

Browse files
committed
MQE-2229: Deprecation Error When Deprecated ActionGroup References Deprecated Element
Added ObjectHandlerUtil for mocking Handlers
1 parent 06b683d commit 4d54ae4

File tree

9 files changed

+146
-186
lines changed

9 files changed

+146
-186
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testGetMultipleObjects()
7373
],
7474
]
7575
]]];
76-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
76+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
7777

7878
//Perform Assertions
7979
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -110,7 +110,7 @@ public function testDeprecatedOperation()
110110
],
111111
OperationDefinitionObjectHandler::OBJ_DEPRECATED => 'deprecation message'
112112
]]];
113-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
113+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
114114

115115
//Perform Assertions
116116
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -240,7 +240,7 @@ public function testObjectCreation()
240240
);
241241

242242
// Set up mocked data output
243-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
243+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
244244

245245
// Get Operation
246246
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -338,7 +338,7 @@ public function testObjectArrayCreation()
338338
);
339339

340340
// Set up mocked data output
341-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
341+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
342342

343343
// Get Operation
344344
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
@@ -406,7 +406,7 @@ public function testLooseJsonCreation()
406406
);
407407

408408
// Set up mocked data output
409-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
409+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
410410

411411
// get Operations
412412
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();

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
*/

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

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

1718
class SectionObjectHandlerTest extends MagentoTestCase
@@ -46,7 +47,7 @@ public function testGetSectionObject()
4647
]
4748
];
4849

49-
$this->setMockParserOutput($mockData);
50+
ObjectHandlerUtil::mockSectionObjectHandlerWithData($mockData);
5051

5152
// get sections
5253
$sectionHandler = SectionObjectHandler::getInstance();
@@ -77,7 +78,7 @@ public function testDeprecatedSection()
7778
]
7879
];
7980

80-
$this->setMockParserOutput($mockData);
81+
ObjectHandlerUtil::mockSectionObjectHandlerWithData($mockData);
8182

8283
// get sections
8384
$sectionHandler = SectionObjectHandler::getInstance();
@@ -91,23 +92,6 @@ public function testDeprecatedSection()
9192
);
9293
}
9394

94-
/**
95-
* Set the mock parser return value
96-
*
97-
* @param array $data
98-
*/
99-
private function setMockParserOutput($data)
100-
{
101-
// clear section object handler value to inject parsed content
102-
$property = new \ReflectionProperty(SectionObjectHandler::class, "INSTANCE");
103-
$property->setAccessible(true);
104-
$property->setValue(null);
105-
106-
$mockSectionParser = AspectMock::double(SectionParser::class, ["getData" => $data])->make();
107-
$instance = AspectMock::double(ObjectManager::class, ["get" => $mockSectionParser])->make();
108-
AspectMock::double(ObjectManagerFactory::class, ["getObjectManager" => $instance]);
109-
}
110-
11195
/**
11296
* clean up function runs after all tests
11397
*/

dev/tests/unit/Magento/FunctionalTestFramework/StaticCheck/DeprecatedEntityUsageCheckTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function testViolatingMetaDataReferences()
194194
]
195195
]]];
196196

197-
ObjectHandlerUtil::getInstance()->setMockOperationParserOutput($mockData);
197+
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);
198198
$dataName = 'dataName1';
199199
$references = [
200200
$dataName => [

0 commit comments

Comments
 (0)