Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion tests/TestHelpers/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ public static function editUserBatch(
);
}
// Send the array of requests at once in parallel.
return HttpRequestHelper::sendBatchRequest($requests, $client);
$results = HttpRequestHelper::sendBatchRequest($requests, $client);

foreach ($results->getFailures() as $e) {
$pathArray = \explode('/', $e->getRequest()->getPath());
$failedUser = \end($pathArray);
$editData = $e->getRequest()->getBody()->getFields();
throw new \Exception(
"Could not set '${editData['key']}' to '${editData['value']}' for user '$failedUser' \n"
. $e->getResponse()->getStatusCode() . "\n" . $e->getResponse()->getBody()
);
}
return $results;
}

/**
Expand Down
25 changes: 19 additions & 6 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,18 @@ public function theseUsersHaveBeenCreated($setDefaultAttributes, $doNotInitializ
$results = HttpRequestHelper::sendBatchRequest($requests, $client);
// Retrieve all failures.
foreach ($results->getFailures() as $e) {
throw $e;
$failedUser = $e->getRequest()->getBody()->getFields()['userid'];
$message = $this->getResponseXml($e->getResponse())->xpath("/ocs/meta/message");
if ($message && (string) $message[0] === "User already exists") {
PHPUnit\Framework\Assert::fail(
"Could not create user '$failedUser' as it already exists. " .
"Please delete the user to run tests again."
);
}
throw new Exception(
"could not create user. "
. $e->getResponse()->getStatusCode() . " " . $e->getResponse()->getBody()
);
}

// Create requests for setting displayname and email for the newly created users.
Expand All @@ -462,15 +473,12 @@ public function theseUsersHaveBeenCreated($setDefaultAttributes, $doNotInitializ
}
// Edit the users in parallel to make the process faster.
if (\count($editData) > 0) {
$results = UserHelper::editUserBatch(
UserHelper::editUserBatch(
$this->getBaseUrl(),
$editData,
$this->getAdminUsername(),
$this->getAdminPassword()
);
foreach ($results->getFailures() as $e) {
throw new \Exception("Could not edit user\n" . $e->getMessage());
}
}

// If the users need to be initialized then initialize them in parallel.
Expand Down Expand Up @@ -1331,7 +1339,12 @@ public function initializeUserBatch($users) {
$response = HttpRequestHelper::sendBatchRequest($requests, $client);
// throw an exception if any request fails.
foreach ($response->getFailures() as $e) {
throw new \Exception("Could not initialize user\n" . $e->getMessage());
$pathArray = \explode('/', $e->getRequest()->getPath());
$failedUser = \end($pathArray);
throw new \Exception(
"Could not initialize user $failedUser \n"
. $e->getResponse()->getStatusCode() . "\n" . $e->getResponse()->getBody()
);
}
}

Expand Down