From a05a746297cbff4dd3e4e2c36c6849fa498440f3 Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Wed, 21 Dec 2022 16:55:14 +0545 Subject: [PATCH] Addressed review --- tests/TestHelpers/GraphHelper.php | 12 +++---- .../features/bootstrap/GraphContext.php | 34 ++++++------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 4d783da4c9..c80e5f8508 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -37,21 +37,21 @@ class GraphHelper { /** * @param string $id * - * @return int (1 = true | 0 = false) + * @return bool */ - public static function isUUIDv4(string $id): int { + public static function isUUIDv4(string $id): bool { $regex = "/^" . self::getUUIDv4Regex() . "$/i"; - return preg_match($regex, $id); + return (bool)preg_match($regex, $id); } /** * @param string $spaceId * - * @return int (1 = true | 0 = false) + * @return bool */ - public static function isSpaceId(string $spaceId): int { + public static function isSpaceId(string $spaceId): bool { $regex = "/^" . self::getUUIDv4Regex() . '\\$' . self::getUUIDv4Regex() . "$/i"; - return preg_match($regex, $spaceId); + return (bool)preg_match($regex, $spaceId); } /** diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 2d7e466083..80353269ea 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1226,12 +1226,7 @@ class GraphContext implements Context { . trim($expectedValue[$keyName], '%') ); } - Assert::assertEquals( - 1, - GraphHelper::isUUIDv4($actualValue['id']), - __METHOD__ . - ' Expected user_id to have UUIDv4 pattern but found: ' . $actualValue['id'] - ); + Assert::assertTrue(GraphHelper::isUUIDv4($actualValue['id']), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualValue['id']); break; default: Assert::assertEquals( @@ -1377,37 +1372,27 @@ class GraphContext implements Context { * check if single drive information is correct * * @param array $expectedDriveInformation - * @param array $actualValueDriveInformation + * @param array $actualDriveInformation * * @return void */ - public function checkUserDriveInformation(array $expectedDriveInformation, array $actualValueDriveInformation):void { + public function checkUserDriveInformation(array $expectedDriveInformation, array $actualDriveInformation):void { foreach (array_keys($expectedDriveInformation) as $keyName) { // break the segment with @@@ to find the actual value from the drive infromation from response $separatedKey = explode("@@@", $keyName); // this stores the actual value of each key from drive information response used for assertion - $actualKeyValueFromDriveInformation = $actualValueDriveInformation; + $actualKeyValue = $actualDriveInformation; foreach ($separatedKey as $key) { - $actualKeyValueFromDriveInformation = $actualKeyValueFromDriveInformation[$key]; + $actualKeyValue = $actualKeyValue[$key]; } switch ($expectedDriveInformation[$keyName]) { case '%user_id%': - Assert::assertEquals( - 1, - GraphHelper::isUUIDv4($actualKeyValueFromDriveInformation), - __METHOD__ . - ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValueFromDriveInformation - ); + Assert::assertTrue(GraphHelper::isUUIDv4($actualKeyValue), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValue); break; case '%space_id%': - Assert::assertEquals( - 1, - GraphHelper::isSpaceId($actualKeyValueFromDriveInformation), - __METHOD__ . - ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValueFromDriveInformation - ); + Assert::assertTrue(GraphHelper::isSpaceId($actualKeyValue), __METHOD__ . ' Expected space_id to have a UUIDv4:UUIDv4 pattern but found: ' . $actualKeyValue); break; default: $expectedDriveInformation[$keyName] = $this->featureContext->substituteInLineCodes( @@ -1416,14 +1401,15 @@ class GraphContext implements Context { [], [ [ + // the actual space_id is substituted from the actual drive information rather than making an API request and substituting "code" => "%space_id%", "function" => [$this, "getSpaceIdFromActualDriveinformation"], - "parameter" => [$actualValueDriveInformation] + "parameter" => [$actualDriveInformation] ], ] ); - Assert::assertEquals($expectedDriveInformation[$keyName], $actualKeyValueFromDriveInformation); + Assert::assertEquals($expectedDriveInformation[$keyName], $actualKeyValue); } } }