Review address for separate functon
This commit is contained in:
committed by
Phil Davis
parent
a05a746297
commit
b9fda28235
@@ -54,6 +54,28 @@ class GraphHelper {
|
|||||||
return (bool)preg_match($regex, $spaceId);
|
return (bool)preg_match($regex, $spaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key name can consist of @@@
|
||||||
|
* This function separate such key and return its actual value from actual drive response which can be used for assertion
|
||||||
|
*
|
||||||
|
* @param string $keyName
|
||||||
|
* @param array $actualDriveInformation
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function separateAndGetValueForKey(string $keyName, array $actualDriveInformation): string {
|
||||||
|
// break the segment with @@@ to find the actual value from the actual drive infromation
|
||||||
|
$separatedKey = explode("@@@", $keyName);
|
||||||
|
// this stores the actual value of each key from drive information response used for assertion
|
||||||
|
$actualKeyValue = $actualDriveInformation;
|
||||||
|
|
||||||
|
foreach ($separatedKey as $key) {
|
||||||
|
$actualKeyValue = $actualKeyValue[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $actualKeyValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $baseUrl
|
* @param string $baseUrl
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
|||||||
@@ -1378,15 +1378,7 @@ class GraphContext implements Context {
|
|||||||
*/
|
*/
|
||||||
public function checkUserDriveInformation(array $expectedDriveInformation, array $actualDriveInformation):void {
|
public function checkUserDriveInformation(array $expectedDriveInformation, array $actualDriveInformation):void {
|
||||||
foreach (array_keys($expectedDriveInformation) as $keyName) {
|
foreach (array_keys($expectedDriveInformation) as $keyName) {
|
||||||
// break the segment with @@@ to find the actual value from the drive infromation from response
|
$actualKeyValue = GraphHelper::separateAndGetValueForKey($keyName, $actualDriveInformation);
|
||||||
$separatedKey = explode("@@@", $keyName);
|
|
||||||
// this stores the actual value of each key from drive information response used for assertion
|
|
||||||
$actualKeyValue = $actualDriveInformation;
|
|
||||||
|
|
||||||
foreach ($separatedKey as $key) {
|
|
||||||
$actualKeyValue = $actualKeyValue[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($expectedDriveInformation[$keyName]) {
|
switch ($expectedDriveInformation[$keyName]) {
|
||||||
case '%user_id%':
|
case '%user_id%':
|
||||||
Assert::assertTrue(GraphHelper::isUUIDv4($actualKeyValue), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValue);
|
Assert::assertTrue(GraphHelper::isUUIDv4($actualKeyValue), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValue);
|
||||||
@@ -1424,7 +1416,11 @@ class GraphContext implements Context {
|
|||||||
public function theResponseShouldContainTheFollowingDriveInformation(TableNode $table): void {
|
public function theResponseShouldContainTheFollowingDriveInformation(TableNode $table): void {
|
||||||
$expectedDriveInformation = $table->getRowsHash();
|
$expectedDriveInformation = $table->getRowsHash();
|
||||||
// array of user drive information (Personal Drive Information Only)
|
// array of user drive information (Personal Drive Information Only)
|
||||||
$actualDriveInformation = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['drive'];
|
$actualDriveInformation = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse());
|
||||||
$this->checkUserDriveInformation($expectedDriveInformation, $actualDriveInformation);
|
if (\is_array($actualDriveInformation) && \array_key_exists('drive', $actualDriveInformation)) {
|
||||||
|
$this->checkUserDriveInformation($expectedDriveInformation, $actualDriveInformation['drive']);
|
||||||
|
} else {
|
||||||
|
throw new Error('Response is not an array or the array does not consist key "drive"');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user