Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] removing the setResponse() and $this->response in given/then step in Provisioning file #7510

Closed
wants to merge 1 commit into from

Conversation

nirajacharya2
Copy link
Contributor

@nirajacharya2 nirajacharya2 commented Oct 17, 2023

Description

We have used setResponse() and $this->response in the Given/Then steps and some helper functions (maybe to reuse existing available methods). But storing responses from Given/Then steps and helper functions is not a good idea because it can lead to a false positive assertion in the Then steps.
So, check the use of setResponse() and $this->response in

  • Given steps
  • Then steps (Then steps can use $this->response but must prevent saving to it)
  • Helper functions

So this pr make the above changes in Provisioning.php

Related Issue

part of: #7082

Motivation and Context

  • To remove setResponse() and $this->response in the Given/Then steps and some helper functions
  • To avoid false positive assertions

How Has This Been Tested?

  • test environment:
  • locally
  • CI

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@nirajacharya2 nirajacharya2 self-assigned this Oct 17, 2023
@nirajacharya2 nirajacharya2 force-pushed the refactor-provisioning branch 4 times, most recently from bfae1e5 to a770b07 Compare October 18, 2023 05:40
@nirajacharya2 nirajacharya2 force-pushed the refactor-provisioning branch 6 times, most recently from 49f077d to f7a8a62 Compare October 20, 2023 04:08
@nirajacharya2 nirajacharya2 force-pushed the refactor-provisioning branch 3 times, most recently from 2c46b2b to 0fbb7e4 Compare November 7, 2023 09:39
@nirajacharya2 nirajacharya2 force-pushed the refactor-provisioning branch 4 times, most recently from aae0217 to 573119d Compare November 9, 2023 09:34
@nirajacharya2 nirajacharya2 marked this pull request as ready for review November 9, 2023 11:00
Comment on lines 3485 to 3531
/**
* @param string $user
*
* @return ResponseInterface
* @throws Exception
*/
public function deleteTheUserUsingTheProvisioningApi(string $user):ResponseInterface {
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
$response = null;
// Always try to delete the user
if (OcisHelper::isTestingWithGraphApi()) {
// users can be deleted using the username in the GraphApi too
$response = $this->graphContext->adminDeletesUserUsingTheGraphApi($user);
} else {
$response = UserHelper::deleteUser(
$this->getBaseUrl(),
$user,
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getStepLineRef(),
$this->ocsApiVersion
);
}
if ($response === null) {
$this->pushToLastStatusCodesArrays();
} else {
$this->pushToLastHttpStatusCodesArray((string)$response->getStatusCode());
}

// Only log a message if the test really expected the user to have been
// successfully created (i.e. the delete is expected to work) and
// there was a problem deleting the user. Because in this case there
// might be an effect on later tests.
if ($this->theUserShouldExist($user)
&& (!\in_array($response->getStatusCode(), [200, 204]))
) {
\error_log(
"INFORMATION: could not delete user '$user' "
. $response->getStatusCode() . " " . $response->getBody()
);
}

$this->rememberThatUserIsNotExpectedToExist($user);
return $response;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from rebase?

Comment on lines 4187 to 4189
public function theUsersReturnedByTheApiShouldNotInclude(string $user, ResponseInterface $response):void {
$response = $response ?? $this->response;
$respondedArray = $this->getArrayOfUsersResponded($response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not reuse Then step methods

Comment on lines 4346 to 4347
public function theDisplayNameReturnedByTheApiShouldBe(string $expectedDisplayName, ?ResponseInterface $response = null):void {
$responseDisplayName = (string) $this->getResponseXml($response, __METHOD__)->data[0]->displayname;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for here as well

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@saw-jan saw-jan deleted the refactor-provisioning branch November 27, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants