1010use Exception ;
1111use Magento \FunctionalTestingFramework \DataGenerator \Handlers \DataObjectHandler ;
1212use Magento \FunctionalTestingFramework \DataGenerator \Objects \EntityDataObject ;
13+ use Magento \FunctionalTestingFramework \DataGenerator \Parsers \DataProfileSchemaParser ;
1314use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
15+ use Magento \FunctionalTestingFramework \ObjectManager ;
16+ use Magento \FunctionalTestingFramework \ObjectManagerFactory ;
17+ use ReflectionProperty ;
1418use tests \unit \Util \MagentoTestCase ;
15- use tests \unit \Util \ObjectHandlerUtil ;
1619use tests \unit \Util \TestLoggingUtil ;
1720
1821/**
@@ -151,7 +154,7 @@ protected function setUp(): void
151154 */
152155 public function testGetAllObjects (): void
153156 {
154- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
157+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
155158
156159 // Call the method under test
157160 $ actual = DataObjectHandler::getInstance ()->getAllObjects ();
@@ -170,10 +173,10 @@ public function testGetAllObjects(): void
170173 */
171174 public function testDeprecatedDataObject (): void
172175 {
173- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_DEPRECATED );
176+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_DEPRECATED );
174177
175178 // Call the method under test
176- $ actual = DataObjectHandler::getInstance ()->getAllObjects ();
179+ DataObjectHandler::getInstance ()->getAllObjects ();
177180
178181 //validate deprecation warning
179182 TestLoggingUtil::getInstance ()->validateMockLogStatement (
@@ -191,7 +194,7 @@ public function testDeprecatedDataObject(): void
191194 */
192195 public function testGetObject (): void
193196 {
194- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
197+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
195198
196199 // Call the method under test
197200 $ actual = DataObjectHandler::getInstance ()->getObject ('EntityOne ' );
@@ -209,7 +212,7 @@ public function testGetObject(): void
209212 */
210213 public function testGetObjectNull (): void
211214 {
212- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
215+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT );
213216
214217 $ actual = DataObjectHandler::getInstance ()->getObject ('h953u789h0g73t521 ' ); // doesnt exist
215218 $ this ->assertNull ($ actual );
@@ -223,7 +226,7 @@ public function testGetObjectNull(): void
223226 */
224227 public function testGetAllObjectsWithDataExtends (): void
225228 {
226- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
229+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
227230
228231 // Call the method under test
229232 $ actual = DataObjectHandler::getInstance ()->getAllObjects ();
@@ -250,7 +253,7 @@ public function testGetAllObjectsWithDataExtends(): void
250253 */
251254 public function testGetObjectWithDataExtends (): void
252255 {
253- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
256+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND );
254257
255258 // Call the method under test
256259 $ actual = DataObjectHandler::getInstance ()->getObject ('EntityTwo ' );
@@ -276,7 +279,7 @@ public function testGetObjectWithDataExtends(): void
276279 */
277280 public function testGetAllObjectsWithDataExtendsItself (): void
278281 {
279- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
282+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
280283
281284 $ this ->expectException (TestFrameworkException::class);
282285 $ this ->expectExceptionMessage (
@@ -296,7 +299,7 @@ public function testGetAllObjectsWithDataExtendsItself(): void
296299 */
297300 public function testGetObjectWithDataExtendsItself (): void
298301 {
299- ObjectHandlerUtil:: mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
302+ $ this -> mockDataObjectHandlerWithData (self ::PARSER_OUTPUT_WITH_EXTEND_INVALID );
300303
301304 $ this ->expectException (TestFrameworkException::class);
302305 $ this ->expectExceptionMessage (
@@ -310,11 +313,64 @@ public function testGetObjectWithDataExtendsItself(): void
310313 );
311314 }
312315
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 ($ objectManager , $ mockDataProfileSchemaParser ) {
344+
345+ if ($ class === DataProfileSchemaParser::class) {
346+ return $ mockDataProfileSchemaParser ;
347+ }
348+
349+ return $ objectManager ->create ($ class , $ arguments );
350+ }
351+ )
352+ );
353+
354+ $ property = new ReflectionProperty (ObjectManager::class, 'instance ' );
355+ $ property ->setAccessible (true );
356+ $ property ->setValue ($ mockObjectManagerInstance );
357+ }
358+
313359 /**
314360 * @inheritDoc
315361 */
316362 public static function tearDownAfterClass (): void
317363 {
364+ parent ::tearDownAfterClass ();
365+
366+ $ dataObjectHandlerProperty = new ReflectionProperty (DataObjectHandler::class, "INSTANCE " );
367+ $ dataObjectHandlerProperty ->setAccessible (true );
368+ $ dataObjectHandlerProperty ->setValue (null );
369+
370+ $ objectManagerProperty = new ReflectionProperty (ObjectManager::class, 'instance ' );
371+ $ objectManagerProperty ->setAccessible (true );
372+ $ objectManagerProperty ->setValue (null );
373+
318374 TestLoggingUtil::getInstance ()->clearMockLoggingUtil ();
319375 }
320376}
0 commit comments