Skip to content

Commit d4a1237

Browse files
committed
MQE-588: CreatedData should throw Error/Warning when undefined data is returned
- changed to print warning message for backward compatibility
1 parent d84e20f commit d4a1237

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/PersistedObjectHandlerTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@
1616
use Magento\FunctionalTestingFramework\ObjectManager;
1717
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1818
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
19+
use tests\unit\Util\TestLoggingUtil;
1920

2021
/**
2122
* Class PersistedObjectHandlerTest
2223
*/
2324
class PersistedObjectHandlerTest extends MagentoTestCase
2425
{
26+
/**
27+
* Before test functionality
28+
* @return void
29+
*/
30+
public function setUp()
31+
{
32+
TestLoggingUtil::getInstance()->setMockLoggingUtil();
33+
}
34+
2535
public function testCreateSimpleEntity()
2636
{
2737
// Test Data and Variables
@@ -389,6 +399,8 @@ public function testRetrieveEntityValidField($name, $key, $value, $type, $scope,
389399
public function testRetrieveEntityInValidField($name, $key, $value, $type, $scope, $stepKey)
390400
{
391401
$invalidDataKey = "invalidDataKey";
402+
$warnMsg = "Undefined field {$invalidDataKey} in entity object with a stepKey of {$stepKey}\n";
403+
$warnMsg .= "Please fix the invalid reference. This will result in fatal error in next major release.";
392404

393405
$parserOutputOne = [
394406
'entity' => [
@@ -416,10 +428,15 @@ public function testRetrieveEntityInValidField($name, $key, $value, $type, $scop
416428
$this->mockCurlHandler($jsonReponseOne);
417429
$handler->createEntity($stepKey, $scope, $name);
418430

419-
$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestReferenceException::class);
420-
421431
// Call method
422432
$handler->retrieveEntityField($stepKey, $invalidDataKey, $scope);
433+
434+
// validate log statement
435+
TestLoggingUtil::getInstance()->validateMockLogStatement(
436+
"warning",
437+
$warnMsg,
438+
[]
439+
);
423440
}
424441

425442
/**
@@ -478,4 +495,14 @@ public function tearDown()
478495

479496
parent::tearDown(); // TODO: Change the autogenerated stub
480497
}
498+
499+
/**
500+
* After class functionality
501+
* @return void
502+
*/
503+
public static function tearDownAfterClass()
504+
{
505+
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
506+
parent::tearDownAfterClass();
507+
}
481508
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
1010
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1111
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
12+
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1213

1314
class PersistedObjectHandler
1415
{
@@ -178,14 +179,16 @@ public function getEntity($key, $scope, $entity, $dependentObjectKeys = [], $sto
178179
* @param string $field
179180
* @param string $scope
180181
* @return string
181-
* @throws TestReferenceException
182-
* @throws TestFrameworkException
183182
*/
184183
public function retrieveEntityField($stepKey, $field, $scope)
185184
{
186185
$fieldValue = $this->retrieveEntity($stepKey, $scope)->getCreatedDataByName($field);
187186
if ($fieldValue === null) {
188-
throw new TestReferenceException("Undefined field {$field} in entity object with a stepKey of {$stepKey}");
187+
$warnMsg = "Undefined field {$field} in entity object with a stepKey of {$stepKey}\n";
188+
$warnMsg .= "Please fix the invalid reference. This will result in fatal error in next major release.";
189+
//TODO: change this to throw an exception in next major release
190+
LoggingUtil::getInstance()->getLogger(PersistedObjectHandler::class)->warn($warnMsg);
191+
print($warnMsg . PHP_EOL);
189192
}
190193
return $fieldValue;
191194
}

0 commit comments

Comments
 (0)