updating lint rules for test code

This commit is contained in:
Niraj Acharya
2024-12-30 09:18:45 +05:45
parent 24798a80d1
commit 089ccc1ca3
45 changed files with 2914 additions and 1151 deletions
@@ -42,7 +42,7 @@ class WebDav extends Assert {
?string $expectedValue,
?array $responseXmlArray,
?string $extraErrorText = ''
):void {
): void {
if ($extraErrorText !== '') {
$extraErrorText = $extraErrorText . " ";
}
@@ -58,7 +58,9 @@ class WebDav extends Assert {
} elseif ($element === "reason") {
$result = $responseXmlArray['value'][3]['value'];
} else {
self::fail(__METHOD__ . " element must be one of exception, response or reason. But '$element' was passed in.");
self::fail(
__METHOD__ . " element must be one of exception, response or reason. But '$element' was passed in."
);
}
self::assertEquals(
@@ -78,7 +80,7 @@ class WebDav extends Assert {
public static function assertResponseContainsShareTypes(
SimpleXMLElement $responseXmlObject,
?array $expectedShareTypes
):void {
): void {
foreach ($expectedShareTypes as $row) {
$xmlPart = $responseXmlObject->xpath(
"//d:prop/oc:share-types/oc:share-type[.=" . $row[0] . "]"
+17 -3
View File
@@ -42,7 +42,11 @@ class AuthAppHelper {
*
* @return ResponseInterface
*/
public static function listAllAppAuthTokensForUser(string $baseUrl, string $user, string $password): ResponseInterface {
public static function listAllAppAuthTokensForUser(
string $baseUrl,
string $user,
string $password
): ResponseInterface {
$url = $baseUrl . self::getAuthAppEndpoint();
return HttpRequestHelper::sendRequest(
$url,
@@ -61,7 +65,12 @@ class AuthAppHelper {
*
* @return ResponseInterface
*/
public static function createAppAuthToken(string $baseUrl, string $user, string $password, string $expiration): ResponseInterface {
public static function createAppAuthToken(
string $baseUrl,
string $user,
string $password,
string $expiration
): ResponseInterface {
$url = $baseUrl . self::getAuthAppEndpoint() . "?expiry=$expiration";
return HttpRequestHelper::sendRequest(
$url,
@@ -80,7 +89,12 @@ class AuthAppHelper {
*
* @return ResponseInterface
*/
public static function deleteAppAuthToken(string $baseUrl, string $user, string $password, string $token): ResponseInterface {
public static function deleteAppAuthToken(
string $baseUrl,
string $user,
string $password,
string $token
): ResponseInterface {
$url = $baseUrl . self::getAuthAppEndpoint() . "?token=$token";
return HttpRequestHelper::sendRequest(
$url,
+5 -1
View File
@@ -38,7 +38,11 @@ class BehatHelper {
*
* @return Context
*/
public static function getContext(ScenarioScope $scope, InitializedContextEnvironment $environment, string $class): Context {
public static function getContext(
ScenarioScope $scope,
InitializedContextEnvironment $environment,
string $class
): Context {
try {
return $environment->getContext($class);
} catch (ContextNotFoundException $e) {
+12 -8
View File
@@ -35,7 +35,7 @@ class EmailHelper {
*
* @return string
*/
public static function getMailBoxFromEmail(string $emailAddress):string {
public static function getMailBoxFromEmail(string $emailAddress): string {
return explode("@", $emailAddress)[0];
}
@@ -45,7 +45,7 @@ class EmailHelper {
*
* @return string
*/
public static function getLocalEmailUrl():string {
public static function getLocalEmailUrl(): string {
$localEmailHost = self::getLocalEmailHost();
$emailPort = \getenv('EMAIL_PORT');
if ($emailPort === false) {
@@ -60,7 +60,7 @@ class EmailHelper {
*
* @return string
*/
public static function getEmailHost():string {
public static function getEmailHost(): string {
$emailHost = \getenv('EMAIL_HOST');
if ($emailHost === false) {
$emailHost = "127.0.0.1";
@@ -74,7 +74,7 @@ class EmailHelper {
*
* @return string
*/
public static function getLocalEmailHost():string {
public static function getLocalEmailHost(): string {
$localEmailHost = \getenv('LOCAL_EMAIL_HOST');
if ($localEmailHost === false) {
$localEmailHost = self::getEmailHost();
@@ -92,7 +92,7 @@ class EmailHelper {
* @return array
* @throws GuzzleException
*/
public static function getMailBoxInformation(string $mailBox, ?string $xRequestId = null):array {
public static function getMailBoxInformation(string $mailBox, ?string $xRequestId = null): array {
$response = HttpRequestHelper::get(
self::getLocalEmailUrl() . "/api/v1/mailbox/" . $mailBox,
$xRequestId,
@@ -113,7 +113,11 @@ class EmailHelper {
* @return object
* @throws GuzzleException
*/
public static function getBodyOfAnEmailById(string $mailBox, string $mailboxId, ?string $xRequestId = null):object {
public static function getBodyOfAnEmailById(
string $mailBox,
string $mailboxId,
?string $xRequestId = null
): object {
$response = HttpRequestHelper::get(
self::getLocalEmailUrl() . "/api/v1/mailbox/" . $mailBox . "/" . $mailboxId,
$xRequestId,
@@ -142,7 +146,7 @@ class EmailHelper {
string $xRequestId,
?int $emailNumber = 1,
?int $waitTimeSec = EMAIL_WAIT_TIMEOUT_SEC
):string {
): string {
$currentTime = \time();
$endTime = $currentTime + $waitTimeSec;
$mailBox = self::getMailBoxFromEmail($emailAddress);
@@ -178,7 +182,7 @@ class EmailHelper {
string $localInbucketUrl,
?string $xRequestId,
string $mailBox
):ResponseInterface {
): ResponseInterface {
return HttpRequestHelper::delete(
$localInbucketUrl . "/api/v1/mailbox/" . $mailBox,
$xRequestId
+42 -9
View File
@@ -110,7 +110,8 @@ class GraphHelper {
* @return string
*/
public static function getShareIdRegex(): string {
return self::getUUIDv4Regex() . '\\\$' . self::getUUIDv4Regex() . '!' . self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex();
return self::getUUIDv4Regex() . '\\\$' . self::getUUIDv4Regex() . '!'
. self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex() . ':' . self::getUUIDv4Regex();
}
/**
@@ -1387,7 +1388,11 @@ class GraphHelper {
string $password,
array $groupIdArray
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$groupIdArray[0]') " . "and memberOf/any(m:m/id eq '$groupIdArray[1]')");
$url = self::getFullUrl(
$baseUrl,
'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$groupIdArray[0]') "
. "and memberOf/any(m:m/id eq '$groupIdArray[1]')"
);
return HttpRequestHelper::get(
$url,
$xRequestId,
@@ -1416,7 +1421,11 @@ class GraphHelper {
string $firstGroup,
string $secondGroup
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$firstGroup') " . "or memberOf/any(m:m/id eq '$secondGroup')");
$url = self::getFullUrl(
$baseUrl,
'users' . '?$filter=memberOf/any(m:m/id '
. "eq '$firstGroup') " . "or memberOf/any(m:m/id eq '$secondGroup')"
);
return HttpRequestHelper::get(
$url,
$xRequestId,
@@ -1472,7 +1481,11 @@ class GraphHelper {
string $roleId,
string $groupId
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'users' . '?$filter=appRoleAssignments/any(m:m/appRoleId ' . "eq '$roleId') " . "and memberOf/any(m:m/id eq '$groupId')");
$url = self::getFullUrl(
$baseUrl,
'users' . '?$filter=appRoleAssignments/any(m:m/appRoleId '
. "eq '$roleId') " . "and memberOf/any(m:m/id eq '$groupId')"
);
return HttpRequestHelper::get(
$url,
$xRequestId,
@@ -1669,7 +1682,15 @@ class GraphHelper {
): ResponseInterface {
$fullUrl = self::getFullUrl($baseUrl, 'me');
$payload['preferredLanguage'] = $language;
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PATCH', $user, $password, null, \json_encode($payload));
return HttpRequestHelper::sendRequest(
$fullUrl,
$xRequestId,
'PATCH',
$user,
$password,
null,
\json_encode($payload)
);
}
/**
@@ -1810,7 +1831,13 @@ class GraphHelper {
?string $expirationDateTime
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/items/$itemId/invite");
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expirationDateTime);
$body = self::createShareInviteBody(
$shareeIds,
$shareTypes,
$permissionsRole,
$permissionsAction,
$expirationDateTime
);
return HttpRequestHelper::post(
$url,
$xRequestId,
@@ -2052,7 +2079,7 @@ class GraphHelper {
string $password,
string $itemId,
string $shareSpaceId
):ResponseInterface {
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/items/$itemId");
return HttpRequestHelper::delete(
$url,
@@ -2083,7 +2110,7 @@ class GraphHelper {
string $itemId,
string $shareSpaceId,
array $body
):ResponseInterface {
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/items/$itemId");
return HttpRequestHelper::sendRequest(
$url,
@@ -2186,7 +2213,13 @@ class GraphHelper {
?string $expirationDateTime
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$spaceId/root/invite");
$body = self::createShareInviteBody($shareeIds, $shareTypes, $permissionsRole, $permissionsAction, $expirationDateTime);
$body = self::createShareInviteBody(
$shareeIds,
$shareTypes,
$permissionsRole,
$permissionsAction,
$expirationDateTime
);
return HttpRequestHelper::post(
$url,
@@ -55,7 +55,7 @@ class HttpRequestHelper {
*
* @return int
*/
public static function numRetriesOnHttpTooEarly():int {
public static function numRetriesOnHttpTooEarly(): int {
// Currently reva and oCIS may return HTTP_TOO_EARLY
// So try up to 10 times before giving up.
return 10;
@@ -93,7 +93,7 @@ class HttpRequestHelper {
bool $stream = false,
?int $timeout = 0,
?Client $client = null
):ResponseInterface {
): ResponseInterface {
if ($client === null) {
$client = self::createClient(
$user,
@@ -196,7 +196,7 @@ class HttpRequestHelper {
?int $timeout = 0,
?Client $client = null,
?bool $isGivenStep = false
):ResponseInterface {
): ResponseInterface {
if ((\getenv('DEBUG_ACCEPTANCE_RESPONSES') !== false) || (\getenv('DEBUG_ACCEPTANCE_API_CALLS') !== false)) {
$debugResponses = true;
} else {
@@ -222,7 +222,10 @@ class HttpRequestHelper {
$client
);
if ($response->getStatusCode() >= 400 && $response->getStatusCode() !== self::HTTP_TOO_EARLY && $response->getStatusCode() !== self::HTTP_CONFLICT) {
if ($response->getStatusCode() >= 400
&& $response->getStatusCode() !== self::HTTP_TOO_EARLY
&& $response->getStatusCode() !== self::HTTP_CONFLICT
) {
$sendExceptionHappened = true;
}
@@ -261,7 +264,7 @@ class HttpRequestHelper {
*
* @return void
*/
private static function debugRequest(?RequestInterface $request, ?string $user, ?string $password):void {
private static function debugRequest(?RequestInterface $request, ?string $user, ?string $password): void {
print("### AUTH: $user:$password\n");
print("### REQUEST: " . $request->getMethod() . " " . $request->getUri() . "\n");
self::printHeaders($request->getHeaders());
@@ -276,7 +279,7 @@ class HttpRequestHelper {
*
* @return void
*/
private static function debugResponse(?ResponseInterface $response):void {
private static function debugResponse(?ResponseInterface $response): void {
print("### RESPONSE\n");
print("Status: " . $response->getStatusCode() . "\n");
self::printHeaders($response->getHeaders());
@@ -291,7 +294,7 @@ class HttpRequestHelper {
*
* @return void
*/
private static function printHeaders(?array $headers):void {
private static function printHeaders(?array $headers): void {
if ($headers) {
print("Headers:\n");
foreach ($headers as $header => $value) {
@@ -313,7 +316,7 @@ class HttpRequestHelper {
*
* @return void
*/
private static function printBody(?StreamInterface $body):void {
private static function printBody(?StreamInterface $body): void {
print("Body:\n");
\var_dump($body->getContents());
// Rewind the stream so that later code can read from the start.
@@ -333,7 +336,7 @@ class HttpRequestHelper {
public static function sendBatchRequest(
?array $requests,
?Client $client
):array {
): array {
return Pool::batch($client, $requests);
}
@@ -358,7 +361,7 @@ class HttpRequestHelper {
?CookieJar $cookies = null,
?bool $stream = false,
?int $timeout = 0
):Client {
): Client {
$options = [];
if ($user !== null) {
$options['auth'] = [$user, $password];
@@ -396,7 +399,7 @@ class HttpRequestHelper {
?string $method = 'GET',
?array $headers = null,
$body = null
):RequestInterface {
): RequestInterface {
if ($headers === null) {
$headers = [];
}
@@ -449,7 +452,7 @@ class HttpRequestHelper {
?array $config = null,
?CookieJar $cookies = null,
?bool $stream = false
):ResponseInterface {
): ResponseInterface {
return self::sendRequest(
$url,
$xRequestId,
@@ -491,7 +494,7 @@ class HttpRequestHelper {
?array $config = null,
?CookieJar $cookies = null,
?bool $stream = false
):ResponseInterface {
): ResponseInterface {
return self::sendRequest(
$url,
$xRequestId,
@@ -533,7 +536,7 @@ class HttpRequestHelper {
?array $config = null,
?CookieJar $cookies = null,
?bool $stream = false
):ResponseInterface {
): ResponseInterface {
return self::sendRequest(
$url,
$xRequestId,
@@ -576,7 +579,7 @@ class HttpRequestHelper {
?array $config = null,
?CookieJar $cookies = null,
?bool $stream = false
):ResponseInterface {
): ResponseInterface {
return self::sendRequest(
$url,
$xRequestId,
@@ -605,7 +608,7 @@ class HttpRequestHelper {
* @return SimpleXMLElement
* @throws Exception
*/
public static function getResponseXml(ResponseInterface $response, ?string $exceptionText = ''):SimpleXMLElement {
public static function getResponseXml(ResponseInterface $response, ?string $exceptionText = ''): SimpleXMLElement {
// rewind just to make sure we can reparse it in case it was parsed already...
$response->getBody()->rewind();
$contents = $response->getBody()->getContents();
@@ -647,7 +650,7 @@ class HttpRequestHelper {
*
* @return array
*/
public static function parseResponseAsXml(ResponseInterface $response):array {
public static function parseResponseAsXml(ResponseInterface $response): array {
// rewind so that we can reparse it if it was parsed already
$response->getBody()->rewind();
$body = $response->getBody()->getContents();
@@ -56,7 +56,11 @@ class OcisConfigHelper {
try {
$response = $client->send($request);
} catch (ConnectException $e) {
throw new \Error("Cannot connect to the ociswrapper at the moment, make sure that ociswrapper is running before proceeding with the test run.\n" . $e->getMessage());
throw new \Error(
"Cannot connect to the ociswrapper at the moment,"
. "make sure that ociswrapper is running before proceeding with the test run.\n"
. $e->getMessage()
);
} catch (GuzzleException $ex) {
$response = $ex->getResponse();
+15 -15
View File
@@ -87,7 +87,7 @@ class OcisHelper {
/**
* @return bool
*/
public static function isTestingOnReva():bool {
public static function isTestingOnReva(): bool {
return (\getenv("TEST_REVA") === "true");
}
@@ -106,7 +106,7 @@ class OcisHelper {
* @return string
* @throws Exception
*/
public static function getStorageDriver():string {
public static function getStorageDriver(): string {
$storageDriver = (\getenv("STORAGE_DRIVER"));
if ($storageDriver === false) {
return StorageDriver::OWNCLOUD;
@@ -166,7 +166,7 @@ class OcisHelper {
*
* @return void
*/
public static function recurseCopy(?string $source, ?string $destination):void {
public static function recurseCopy(?string $source, ?string $destination): void {
$dir = \opendir($source);
@\mkdir($destination);
while (($file = \readdir($dir)) !== false) {
@@ -184,7 +184,7 @@ class OcisHelper {
/**
* @return int
*/
public static function getLdapPort():int {
public static function getLdapPort(): int {
$port = \getenv("REVA_LDAP_PORT");
return $port ? (int)$port : 636;
}
@@ -192,7 +192,7 @@ class OcisHelper {
/**
* @return bool
*/
public static function useSsl():bool {
public static function useSsl(): bool {
$useSsl = \getenv("REVA_LDAP_USESSL");
if ($useSsl === false) {
return (self::getLdapPort() === 636);
@@ -204,7 +204,7 @@ class OcisHelper {
/**
* @return string
*/
public static function getBaseDN():string {
public static function getBaseDN(): string {
$dn = \getenv("REVA_LDAP_BASE_DN");
return $dn ?: "dc=owncloud,dc=com";
}
@@ -212,7 +212,7 @@ class OcisHelper {
/**
* @return string
*/
public static function getGroupsOU():string {
public static function getGroupsOU(): string {
$ou = \getenv("REVA_LDAP_GROUPS_OU");
return $ou ?: "TestGroups";
}
@@ -220,7 +220,7 @@ class OcisHelper {
/**
* @return string
*/
public static function getUsersOU():string {
public static function getUsersOU(): string {
$ou = \getenv("REVA_LDAP_USERS_OU");
return $ou ?: "TestUsers";
}
@@ -228,14 +228,14 @@ class OcisHelper {
/**
* @return string
*/
public static function getGroupSchema():string {
public static function getGroupSchema(): string {
$schema = \getenv("REVA_LDAP_GROUP_SCHEMA");
return $schema ?: "rfc2307";
}
/**
* @return string
*/
public static function getHostname():string {
public static function getHostname(): string {
$hostname = \getenv("REVA_LDAP_HOSTNAME");
return $hostname ?: "localhost";
}
@@ -243,7 +243,7 @@ class OcisHelper {
/**
* @return string
*/
public static function getBindDN():string {
public static function getBindDN(): string {
$dn = \getenv("REVA_LDAP_BIND_DN");
return $dn ?: "cn=admin,dc=owncloud,dc=com";
}
@@ -251,7 +251,7 @@ class OcisHelper {
/**
* @return string
*/
public static function getBindPassword():string {
public static function getBindPassword(): string {
$pw = \getenv("REVA_LDAP_BIND_PASSWORD");
return $pw ?: "";
}
@@ -259,7 +259,7 @@ class OcisHelper {
/**
* @return string
*/
private static function getOcisRevaDataRoot():string {
private static function getOcisRevaDataRoot(): string {
$root = \getenv("OCIS_REVA_DATA_ROOT");
if ($root === false || $root === "") {
$root = "/var/tmp/ocis/owncloud/";
@@ -275,7 +275,7 @@ class OcisHelper {
*
* @return bool
*/
private static function recurseRmdir(?string $dir):bool {
private static function recurseRmdir(?string $dir): bool {
if (\file_exists($dir) === true) {
$files = \array_diff(\scandir($dir), ['.', '..']);
foreach ($files as $file) {
@@ -307,7 +307,7 @@ class OcisHelper {
?string $user,
?string $password,
?string $xRequestId = ''
):void {
): void {
HttpRequestHelper::get(
$baseUrl . "/ocs/v2.php/apps/notifications/api/v1/notifications",
$xRequestId,
@@ -56,7 +56,7 @@ class OcsApiHelper {
$body = [],
?int $ocsApiVersion = 2,
?array $headers = []
):ResponseInterface {
): ResponseInterface {
$fullUrl = $baseUrl;
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
@@ -86,7 +86,7 @@ class OcsApiHelper {
$body = [],
?int $ocsApiVersion = 2,
?array $headers = []
):RequestInterface {
): RequestInterface {
$fullUrl = $baseUrl;
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
@@ -55,7 +55,13 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getBundlesList(string $baseUrl, string $user, string $password, string $xRequestId, array $headers = []): ResponseInterface {
public static function getBundlesList(
string $baseUrl,
string $user,
string $password,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "bundles-list");
return HttpRequestHelper::post(
$fullUrl,
@@ -79,7 +85,13 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getBundleByName(string $baseUrl, string $user, string $password, string $bundleName, string $xRequestId): array {
public static function getBundleByName(
string $baseUrl,
string $user,
string $password,
string $bundleName,
string $xRequestId
): array {
$response = self::getBundlesList($baseUrl, $user, $password, $xRequestId);
Assert::assertEquals(201, $response->getStatusCode(), "Failed to get bundles list");
@@ -104,7 +116,13 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getRolesList(string $baseUrl, string $user, string $password, string $xRequestId, array $headers = []): ResponseInterface {
public static function getRolesList(
string $baseUrl,
string $user,
string $password,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "roles-list");
return HttpRequestHelper::post(
$fullUrl,
@@ -130,7 +148,15 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function assignRoleToUser(string $baseUrl, string $user, string $password, string $assigneeId, string $roleId, string $xRequestId, array $headers = []): ResponseInterface {
public static function assignRoleToUser(
string $baseUrl,
string $user,
string $password,
string $assigneeId,
string $roleId,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "assignments-add");
$body = json_encode(["account_uuid" => $assigneeId, "role_id" => $roleId], JSON_THROW_ON_ERROR);
return HttpRequestHelper::post(
@@ -156,7 +182,14 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getAssignmentsList(string $baseUrl, string $user, string $password, string $userId, string $xRequestId, array $headers = []): ResponseInterface {
public static function getAssignmentsList(
string $baseUrl,
string $user,
string $password,
string $userId,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "assignments-list");
$body = json_encode(["account_uuid" => $userId], JSON_THROW_ON_ERROR);
return HttpRequestHelper::post(
@@ -181,7 +214,13 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getValuesList(string $baseUrl, string $user, string $password, string $xRequestId, array $headers = []): ResponseInterface {
public static function getValuesList(
string $baseUrl,
string $user,
string $password,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "values-list");
$body = json_encode(["account_uuid" => "me"], JSON_THROW_ON_ERROR);
return HttpRequestHelper::post(
@@ -205,7 +244,12 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getAutoAcceptSharesSettingValue(string $baseUrl, string $user, string $password, string $xRequestId): bool {
public static function getAutoAcceptSharesSettingValue(
string $baseUrl,
string $user,
string $password,
string $xRequestId
): bool {
$response = self::getValuesList($baseUrl, $user, $password, $xRequestId);
Assert::assertEquals(201, $response->getStatusCode(), "Failed to get values list");
@@ -235,7 +279,12 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getLanguageSettingValue(string $baseUrl, string $user, string $password, string $xRequestId): string {
public static function getLanguageSettingValue(
string $baseUrl,
string $user,
string $password,
string $xRequestId
): string {
$response = self::getValuesList($baseUrl, $user, $password, $xRequestId);
Assert::assertEquals(201, $response->getStatusCode(), "Failed to get values list");
@@ -267,7 +316,14 @@ class SettingsHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function updateSettings(string $baseUrl, string $user, string $password, string $body, string $xRequestId, array $headers = []): ResponseInterface {
public static function updateSettings(
string $baseUrl,
string $user,
string $password,
string $body,
string $xRequestId,
array $headers = []
): ResponseInterface {
$fullUrl = self::buildFullUrl($baseUrl, "values-save");
return HttpRequestHelper::post(
$fullUrl,
+11 -11
View File
@@ -43,7 +43,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
*
* @return array of suite context parameters
*/
public static function getSuiteParameters(HookScope $scope):array {
public static function getSuiteParameters(HookScope $scope): array {
return $scope->getEnvironment()->getSuite()
->getSettings() ['context'] ['parameters'];
}
@@ -90,7 +90,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $adminUsername,
?string $adminPassword,
?string $xRequestId = ''
):SimpleXMLElement {
): SimpleXMLElement {
$result = OcsApiHelper::sendRequest(
$baseUrl,
$adminUsername,
@@ -122,7 +122,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $adminUsername,
?string $adminPassword,
?string $xRequestId = ''
):string {
): string {
$sysInfo = self::getSysInfo(
$baseUrl,
$adminUsername,
@@ -141,7 +141,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
* @return string
* @throws Exception
*/
private static function checkAdminUsername(?string $adminUsername, ?string $callerName):?string {
private static function checkAdminUsername(?string $adminUsername, ?string $callerName): ?string {
if (self::$adminUsername === null
&& $adminUsername === null
) {
@@ -162,7 +162,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
* @return string
* @throws Exception
*/
private static function checkAdminPassword(?string $adminPassword, ?string $callerName):string {
private static function checkAdminPassword(?string $adminPassword, ?string $callerName): string {
if (self::$adminPassword === null
&& $adminPassword === null
) {
@@ -183,7 +183,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
* @return string
* @throws Exception
*/
private static function checkBaseUrl(?string $baseUrl, ?string $callerName):?string {
private static function checkBaseUrl(?string $baseUrl, ?string $callerName): ?string {
if (self::$baseUrl === null
&& $baseUrl === null
) {
@@ -215,7 +215,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $baseUrl = null,
?string $adminUsername = null,
?string $adminPassword = null
):void {
): void {
$baseUrl = self::checkBaseUrl($baseUrl, "mkDirOnServer");
$adminUsername = self::checkAdminUsername($adminUsername, "mkDirOnServer");
$adminPassword = self::checkAdminPassword($adminPassword, "mkDirOnServer");
@@ -254,7 +254,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $baseUrl = null,
?string $adminUsername = null,
?string $adminPassword = null
):void {
): void {
$baseUrl = self::checkBaseUrl($baseUrl, "rmDirOnServer");
$adminUsername = self::checkAdminUsername($adminUsername, "rmDirOnServer");
$adminPassword = self::checkAdminPassword($adminPassword, "rmDirOnServer");
@@ -295,7 +295,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $baseUrl = null,
?string $adminUsername = null,
?string $adminPassword = null
):void {
): void {
$baseUrl = self::checkBaseUrl($baseUrl, "createFileOnServer");
$adminUsername = self::checkAdminUsername($adminUsername, "createFileOnServer");
$adminPassword = self::checkAdminPassword($adminPassword, "createFileOnServer");
@@ -337,7 +337,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $baseUrl = null,
?string $adminUsername = null,
?string $adminPassword = null
):void {
): void {
$baseUrl = self::checkBaseUrl($baseUrl, "deleteFileOnServer");
$adminUsername = self::checkAdminUsername($adminUsername, "deleteFileOnServer");
$adminPassword = self::checkAdminPassword($adminPassword, "deleteFileOnServer");
@@ -377,7 +377,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
?string $baseUrl = null,
?string $adminUsername = null,
?string $adminPassword = null
):string {
): string {
$baseUrl = self::checkBaseUrl($baseUrl, "readFile");
$adminUsername = self::checkAdminUsername(
$adminUsername,
@@ -192,7 +192,7 @@ class SharingHelper {
* @throws InvalidArgumentException
*
*/
public static function getPermissionSum($permissions):int {
public static function getPermissionSum($permissions): int {
if (\is_numeric($permissions)) {
// Allow any permission number so that test scenarios can
// specifically test invalid permission values
@@ -230,7 +230,7 @@ class SharingHelper {
* @throws InvalidArgumentException
*
*/
public static function getShareType($shareType):int {
public static function getShareType($shareType): int {
if (\array_key_exists($shareType, self::SHARE_TYPES)) {
return self::SHARE_TYPES[$shareType];
} else {
@@ -259,7 +259,7 @@ class SharingHelper {
public static function getLastShareIdFromResponse(
SimpleXMLElement $responseXmlObject,
string $errorMessage = "cannot find share id in response"
):string {
): string {
$xmlPart = $responseXmlObject->xpath("//data/element[last()]/id");
if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
@@ -138,7 +138,7 @@ class UploadHelper extends Assert {
*
* @return array $string
*/
public static function chunkFile(?string $file, ?int $noOfChunks = 1):array {
public static function chunkFile(?string $file, ?int $noOfChunks = 1): array {
$size = \filesize($file);
$chunkSize = \ceil($size / $noOfChunks);
$chunks = [];
@@ -162,7 +162,7 @@ class UploadHelper extends Assert {
*
* @return void
*/
public static function createFileSpecificSize(?string $name, ?int $size):void {
public static function createFileSpecificSize(?string $name, ?int $size): void {
if (\file_exists($name)) {
\unlink($name);
}
@@ -190,7 +190,7 @@ class UploadHelper extends Assert {
*
* @return void
*/
public static function createFileWithText(?string $name, ?string $text):void {
public static function createFileWithText(?string $name, ?string $text): void {
$file = \fopen($name, 'w');
\fwrite($file, $text);
\fclose($file);
@@ -207,7 +207,7 @@ class UploadHelper extends Assert {
*
* @return string
*/
public static function getUploadFilesDir(?string $name):string {
public static function getUploadFilesDir(?string $name): string {
return \getenv("FILES_FOR_UPLOAD") . $name;
}
}
+8 -8
View File
@@ -56,7 +56,7 @@ class UserHelper {
string $adminPassword,
string $xRequestId = '',
?int $ocsApiVersion = 2
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -90,7 +90,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?int $ocsApiVersion = 2
):array {
): array {
$requests = [];
$client = HttpRequestHelper::createClient(
$adminUser,
@@ -143,7 +143,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?int $ocsApiVersion = 2
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -175,7 +175,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?int $ocsApiVersion = 2
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -209,7 +209,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?int $ocsApiVersion = 2
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -243,7 +243,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId,
?int $ocsApiVersion = 2
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -273,7 +273,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?string $search =""
):ResponseInterface {
): ResponseInterface {
return OcsApiHelper::sendRequest(
$baseUrl,
$adminUser,
@@ -301,7 +301,7 @@ class UserHelper {
?string $adminPassword,
?string $xRequestId = '',
?string $search = ""
):array {
): array {
$result = self::getGroups(
$baseUrl,
$adminUser,
+42 -19
View File
@@ -86,7 +86,7 @@ class WebDavHelper {
*/
public static function removeSpaceIdReferenceForUser(
?string $user
):void {
): void {
if (\array_key_exists($user, self::$spacesIdRef)) {
unset(self::$spacesIdRef[$user]);
}
@@ -245,7 +245,7 @@ class WebDavHelper {
?int $davPathVersionToUse = self::DAV_VERSION_NEW,
?string $doDavRequestAsUser = null,
?array $headers = []
):ResponseInterface {
): ResponseInterface {
$body = self::getBodyForPropfind($properties);
$folderDepth = (string) $folderDepth;
if ($folderDepth !== '0' && $folderDepth !== '1' && $folderDepth !== 'infinity') {
@@ -307,7 +307,7 @@ class WebDavHelper {
?int $davPathVersionToUse = self::DAV_VERSION_NEW,
?string $type="files",
?string $spaceId = null,
):ResponseInterface {
): ResponseInterface {
if ($namespaceString !== null) {
$ns = self::parseNamespace($namespaceString);
$propertyBody = "<$ns->prefix:$propertyName" .
@@ -348,7 +348,7 @@ class WebDavHelper {
*
* @return array
*/
public static function getPropertyWithNamespaceInfo(string $namespaceString = "", string $property = ""):array {
public static function getPropertyWithNamespaceInfo(string $namespaceString = "", string $property = ""): array {
$namespace = "";
$namespacePrefix = "";
if (\is_int($namespaceString)) {
@@ -396,7 +396,7 @@ class WebDavHelper {
?int $davPathVersion = null,
?string $namespaceString = null,
?string $type="files"
):ResponseInterface {
): ResponseInterface {
$propertyBody = "";
foreach ($propertiesArray as $propertyArray) {
$property = $propertyArray["propertyName"];
@@ -466,7 +466,7 @@ class WebDavHelper {
?array $properties = null,
?string $type = "files",
?int $davPathVersionToUse = self::DAV_VERSION_NEW
):ResponseInterface {
): ResponseInterface {
if (!$properties) {
$properties = [
'd:getetag', 'd:resourcetype'
@@ -493,7 +493,7 @@ class WebDavHelper {
* @return string
* @throws Exception
*/
public static function generateUUIDv4():string {
public static function generateUUIDv4(): string {
// generate 16 bytes (128 bits) of random data or use the data passed into the function.
$data = random_bytes(16);
\assert(\strlen($data) == 16);
@@ -516,7 +516,12 @@ class WebDavHelper {
* @throws GuzzleException
* @throws Exception
*/
public static function getPersonalSpaceIdForUser(string $baseUrl, string $user, string $password, string $xRequestId):string {
public static function getPersonalSpaceIdForUser(
string $baseUrl,
string $user,
string $password,
string $xRequestId
): string {
if (\array_key_exists($user, self::$spacesIdRef) && \array_key_exists("personal", self::$spacesIdRef[$user])) {
return self::$spacesIdRef[$user]["personal"];
}
@@ -546,14 +551,21 @@ class WebDavHelper {
$user,
$password
);
Assert::assertEquals(207, $response->getStatusCode(), "PROPFIND for user '$user' failed so the personal space id cannot be discovered");
Assert::assertEquals(
207,
$response->getStatusCode(),
"PROPFIND for user '$user' failed so the personal space id cannot be discovered"
);
$responseXmlObject = HttpRequestHelper::getResponseXml(
$response,
__METHOD__
);
$xmlPart = $responseXmlObject->xpath("/d:multistatus/d:response[1]/d:propstat/d:prop/oc:spaceid");
Assert::assertNotEmpty($xmlPart, "The 'oc:spaceid' for user '$user' was not found in the PROPFIND response");
Assert::assertNotEmpty(
$xmlPart,
"The 'oc:spaceid' for user '$user' was not found in the PROPFIND response"
);
$personalSpaceId = $xmlPart[0]->__toString();
}
@@ -577,7 +589,12 @@ class WebDavHelper {
* @return string
* @throws Exception|GuzzleException
*/
public static function getPersonalSpaceIdForUserOrFakeIfNotFound(string $baseUrl, string $user, string $password, string $xRequestId):string {
public static function getPersonalSpaceIdForUserOrFakeIfNotFound(
string $baseUrl,
string $user,
string $password,
string $xRequestId
): string {
if (\str_starts_with($user, "non-exist") || \str_starts_with($user, "nonexist")) {
return self::generateUUIDv4();
}
@@ -641,7 +658,7 @@ class WebDavHelper {
?array $urlParameter = [],
?string $doDavRequestAsUser = null,
?bool $isGivenStep = false,
):ResponseInterface {
): ResponseInterface {
$baseUrl = self::sanitizeUrl($baseUrl, true);
// We need to manipulate and use path as a string.
@@ -651,7 +668,9 @@ class WebDavHelper {
}
// get space id if testing with spaces dav
if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES && !\in_array($type, ["public-files", "versions"])) {
if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES
&& !\in_array($type, ["public-files", "versions"])
) {
$path = \ltrim($path, "/");
if (\str_starts_with($path, "Shares/")) {
$spaceId = GraphHelper::SHARES_SPACE_ID;
@@ -667,7 +686,9 @@ class WebDavHelper {
}
$suffixPath = $user;
if ($davPathVersionToUse === self::DAV_VERSION_SPACES && !\in_array($type, ["archive", "versions", "public-files"])) {
if ($davPathVersionToUse === self::DAV_VERSION_SPACES
&& !\in_array($type, ["archive", "versions", "public-files"])
) {
$suffixPath = $spaceId;
} elseif ($type === "versions") {
// $path is file-id in case of versions
@@ -751,7 +772,7 @@ class WebDavHelper {
int $davPathVersion,
?string $userOrItemIdOrSpaceIdOrToken = null,
?string $type = "files"
):string {
): string {
switch ($type) {
case 'archive':
return self::prefixRemotePhp("dav/archive/$userOrItemIdOrSpaceIdOrToken/files");
@@ -807,7 +828,7 @@ class WebDavHelper {
*
* @return string
*/
public static function sanitizeUrl(?string $url, ?bool $trailingSlash = false):string {
public static function sanitizeUrl(?string $url, ?bool $trailingSlash = false): string {
if ($trailingSlash === true) {
$url = $url . "/";
} else {
@@ -834,7 +855,7 @@ class WebDavHelper {
?string $token,
?string $xRequestId = '',
?int $davVersionToUse = self::DAV_VERSION_NEW
):string {
): string {
$response = self::propfind(
$baseUrl,
null,
@@ -879,7 +900,7 @@ class WebDavHelper {
?string $xRequestId = '',
?int $davPathVersionToUse = self::DAV_VERSION_NEW,
?string $spaceId = null,
):string {
): string {
$response = self::propfind(
$baseUrl,
$user,
@@ -900,7 +921,9 @@ class WebDavHelper {
Assert::assertArrayHasKey(
0,
$xmlPart,
__METHOD__ . " XML part does not have key 0. Expected a value at index 0 of 'xmlPart' but, found: " . json_encode($xmlPart)
__METHOD__
. " XML part does not have key 0. Expected a value at index 0 of 'xmlPart' but, found: "
. json_encode($xmlPart)
);
$mtime = new DateTime($xmlPart[0]->__toString());
return $mtime->format('U');