Skip to content

MQE-588: CreatedData should throw Error/Warning when undefined data i… #432

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 6 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
use Magento\FunctionalTestingFramework\DataGenerator\Parsers\DataProfileSchemaParser;
use Magento\FunctionalTestingFramework\DataGenerator\Persist\CurlHandler;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;
use Magento\FunctionalTestingFramework\ObjectManager;
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
Expand Down Expand Up @@ -330,6 +332,108 @@ public function testRetrieveEntityAcrossScopes()
$this->assertEquals($dataValueThree, $retrievedFromSuite);
}

/**
* @param string $name
* @param string $key
* @param string $value
* @param string $type
* @param string $scope
* @param string $stepKey
* @dataProvider entityDataProvider
*/
public function testRetrieveEntityValidField($name, $key, $value, $type, $scope, $stepKey)
{
$parserOutputOne = [
'entity' => [
$name => [
'type' => $type,
'data' => [
0 => [
'key' => $key,
'value' => $value
]
]
]
]
];
$jsonReponseOne = "
{
\"" . strtolower($key) . "\" : \"{$value}\"
}
";

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

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

// Call method
$retrieved = $handler->retrieveEntityField($stepKey, $key, $scope);

$this->assertEquals($value, $retrieved);
}

/**
* @param string $name
* @param string $key
* @param string $value
* @param string $type
* @param string $scope
* @param string $stepKey
* @dataProvider entityDataProvider
* @throws TestReferenceException
* @throws TestFrameworkException
*/
public function testRetrieveEntityInValidField($name, $key, $value, $type, $scope, $stepKey)
{
$invalidDataKey = "invalidDataKey";

$parserOutputOne = [
'entity' => [
$name => [
'type' => $type,
'data' => [
0 => [
'key' => $key,
'value' => $value
]
]
]
]
];
$jsonReponseOne = "
{
\"" . strtolower($key) . "\" : \"{$value}\"
}
";

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

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

$this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestReferenceException::class);

// Call method
$handler->retrieveEntityField($stepKey, $invalidDataKey, $scope);
}

/**
* Data provider for testRetrieveEntityField
*/
public static function entityDataProvider()
{
return [
['Entity1', 'testKey1', 'testValue1', 'testType', PersistedObjectHandler::HOOK_SCOPE, 'StepKey1'],
['Entity2', 'testKey2', 'testValue2', 'testType', PersistedObjectHandler::SUITE_SCOPE, 'StepKey2'],
['Entity3', 'testKey3', 'testValue3', 'testType', PersistedObjectHandler::TEST_SCOPE, 'StepKey3']
];
}

/**
* Mocks DataObjectHandler to use given output to create
* @param $parserOutput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\FunctionalTestingFramework\DataGenerator\Handlers;

use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException;

class PersistedObjectHandler
Expand Down Expand Up @@ -178,11 +179,15 @@ public function getEntity($key, $scope, $entity, $dependentObjectKeys = [], $sto
* @param string $scope
* @return string
* @throws TestReferenceException
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
* @throws TestFrameworkException
*/
public function retrieveEntityField($stepKey, $field, $scope)
{
return $this->retrieveEntity($stepKey, $scope)->getCreatedDataByName($field);
$fieldValue = $this->retrieveEntity($stepKey, $scope)->getCreatedDataByName($field);
if ($fieldValue === null) {
throw new TestReferenceException("Undefined field {$field} in entity object with a stepKey of {$stepKey}");
}
return $fieldValue;
}

/**
Expand Down