Skip to content

Commit

Permalink
updating lint rules for test code
Browse files Browse the repository at this point in the history
  • Loading branch information
nirajacharya2 committed Dec 30, 2024
1 parent 24798a8 commit 089ccc1
Show file tree
Hide file tree
Showing 45 changed files with 2,914 additions and 1,151 deletions.
16 changes: 15 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
->exclude($excludeDirs)
->in(__DIR__);

$config = new OC\CodingStandard\Config();
$ocRule = (new OC\CodingStandard\Config())->getRules();
$config = new PhpCsFixer\Config();
$config->setFinder($finder)
->setIndent("\t")
->setRules(
array_merge(
$ocRule,
[
"return_type_declaration" => [
"space_before" => "none",
],
'single_space_around_construct' => true
]
)
);
$config->setFinder($finder);
return $config;
18 changes: 14 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<exclude name="Generic.WhiteSpace.DisallowTabIndent.NonIndentTabsUsed" />
</rule>

<rule ref="Generic.Files.LineLength">
<exclude name="Generic.Files.LineLength.TooLong" />
</rule>

<rule ref="PEAR">
<exclude name="Generic.Commenting.DocComment.ShortNotCapital" />
<exclude name="Generic.Commenting.DocComment.SpacingAfter" />
Expand Down Expand Up @@ -77,4 +73,18 @@
<exclude-pattern>*/lib/storagewrapper.php</exclude-pattern>
</rule>

<rule ref="Generic.Commenting.Todo">
<message>Please review this TODO comment: %s</message>
<type>error</type>
</rule>
<rule ref="Squiz.PHP.NonExecutableCode" />
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
<rule ref="Generic.Files.LineLength">
<properties>
<property name="ignoreComments" value="true" />
<type>error</type>
<property name="lineLimit" value="120" />
<property name="absoluteLineLimit" value="120" />
</properties>
</rule>
</ruleset>
8 changes: 5 additions & 3 deletions tests/acceptance/TestHelpers/Asserts/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function assertDavResponseElementIs(
?string $expectedValue,
?array $responseXmlArray,
?string $extraErrorText = ''
):void {
): void {
if ($extraErrorText !== '') {
$extraErrorText = $extraErrorText . " ";
}
Expand All @@ -58,7 +58,9 @@ public static function assertDavResponseElementIs(
} 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(
Expand All @@ -78,7 +80,7 @@ public static function assertDavResponseElementIs(
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] . "]"
Expand Down
20 changes: 17 additions & 3 deletions tests/acceptance/TestHelpers/AuthAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public static function getAuthAppEndpoint(): string {
*
* @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,
Expand All @@ -61,7 +65,12 @@ public static function listAllAppAuthTokensForUser(string $baseUrl, string $user
*
* @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,
Expand All @@ -80,7 +89,12 @@ public static function createAppAuthToken(string $baseUrl, string $user, string
*
* @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,
Expand Down
6 changes: 5 additions & 1 deletion tests/acceptance/TestHelpers/BehatHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 12 additions & 8 deletions tests/acceptance/TestHelpers/EmailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -45,7 +45,7 @@ public static function getMailBoxFromEmail(string $emailAddress):string {
*
* @return string
*/
public static function getLocalEmailUrl():string {
public static function getLocalEmailUrl(): string {
$localEmailHost = self::getLocalEmailHost();
$emailPort = \getenv('EMAIL_PORT');
if ($emailPort === false) {
Expand All @@ -60,7 +60,7 @@ public static function getLocalEmailUrl():string {
*
* @return string
*/
public static function getEmailHost():string {
public static function getEmailHost(): string {
$emailHost = \getenv('EMAIL_HOST');
if ($emailHost === false) {
$emailHost = "127.0.0.1";
Expand All @@ -74,7 +74,7 @@ public static function getEmailHost():string {
*
* @return string
*/
public static function getLocalEmailHost():string {
public static function getLocalEmailHost(): string {
$localEmailHost = \getenv('LOCAL_EMAIL_HOST');
if ($localEmailHost === false) {
$localEmailHost = self::getEmailHost();
Expand All @@ -92,7 +92,7 @@ public static function getLocalEmailHost():string {
* @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,
Expand All @@ -113,7 +113,11 @@ public static function getMailBoxInformation(string $mailBox, ?string $xRequestI
* @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,
Expand Down Expand Up @@ -142,7 +146,7 @@ public static function getBodyOfLastEmail(
string $xRequestId,
?int $emailNumber = 1,
?int $waitTimeSec = EMAIL_WAIT_TIMEOUT_SEC
):string {
): string {
$currentTime = \time();
$endTime = $currentTime + $waitTimeSec;
$mailBox = self::getMailBoxFromEmail($emailAddress);
Expand Down Expand Up @@ -178,7 +182,7 @@ public static function deleteAllEmailsForAMailbox(
string $localInbucketUrl,
?string $xRequestId,
string $mailBox
):ResponseInterface {
): ResponseInterface {
return HttpRequestHelper::delete(
$localInbucketUrl . "/api/v1/mailbox/" . $mailBox,
$xRequestId
Expand Down
51 changes: 42 additions & 9 deletions tests/acceptance/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public static function getFileIdRegex(): string {
* @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();
}

/**
Expand Down Expand Up @@ -1387,7 +1388,11 @@ public static function getUsersOfTwoGroups(
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,
Expand Down Expand Up @@ -1416,7 +1421,11 @@ public static function getUsersFromOneOrOtherGroup(
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,
Expand Down Expand Up @@ -1472,7 +1481,11 @@ public static function getUsersWithFilterRolesAssignmentAndMemberOf(
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,
Expand Down Expand Up @@ -1669,7 +1682,15 @@ public static function switchSystemLanguage(
): 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)
);
}

/**
Expand Down Expand Up @@ -1810,7 +1831,13 @@ public static function sendSharingInvitation(
?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,
Expand Down Expand Up @@ -2052,7 +2079,7 @@ public static function disableShareSync(
string $password,
string $itemId,
string $shareSpaceId
):ResponseInterface {
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/items/$itemId");
return HttpRequestHelper::delete(
$url,
Expand Down Expand Up @@ -2083,7 +2110,7 @@ public static function hideOrUnhideShare(
string $itemId,
string $shareSpaceId,
array $body
):ResponseInterface {
): ResponseInterface {
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/items/$itemId");
return HttpRequestHelper::sendRequest(
$url,
Expand Down Expand Up @@ -2186,7 +2213,13 @@ public static function sendSharingInvitationForDrive(
?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,
Expand Down
Loading

0 comments on commit 089ccc1

Please sign in to comment.