remove throwExceptionIfNotFound parameter and userTriesToRestoreElementInTrash function

Signed-off-by: prashant-gurung899 <prasantgrg777@gmail.com>
This commit is contained in:
prashant-gurung899
2024-06-27 15:55:34 +05:45
parent 5f03a566ee
commit af4193f3e0
2 changed files with 8 additions and 26 deletions
+1 -2
View File
@@ -10,11 +10,10 @@ Feature: an user shares resources usin ScienceMesh application
And user "Brian" has been created with default attributes and without skeleton files And user "Brian" has been created with default attributes and without skeleton files
Scenario: user generates invitation Scenario: user generates invitation
Given using server "LOCAL" Given using server "LOCAL"
When "Alice" generates invitation When "Alice" generates invitation
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
When using server "REMOTE" When using server "REMOTE"
And "Brian" accepts invitation And "Brian" accepts invitation
Then the HTTP status code should be "200" Then the HTTP status code should be "200"
@@ -553,7 +553,7 @@ class TrashbinContext implements Context {
public function userTriesToRestoreFromTrashbinOfUser(?string $asUser, ?string $path, ?string $user):void { public function userTriesToRestoreFromTrashbinOfUser(?string $asUser, ?string $path, ?string $user):void {
$user = $this->featureContext->getActualUsername($user); $user = $this->featureContext->getActualUsername($user);
$asUser = $this->featureContext->getActualUsername($asUser); $asUser = $this->featureContext->getActualUsername($asUser);
$response = $this->restoreElement($user, $path, null, true, $asUser); $response = $this->restoreElement($user, $path, null, $asUser);
$this->featureContext->setResponse($response); $this->featureContext->setResponse($response);
} }
@@ -572,7 +572,7 @@ class TrashbinContext implements Context {
public function userTriesToRestoreFromTrashbinOfUserUsingPassword(?string $asUser, ?string $path, ?string $user, ?string $password):void { public function userTriesToRestoreFromTrashbinOfUserUsingPassword(?string $asUser, ?string $path, ?string $user, ?string $password):void {
$asUser = $this->featureContext->getActualUsername($asUser); $asUser = $this->featureContext->getActualUsername($asUser);
$user = $this->featureContext->getActualUsername($user); $user = $this->featureContext->getActualUsername($user);
$response = $this->restoreElement($user, $path, null, true, $asUser, $password); $response = $this->restoreElement($user, $path, null, $asUser, $password);
$this->featureContext->setResponse($response); $this->featureContext->setResponse($response);
} }
@@ -812,7 +812,6 @@ class TrashbinContext implements Context {
* @param string $user * @param string $user
* @param string $originalPath * @param string $originalPath
* @param string|null $destinationPath * @param string|null $destinationPath
* @param bool $throwExceptionIfNotFound
* @param string|null $asUser - To send request as another user * @param string|null $asUser - To send request as another user
* @param string|null $password * @param string|null $password
* *
@@ -820,7 +819,7 @@ class TrashbinContext implements Context {
* @throws JsonException * @throws JsonException
* @throws GuzzleException * @throws GuzzleException
*/ */
private function restoreElement(string $user, string $originalPath, ?string $destinationPath = null, bool $throwExceptionIfNotFound = true, ?string $asUser = null, ?string $password = null):ResponseInterface { private function restoreElement(string $user, string $originalPath, ?string $destinationPath = null, ?string $asUser = null, ?string $password = null):ResponseInterface {
$asUser = $asUser ?? $user; $asUser = $asUser ?? $user;
$listing = $this->listTrashbinFolder($user); $listing = $this->listTrashbinFolder($user);
$originalPath = \trim($originalPath, '/'); $originalPath = \trim($originalPath, '/');
@@ -841,12 +840,10 @@ class TrashbinContext implements Context {
// The requested element to restore was not even in the trashbin. // The requested element to restore was not even in the trashbin.
// Throw an exception, because there was not any API call, and so there // Throw an exception, because there was not any API call, and so there
// is also no up-to-date response to examine in later test steps. // is also no up-to-date response to examine in later test steps.
if ($throwExceptionIfNotFound) { throw new \Exception(
throw new \Exception( __METHOD__
__METHOD__ . " cannot restore from trashbin because no element was found for user $user at original path $originalPath"
. " cannot restore from trashbin because no element was found for user $user at original path $originalPath" );
);
}
} }
/** /**
@@ -925,20 +922,6 @@ class TrashbinContext implements Context {
} }
} }
/**
* @When /^user "([^"]*)" tries to restore the (?:file|folder|entry) with original path "([^"]*)" using the trashbin API$/
*
* @param string $user
* @param string $originalPath
*
* @return void
* @throws Exception
*/
public function userTriesToRestoreElementInTrash(string $user, string $originalPath):void {
$response = $this->restoreElement($user, $originalPath, null, false);
$this->featureContext->setResponse($response);
}
/** /**
* @When /^user "([^"]*)" restores the (?:file|folder|entry) with original path "([^"]*)" using the trashbin API$/ * @When /^user "([^"]*)" restores the (?:file|folder|entry) with original path "([^"]*)" using the trashbin API$/
* *