From 4e1ea0af8166fb3e40a4a0e2480183cb49137fb9 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Fri, 3 Jan 2020 13:37:59 -0600 Subject: [PATCH 1/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist --- .../Util/TestGeneratorTest.php | 26 +++++++++++++++++++ .../Util/TestGenerator.php | 7 +++++ 2 files changed, 33 insertions(+) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php index 8f8eee749..e86a924c9 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php @@ -14,6 +14,7 @@ use Magento\FunctionalTestingFramework\Util\MagentoTestCase; use Magento\FunctionalTestingFramework\Util\TestGenerator; use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; class TestGeneratorTest extends MagentoTestCase { @@ -41,11 +42,36 @@ public function testEntityException() $testGeneratorObject->createAllTestFiles(null, []); } + /** + * Test to check exceptions for createData on referencing non-existent entity + * + * @throws TestReferenceException + */ + + public function testCreateDataException() + { + $actionObject = new ActionObject('fakeAction', 'createData', [ + 'entity' => 'invalidEntity' + ]); + + $testObject = new TestObject("sampleTest", ["merge123" => $actionObject], [], [], "filename"); + + $testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]); + + AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $testObject]]); + + $this->expectExceptionMessage("Entity \"invalidEntity\" does not exist." . + "\nException occurred parsing action at StepKey \"fakeAction\" in Test \"sampleTest\""); + + $testGeneratorObject->createAllTestFiles(null, []); + } + /** * Tests that skipped tests do not have a fully generated body * * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException */ + public function testSkippedNoGeneration() { $actionInput = 'fakeInput'; diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 09c353029..762fbd346 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -731,6 +731,13 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "createData": $entity = $customActionAttributes['entity']; + if(DataObjectHandler::getInstance()->getObject($entity) === null) { + throw new TestReferenceException( + "Entity \"" . $entity . "\" does not exist." . + "\nException occurred parsing action at StepKey \"" . $stepKey . "\"" + ); + } + //TODO refactor entity field override to not be individual actionObjects $customEntityFields = $customActionAttributes[ActionObjectExtractor::ACTION_OBJECT_PERSISTENCE_FIELDS] ?? []; From 1075fd48fb90f2f4d5df673a5fbabcd1055868b9 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Fri, 3 Jan 2020 16:34:34 -0600 Subject: [PATCH 2/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist --- .../Util/TestGeneratorTest.php | 24 ------------------- .../Handlers/PersistedObjectHandler.php | 8 +++++++ .../Util/TestGenerator.php | 7 ------ 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php index e86a924c9..17da4cd20 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php @@ -42,30 +42,6 @@ public function testEntityException() $testGeneratorObject->createAllTestFiles(null, []); } - /** - * Test to check exceptions for createData on referencing non-existent entity - * - * @throws TestReferenceException - */ - - public function testCreateDataException() - { - $actionObject = new ActionObject('fakeAction', 'createData', [ - 'entity' => 'invalidEntity' - ]); - - $testObject = new TestObject("sampleTest", ["merge123" => $actionObject], [], [], "filename"); - - $testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $testObject]); - - AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $testObject]]); - - $this->expectExceptionMessage("Entity \"invalidEntity\" does not exist." . - "\nException occurred parsing action at StepKey \"fakeAction\" in Test \"sampleTest\""); - - $testGeneratorObject->createAllTestFiles(null, []); - } - /** * Tests that skipped tests do not have a fully generated body * diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php index 2a0f11a01..7015292c0 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php @@ -97,6 +97,14 @@ public function createEntity( } $retrievedEntity = DataObjectHandler::getInstance()->getObject($entity); + + if ($retrievedEntity === null) { + throw new TestReferenceException( + "Entity \"" . $entity . "\" does not exist." . + "\nException occurred parsing action at StepKey \"" . $key . "\"" + ); + } + $persistedObject = new DataPersistenceHandler( $retrievedEntity, $retrievedDependentObjects, diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 762fbd346..09c353029 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -731,13 +731,6 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato case "createData": $entity = $customActionAttributes['entity']; - if(DataObjectHandler::getInstance()->getObject($entity) === null) { - throw new TestReferenceException( - "Entity \"" . $entity . "\" does not exist." . - "\nException occurred parsing action at StepKey \"" . $stepKey . "\"" - ); - } - //TODO refactor entity field override to not be individual actionObjects $customEntityFields = $customActionAttributes[ActionObjectExtractor::ACTION_OBJECT_PERSISTENCE_FIELDS] ?? []; From a415f0554beb308c26f5a32ced30f40a9d11664f Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Fri, 3 Jan 2020 16:39:39 -0600 Subject: [PATCH 3/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist reverted changes --- .../Magento/FunctionalTestFramework/Util/TestGeneratorTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php index 17da4cd20..8f8eee749 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php @@ -14,7 +14,6 @@ use Magento\FunctionalTestingFramework\Util\MagentoTestCase; use Magento\FunctionalTestingFramework\Util\TestGenerator; use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; -use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; class TestGeneratorTest extends MagentoTestCase { @@ -47,7 +46,6 @@ public function testEntityException() * * @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException */ - public function testSkippedNoGeneration() { $actionInput = 'fakeInput'; From af0a499d4b52c06d8053d2a57c7e9fe81227159a Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Mon, 6 Jan 2020 09:48:01 -0600 Subject: [PATCH 4/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist reverted changes Added unit test --- .../Handlers/PersistedObjectHandlerTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php index 6c3823466..34d59e8c8 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php @@ -32,6 +32,31 @@ public function setUp() TestLoggingUtil::getInstance()->setMockLoggingUtil(); } + public function testCreateInvalidEntity() + { + // Test Data and Variables + + $entityName = "InvalidEntity"; + $entityStepKey = "StepKey"; + $scope = PersistedObjectHandler::TEST_SCOPE; + + $exceptionMessage = "Entity \"" . $entityName . "\" does not exist." . + "\nException occurred parsing action at StepKey \"" . $entityStepKey . "\""; + + $this->expectException(TestReferenceException::class); + + $this->expectExceptionMessage($exceptionMessage); + + $handler = PersistedObjectHandler::getInstance(); + + // Call method + $handler->createEntity( + $entityStepKey, + $scope, + $entityName + ); + } + public function testCreateSimpleEntity() { // Test Data and Variables From 28804f4891ed698c91fd77040d411ede6de9bbfa Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Mon, 6 Jan 2020 15:00:21 -0600 Subject: [PATCH 5/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist reverted changes fixed unit test --- .../DataGenerator/Handlers/PersistedObjectHandlerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php index 34d59e8c8..04e1f0810 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php @@ -32,10 +32,9 @@ public function setUp() TestLoggingUtil::getInstance()->setMockLoggingUtil(); } - public function testCreateInvalidEntity() + public function testCreateEntityWithNonExistingName() { // Test Data and Variables - $entityName = "InvalidEntity"; $entityStepKey = "StepKey"; $scope = PersistedObjectHandler::TEST_SCOPE; From 188d6bae7e827fefd83eb377adf52fd65d95b3f9 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Mon, 6 Jan 2020 15:45:31 -0600 Subject: [PATCH 6/6] MQE-1513: createData throws a useless error message during runtime when the entity does not exist reverted changes reworded message --- .../DataGenerator/Handlers/PersistedObjectHandlerTest.php | 2 +- .../DataGenerator/Handlers/PersistedObjectHandler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php index 04e1f0810..592b87f4e 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php @@ -40,7 +40,7 @@ public function testCreateEntityWithNonExistingName() $scope = PersistedObjectHandler::TEST_SCOPE; $exceptionMessage = "Entity \"" . $entityName . "\" does not exist." . - "\nException occurred parsing action at StepKey \"" . $entityStepKey . "\""; + "\nException occurred executing action at StepKey \"" . $entityStepKey . "\""; $this->expectException(TestReferenceException::class); diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php index 7015292c0..00353856b 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php @@ -101,7 +101,7 @@ public function createEntity( if ($retrievedEntity === null) { throw new TestReferenceException( "Entity \"" . $entity . "\" does not exist." . - "\nException occurred parsing action at StepKey \"" . $key . "\"" + "\nException occurred executing action at StepKey \"" . $key . "\"" ); }