Skip to content

MQE-2229: Deprecation Error When Deprecated ActionGroup References De… #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 10, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\FunctionalTestingFramework\ObjectManager;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\ObjectHandlerUtil;
use tests\unit\Util\TestLoggingUtil;

/**
Expand Down Expand Up @@ -148,7 +149,7 @@ public function setUp(): void
*/
public function testGetAllObjects()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getAllObjects();
Expand All @@ -164,7 +165,7 @@ public function testGetAllObjects()
*/
public function testDeprecatedDataObject()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_DEPRECATED);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_DEPRECATED);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getAllObjects();
Expand All @@ -182,7 +183,7 @@ public function testDeprecatedDataObject()
*/
public function testGetObject()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getObject('EntityOne');
Expand All @@ -197,7 +198,7 @@ public function testGetObject()
*/
public function testGetObjectNull()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT);

$actual = DataObjectHandler::getInstance()->getObject('h953u789h0g73t521'); // doesnt exist
$this->assertNull($actual);
Expand All @@ -208,7 +209,7 @@ public function testGetObjectNull()
*/
public function testGetAllObjectsWithDataExtends()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getAllObjects();
Expand All @@ -232,7 +233,7 @@ public function testGetAllObjectsWithDataExtends()
*/
public function testGetObjectWithDataExtends()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND);

// Call the method under test
$actual = DataObjectHandler::getInstance()->getObject('EntityTwo');
Expand All @@ -255,7 +256,7 @@ public function testGetObjectWithDataExtends()
*/
public function testGetAllObjectsWithDataExtendsItself()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);

$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException::class);
$this->expectExceptionMessage(
Expand All @@ -272,7 +273,7 @@ public function testGetAllObjectsWithDataExtendsItself()
*/
public function testGetObjectWithDataExtendsItself()
{
$this->setUpMockDataObjectHander(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);
ObjectHandlerUtil::mockDataObjectHandlerWithData(self::PARSER_OUTPUT_WITH_EXTEND_INVALID);

$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException::class);
$this->expectExceptionMessage(
Expand All @@ -286,33 +287,6 @@ public function testGetObjectWithDataExtendsItself()
);
}

/**
* Set up everything required to mock DataObjectHander::getInstance()
* The first call to getInstance() uses these mocks to emulate the parser, initializing internal state
* according to the PARSER_OUTPUT value
*
* @param array $entityDataArray
*/
private function setUpMockDataObjectHander($entityDataArray)
{
// Clear DataObjectHandler singleton if already set
$property = new \ReflectionProperty(DataObjectHandler::class, "INSTANCE");
$property->setAccessible(true);
$property->setValue(null);

$mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
'readDataProfiles' => $entityDataArray
])->make();

$mockObjectManager = AspectMock::double(ObjectManager::class, [
'create' => $mockDataProfileSchemaParser
])->make();

AspectMock::double(ObjectManagerFactory::class, [
'getObjectManager' => $mockObjectManager
]);
}

/**
* clean up function runs after all tests
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\OperationDefinitionObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\OperationDefinitionParser;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\ObjectHandlerUtil;
use tests\unit\Util\TestLoggingUtil;

/**
Expand Down Expand Up @@ -72,7 +73,7 @@ public function testGetMultipleObjects()
],
]
]]];
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);

//Perform Assertions
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
Expand Down Expand Up @@ -109,7 +110,7 @@ public function testDeprecatedOperation()
],
OperationDefinitionObjectHandler::OBJ_DEPRECATED => 'deprecation message'
]]];
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);

//Perform Assertions
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
Expand Down Expand Up @@ -239,7 +240,7 @@ public function testObjectCreation()
);

// Set up mocked data output
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);

// Get Operation
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
Expand Down Expand Up @@ -337,7 +338,7 @@ public function testObjectArrayCreation()
);

// Set up mocked data output
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);

// Get Operation
$operationDefinitionManager = OperationDefinitionObjectHandler::getInstance();
Expand Down Expand Up @@ -405,7 +406,7 @@ public function testLooseJsonCreation()
);

// Set up mocked data output
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockOperationHandlerWithData($mockData);

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

/**
* Function used to set mock for parser return and force init method to run between tests.
*
* @param array $data
*/
private function setMockParserOutput($data)
{
// clear Operation object handler value to inject parsed content
$property = new \ReflectionProperty(
OperationDefinitionObjectHandler::class,
'INSTANCE'
);
$property->setAccessible(true);
$property->setValue(null);

$mockOperationParser = AspectMock::double(
OperationDefinitionParser::class,
["readOperationMetadata" => $data]
)->make();
$instance = AspectMock::double(ObjectManager::class, ['create' => $mockOperationParser])->make();
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* clean up function runs after all tests
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\FunctionalTestingFramework\ObjectManager;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\ObjectHandlerUtil;
use tests\unit\Util\TestLoggingUtil;

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function testCreateSimpleEntity()
";

// Mock Classes
$this->mockDataHandlerWithOutput($parserOutput);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
$this->mockCurlHandler($jsonResponse);
$handler = PersistedObjectHandler::getInstance();

Expand Down Expand Up @@ -127,7 +128,7 @@ public function testDeleteSimpleEntity()
";

// Mock Classes
$this->mockDataHandlerWithOutput($parserOutput);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
$this->mockCurlHandler($jsonResponse);
$handler = PersistedObjectHandler::getInstance();

Expand Down Expand Up @@ -175,7 +176,7 @@ public function testGetSimpleEntity()
";

// Mock Classes
$this->mockDataHandlerWithOutput($parserOutput);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
$this->mockCurlHandler($jsonResponse);
$handler = PersistedObjectHandler::getInstance();

Expand Down Expand Up @@ -235,7 +236,7 @@ public function testUpdateSimpleEntity()
";

// Mock Classes
$this->mockDataHandlerWithOutput($parserOutput);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutput);
$this->mockCurlHandler($jsonResponse);
$handler = PersistedObjectHandler::getInstance();
$handler->createEntity(
Expand Down Expand Up @@ -322,7 +323,7 @@ public function testRetrieveEntityAcrossScopes()
// Mock Classes and Create Entities
$handler = PersistedObjectHandler::getInstance();

$this->mockDataHandlerWithOutput($parserOutputOne);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
$this->mockCurlHandler($jsonReponseOne);
$handler->createEntity(
$entityStepKeyOne,
Expand Down Expand Up @@ -399,7 +400,7 @@ public function testRetrieveEntityValidField($name, $key, $value, $type, $scope,
// Mock Classes and Create Entities
$handler = PersistedObjectHandler::getInstance();

$this->mockDataHandlerWithOutput($parserOutputOne);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
$this->mockCurlHandler($jsonReponseOne);
$handler->createEntity($stepKey, $scope, $name);

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

// Mock Classes and Create Entities
$handler = PersistedObjectHandler::getInstance();

$this->mockDataHandlerWithOutput($parserOutputOne);
ObjectHandlerUtil::mockDataObjectHandlerWithData($parserOutputOne);
$this->mockCurlHandler($jsonReponseOne);
$handler->createEntity($stepKey, $scope, $name);

Expand All @@ -475,31 +475,6 @@ public static function entityDataProvider()
];
}

/**
* Mocks DataObjectHandler to use given output to create
* @param $parserOutput
* @throws \Exception
*/
public function mockDataHandlerWithOutput($parserOutput)
{
// Clear DataObjectHandler singleton if already set
$property = new \ReflectionProperty(DataObjectHandler::class, "INSTANCE");
$property->setAccessible(true);
$property->setValue(null);

$mockDataProfileSchemaParser = AspectMock::double(DataProfileSchemaParser::class, [
'readDataProfiles' => $parserOutput
])->make();

$mockObjectManager = AspectMock::double(ObjectManager::class, [
'create' => $mockDataProfileSchemaParser
])->make();

AspectMock::double(ObjectManagerFactory::class, [
'getObjectManager' => $mockObjectManager
]);
}

public function mockCurlHandler($response)
{
AspectMock::double(CurlHandler::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
use Magento\FunctionalTestingFramework\XmlParser\PageParser;
use tests\unit\Util\MagentoTestCase;
use tests\unit\Util\ObjectHandlerUtil;
use tests\unit\Util\TestLoggingUtil;

class PageObjectHandlerTest extends MagentoTestCase
Expand Down Expand Up @@ -45,7 +46,7 @@ public function testGetPageObject()
],
"area" => "test"
]];
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);

// get pages
$pageHandler = PageObjectHandler::getInstance();
Expand All @@ -70,7 +71,7 @@ public function testGetEmptyPage()
],
"area" => "test"
]];
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);

// get pages
$page = PageObjectHandler::getInstance()->getObject('testPage1');
Expand All @@ -91,7 +92,7 @@ public function testDeprecatedPage()
"deprecated" => "deprecation message",
"filename" => "filename.xml"
]];
$this->setMockParserOutput($mockData);
ObjectHandlerUtil::mockPageObjectHandlerWithData($mockData);

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

/**
* Function used to set mock for parser return and force init method to run between tests.
*
* @param array $data
*/
private function setMockParserOutput($data)
{
// clear section object handler value to inject parsed content
$property = new \ReflectionProperty(PageObjectHandler::class, 'INSTANCE');
$property->setAccessible(true);
$property->setValue(null);

$mockSectionParser = AspectMock::double(PageParser::class, ["getData" => $data])->make();
$instance = AspectMock::double(ObjectManager::class, ['get' => $mockSectionParser])->make();
AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]);
}

/**
* clean up function runs after all tests
*/
Expand Down
Loading