10
10
use Exception ;
11
11
use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
12
12
use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
13
+ use Magento \FunctionalTestingFramework \DataGenerator \Parsers \DataProfileSchemaParser ;
13
14
use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
15
+ use Magento \FunctionalTestingFramework \ObjectManager ;
16
+ use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
17
+ use ReflectionProperty ;
14
18
use tests \unit \Util \MagentoTestCase ;
15
- use tests \unit \Util \ObjectHandlerUtil ;
16
19
use tests \unit \Util \TestLoggingUtil ;
17
20
18
21
/**
@@ -151,7 +154,7 @@ protected function setUp(): void
151
154
*/
152
155
public function testGetAllObjects (): void
153
156
{
154
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
157
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
155
158
156
159
// Call the method under test
157
160
$ actual = DataObjectHandler::getInstance ()->getAllObjects ();
@@ -170,10 +173,10 @@ public function testGetAllObjects(): void
170
173
*/
171
174
public function testDeprecatedDataObject (): void
172
175
{
173
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_DEPRECATED );
176
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_DEPRECATED );
174
177
175
178
// Call the method under test
176
- $ actual = DataObjectHandler::getInstance ()->getAllObjects ();
179
+ DataObjectHandler::getInstance ()->getAllObjects ();
177
180
178
181
//validate deprecation warning
179
182
TestLoggingUtil::getInstance ()->validateMockLogStatement (
@@ -191,7 +194,7 @@ public function testDeprecatedDataObject(): void
191
194
*/
192
195
public function testGetObject (): void
193
196
{
194
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
197
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
195
198
196
199
// Call the method under test
197
200
$ actual = DataObjectHandler::getInstance ()->getObject ('EntityOne ' );
@@ -209,7 +212,7 @@ public function testGetObject(): void
209
212
*/
210
213
public function testGetObjectNull (): void
211
214
{
212
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
215
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
213
216
214
217
$ actual = DataObjectHandler::getInstance ()->getObject ('h953u789h0g73t521 ' ); // doesnt exist
215
218
$ this ->assertNull ($ actual );
@@ -223,7 +226,7 @@ public function testGetObjectNull(): void
223
226
*/
224
227
public function testGetAllObjectsWithDataExtends (): void
225
228
{
226
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
229
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
227
230
228
231
// Call the method under test
229
232
$ actual = DataObjectHandler::getInstance ()->getAllObjects ();
@@ -250,7 +253,7 @@ public function testGetAllObjectsWithDataExtends(): void
250
253
*/
251
254
public function testGetObjectWithDataExtends (): void
252
255
{
253
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
256
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
254
257
255
258
// Call the method under test
256
259
$ actual = DataObjectHandler::getInstance ()->getObject ('EntityTwo ' );
@@ -276,7 +279,7 @@ public function testGetObjectWithDataExtends(): void
276
279
*/
277
280
public function testGetAllObjectsWithDataExtendsItself (): void
278
281
{
279
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
282
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
280
283
281
284
$ this ->expectException (TestFrameworkException::class);
282
285
$ this ->expectExceptionMessage (
@@ -296,7 +299,7 @@ public function testGetAllObjectsWithDataExtendsItself(): void
296
299
*/
297
300
public function testGetObjectWithDataExtendsItself (): void
298
301
{
299
- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
302
+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
300
303
301
304
$ this ->expectException (TestFrameworkException::class);
302
305
$ this ->expectExceptionMessage (
@@ -310,11 +313,66 @@ public function testGetObjectWithDataExtendsItself(): void
310
313
);
311
314
}
312
315
316
+ /**
317
+ * Create mock data object handler with data.
318
+ *
319
+ * @param array $mockData
320
+ *
321
+ * @return void
322
+ */
323
+ private function mockDataObjectHandlerWithData (array $ mockData ): void
324
+ {
325
+ $ dataObjectHandlerProperty = new ReflectionProperty (DataObjectHandler::class, "INSTANCE " );
326
+ $ dataObjectHandlerProperty ->setAccessible (true );
327
+ $ dataObjectHandlerProperty ->setValue (null );
328
+
329
+ $ mockDataProfileSchemaParser = $ this ->createMock (DataProfileSchemaParser::class);
330
+ $ mockDataProfileSchemaParser
331
+ ->method ('readDataProfiles ' )
332
+ ->willReturn ($ mockData );
333
+
334
+ $ objectManager = ObjectManagerFactory::getObjectManager ();
335
+ $ mockObjectManagerInstance = $ this ->createMock (ObjectManager::class);
336
+ $ mockObjectManagerInstance
337
+ ->method ('create ' )
338
+ ->will (
339
+ $ this ->returnCallback (
340
+ function (
341
+ string $ class ,
342
+ array $ arguments = []
343
+ ) use (
344
+ $ objectManager ,
345
+ $ mockDataProfileSchemaParser
346
+ ) {
347
+ if ($ class === DataProfileSchemaParser::class) {
348
+ return $ mockDataProfileSchemaParser ;
349
+ }
350
+
351
+ return $ objectManager ->create ($ class , $ arguments );
352
+ }
353
+ )
354
+ );
355
+
356
+ $ property = new ReflectionProperty (ObjectManager::class, 'instance ' );
357
+ $ property ->setAccessible (true );
358
+ $ property ->setValue ($ mockObjectManagerInstance );
359
+ }
360
+
313
361
/**
314
362
* @inheritDoc
315
363
*/
316
364
public static function tearDownAfterClass (): void
317
365
{
366
+ parent ::tearDownAfterClass ();
367
+
368
+ $ dataObjectHandlerProperty = new ReflectionProperty (DataObjectHandler::class, "INSTANCE " );
369
+ $ dataObjectHandlerProperty ->setAccessible (true );
370
+ $ dataObjectHandlerProperty ->setValue (null );
371
+
372
+ $ objectManagerProperty = new ReflectionProperty (ObjectManager::class, 'instance ' );
373
+ $ objectManagerProperty ->setAccessible (true );
374
+ $ objectManagerProperty ->setValue (null );
375
+
318
376
TestLoggingUtil::getInstance ()->clearMockLoggingUtil ();
319
377
}
320
378
}
0 commit comments