Skip to content

Commit

Permalink
Merge pull request #310 from owncloud/bump-guzzle-behat
Browse files Browse the repository at this point in the history
[tests-only] [full-ci] Update test dependencies and function types
  • Loading branch information
individual-it authored Oct 20, 2021
2 parents d0c4194 + 2d4ec30 commit 693b202
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 52 deletions.
83 changes: 49 additions & 34 deletions tests/acceptance/features/bootstrap/Oauth2Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
use Page\Oauth2AuthRequestPage;
Expand Down Expand Up @@ -116,15 +115,15 @@ public function __construct(
* @When /^user "([^"]*)" sends an oauth2 authorization request using the webUI$/
* @Given /^user "([^"]*)" has sent an oauth2 authorization request$/
*
* @param string $username
* @param string $clientId
* @param string|null $username
* @param string|null $clientId
*
* @return void
*/
public function oauthAuthorizationRequestUsingTheWebui(
$username = null,
$clientId = null
) {
?string $username = null,
?string $clientId = null
): void {
if ($clientId === null) {
$clientId = $this->clientId;
}
Expand All @@ -146,20 +145,20 @@ public function oauthAuthorizationRequestUsingTheWebui(
*
* @return void
*/
public function theUserSendsOauthAuthorizationRequestUsingTheWebui() {
public function theUserSendsOauthAuthorizationRequestUsingTheWebui(): void {
$this->oauthAuthorizationRequestUsingTheWebui();
}

/**
* @When /^the user(?: "([^"]*)")? sends an oauth2 authorization request with the new client-id using the webUI$/
*
* @param string $username
* @param string|null $username
*
* @return void
*/
public function oauthAuthorizationRequestWithNewClientIdUsingTheWebui(
$username = null
) {
?string $username = null
): void {
$this->oauthAuthorizationRequestUsingTheWebui(
$username,
\end($this->createdOauthClients)['client_id']
Expand All @@ -171,7 +170,7 @@ public function oauthAuthorizationRequestWithNewClientIdUsingTheWebui(
*
* @return void
*/
public function oAuthAuthorizationRequestUnregisteredClientIdUsingTheWebui() {
public function oAuthAuthorizationRequestUnregisteredClientIdUsingTheWebui(): void {
$this->visitPath(
$this->featureContext->getBaseUrl() .
'/index.php/apps/oauth2/authorize?response_type=code&client_id=xxxxxx' .
Expand All @@ -186,7 +185,7 @@ public function oAuthAuthorizationRequestUnregisteredClientIdUsingTheWebui() {
*
* @return void
*/
public function theUserAuthorizesOauthAppUsingTheWebUI() {
public function theUserAuthorizesOauthAppUsingTheWebUI(): void {
$this->oauth2AuthRequestPage->authorizeApp();
}

Expand All @@ -197,7 +196,7 @@ public function theUserAuthorizesOauthAppUsingTheWebUI() {
*
* @return void
*/
public function establishOauthSession($user) {
public function establishOauthSession(string $user): void {
$this->oauthAuthorizationRequestUsingTheWebui();
$this->webUILoginContext
->userLogInWithUsernameAndPasswordAfterRedirectFromPage(
Expand All @@ -214,7 +213,7 @@ public function establishOauthSession($user) {
*
* @return void
*/
public function refreshAccessToken() {
public function refreshAccessToken(): void {
$oldAccessToken = $this->accessTokenResponse->access_token;
$this->clientAppRequestsAccessToken(
$this->accessTokenResponse->refresh_token
Expand All @@ -231,7 +230,7 @@ public function refreshAccessToken() {
*
* @return void
*/
public function switchTheUserToContinueOauthProcess() {
public function switchTheUserToContinueOauthProcess(): void {
$this->oauth2AuthRequestPage->switchUsers();
}

Expand All @@ -248,10 +247,10 @@ public function switchTheUserToContinueOauthProcess() {
* @return void
*/
public function clientAppRequestsAccessToken(
$refreshToken = null,
$clientId = null,
$clientSecret = null
) {
?string $refreshToken = null,
?string $clientId = null,
?string $clientSecret = null
): void {
$redirectUri = \parse_url($this->getSession()->getCurrentUrl());
\parse_str($redirectUri['query'], $parameters);
if ($clientId === null) {
Expand Down Expand Up @@ -300,8 +299,8 @@ public function clientAppRequestsAccessToken(
* @return void
*/
public function clientAppRequestsAccessTokenWithNewClientId(
$refreshToken = null
) {
?string $refreshToken = null
): void {
$this->clientAppRequestsAccessToken(
$refreshToken,
\end($this->createdOauthClients)['client_id'],
Expand All @@ -318,7 +317,10 @@ public function clientAppRequestsAccessTokenWithNewClientId(
*
* @return void
*/
public function userRequestsURLWithOAuth($url, $method) {
public function userRequestsURLWithOAuth(
string $url,
string $method
): void {
$this->featureContext->authContext->sendRequest(
$url,
$method,
Expand All @@ -333,7 +335,7 @@ public function userRequestsURLWithOAuth($url, $method) {
*
* @return void
*/
public function revokeOauthAppUsingTheWebUI($appName) {
public function revokeOauthAppUsingTheWebUI(string $appName): void {
$this->oath2OnPersonalSecurityPage->revokeApp(
$this->getSession(),
$appName
Expand All @@ -346,7 +348,7 @@ public function revokeOauthAppUsingTheWebUI($appName) {
*
* @return void
*/
public function theUserBrowsesToTheOauth2AdminSettingsPage() {
public function theUserBrowsesToTheOauth2AdminSettingsPage(): void {
$this->oauth2AdminSettingsPage->open();
}

Expand All @@ -358,7 +360,10 @@ public function theUserBrowsesToTheOauth2AdminSettingsPage() {
*
* @return void
*/
public function addNewOauthClientUsingTheWebUI($name, $uri) {
public function addNewOauthClientUsingTheWebUI(
string $name,
string $uri
): void {
$this->oauth2AdminSettingsPage->addClient($name, $uri);
$client = $this->oauth2AdminSettingsPage->getClientInformationByName($name);
$this->createdOauthClients[] = $client;
Expand All @@ -372,7 +377,10 @@ public function addNewOauthClientUsingTheWebUI($name, $uri) {
*
* @return void
*/
public function addNewOauthClient($name, $uri) {
public function addNewOauthClient(
string $name,
string $uri
): void {
$this->webUIGeneralContext->adminLogsInUsingTheWebUI();
$this->theUserBrowsesToTheOauth2AdminSettingsPage();
$this->addNewOauthClientUsingTheWebUI($name, $uri);
Expand All @@ -388,7 +396,11 @@ public function addNewOauthClient($name, $uri) {
*
* @return void
*/
public function accessFileUsingOauthToken($shouldOrNot, $file, $user) {
public function accessFileUsingOauthToken(
string $shouldOrNot,
string $file,
string $user
): void {
$should = ($shouldOrNot !== "not");
// The capturing groups of the regex include the quotes at each
// end of the captured string, so trim them.
Expand Down Expand Up @@ -451,7 +463,7 @@ public function accessFileUsingOauthToken($shouldOrNot, $file, $user) {
*
* @return void
*/
public function clientAppShouldReceiveAuthCode() {
public function clientAppShouldReceiveAuthCode(): void {
$redirectUri = \parse_url($this->getSession()->getCurrentUrl());
Assert::assertEquals(
$this->redirectUriHost,
Expand Down Expand Up @@ -481,7 +493,7 @@ public function clientAppShouldReceiveAuthCode() {
*
* @return void
*/
public function invalidOauthRequestMessageShouldBeShown() {
public function invalidOauthRequestMessageShouldBeShown(): void {
$error = $this->oauth2AuthRequestPage->getErrorMessageHeading();
Assert::assertSame("Request not valid", $error);
}
Expand All @@ -491,7 +503,7 @@ public function invalidOauthRequestMessageShouldBeShown() {
*
* @return void
*/
public function appShouldNotBeAbleToRefreshToken() {
public function appShouldNotBeAbleToRefreshToken(): void {
$this->clientAppRequestsAccessToken(
$this->accessTokenResponse->refresh_token
);
Expand All @@ -512,7 +524,10 @@ public function appShouldNotBeAbleToRefreshToken() {
*
* @return void
*/
public function assertClientIsListedOnWebUI($name, $uri) {
public function assertClientIsListedOnWebUI(
string $name,
string $uri
): void {
$client = $this->oauth2AdminSettingsPage->getClientInformationByName($name);
Assert::assertSame(
$name,
Expand All @@ -536,7 +551,7 @@ public function assertClientIsListedOnWebUI($name, $uri) {
*
* @return void
*/
public function before(BeforeScenarioScope $scope) {
public function before(BeforeScenarioScope $scope): void {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
Expand All @@ -551,7 +566,7 @@ public function before(BeforeScenarioScope $scope) {
*
* @return void
*/
public function after() {
public function after(): void {
$this->featureContext->authContext->aNewBrowserSessionForHasBeenStarted(
$this->featureContext->getAdminUsername()
);
Expand All @@ -572,7 +587,7 @@ public function after() {
*
* @return int port number
*/
private function findAvailablePort() {
private function findAvailablePort(): int {
$socket = \socket_create_listen(0);
\socket_getsockname($socket, $address, $port);
\socket_close($socket);
Expand Down
10 changes: 7 additions & 3 deletions tests/acceptance/features/lib/Oauth2AdminSettingsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ class Oauth2AdminSettingsPage extends OwncloudPage {
*
* @param string $appName
* @param string $redirectionUri
* @param boolean $allowSubdomains
* @param bool $allowSubdomains
*
* @return void
* @throws ElementNotFoundException
*
*/
public function addClient($appName, $redirectionUri, $allowSubdomains = false) {
public function addClient(
string $appName,
string $redirectionUri,
bool $allowSubdomains = false
): void {
$this->fillField($this->oauthAppNameInputId, $appName);
$this->fillField($this->oauthRedirectionUriInputId, $redirectionUri);
if ($allowSubdomains === true) {
Expand Down Expand Up @@ -83,7 +87,7 @@ public function addClient($appName, $redirectionUri, $allowSubdomains = false) {
*
* @return string[] array with keys name,redirection_uri,client_id,client_secret,id
*/
public function getClientInformationByName($name) {
public function getClientInformationByName(string $name): array {
$xpath = \sprintf($this->clientRowByNameXpath, $name);
$tds = $this->findAll("xpath", $xpath);
if (\count($tds) === 0) {
Expand Down
20 changes: 10 additions & 10 deletions tests/acceptance/features/lib/Oauth2AuthRequestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Oauth2AuthRequestPage extends OwncloudPage {
*
* @return void
*/
public function authorizeApp() {
public function authorizeApp(): void {
$submitButton = $this->find("xpath", $this->authorizeButtonXpath);

if ($submitButton === null) {
throw new ElementNotFoundException(
__METHOD__ .
Expand All @@ -59,9 +59,9 @@ public function authorizeApp() {
*
* @return void
*/
public function switchUsers() {
public function switchUsers(): void {
$switchUsersButton = $this->find("xpath", $this->switchUsersButtonXpath);

if ($switchUsersButton === null) {
throw new ElementNotFoundException(
__METHOD__ .
Expand All @@ -78,20 +78,20 @@ public function switchUsers() {
*
* @return string
*/
public function getErrorMessageHeading() {
public function getErrorMessageHeading(): string {
$errorMessageHeadingElement = $this->find(
"xpath",
$this->errorMessageHeadingXpath
);

if ($errorMessageHeadingElement === null) {
throw new ElementNotFoundException(
__METHOD__ .
" xpath $this->errorMessageHeadingXpath " .
"could not find heading of error message"
);
}

return $errorMessageHeadingElement->getText();
}

Expand All @@ -103,8 +103,8 @@ public function getErrorMessageHeading() {
*/
public function waitTillPageIsLoaded(
Session $session,
$timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
) {
int $timeout_msec = STANDARD_UI_WAIT_TIMEOUT_MILLISEC
): void {
$currentTime = \microtime(true);
$end = $currentTime + ($timeout_msec / 1000);
while ($currentTime <= $end) {
Expand All @@ -124,7 +124,7 @@ public function waitTillPageIsLoaded(
\usleep(STANDARD_SLEEP_TIME_MICROSEC);
$currentTime = \microtime(true);
}

if ($currentTime > $end) {
throw new \Exception(
__METHOD__ . " timeout waiting for page to load"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Oauth2OnPersonalSecuritySettingsPage extends OwncloudPage {
*
* @return void
*/
public function revokeApp(Session $session, $app) {
public function revokeApp(Session $session, string $app): void {
$xpath = \sprintf($this->deleteBtnByAppNameXpath, $app);
$revokeBtn = $this->find("xpath", $xpath);
if ($revokeBtn === null) {
Expand Down
8 changes: 4 additions & 4 deletions vendor-bin/behat/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
}
},
"require": {
"behat/behat": "^3.8",
"behat/behat": "^3.9",
"behat/gherkin": "^4.9",
"behat/mink": "1.7.1",
"behat/mink-extension": "^2.3",
"behat/mink-goutte-driver": "^1.2",
"friends-of-behat/mink-extension": "^2.5",
"behat/mink-selenium2-driver": "^1.4",
"ciaranmcnulty/behat-stepthroughextension" : "dev-master",
"jarnaiz/behat-junit-formatter": "^1.3",
"rdx/behat-variables": "^1.2",
"sensiolabs/behat-page-object-extension": "^2.3",
"symfony/translation": "^4.4",
"sabre/xml": "^2.2",
"guzzlehttp/guzzle": "^6.5",
"guzzlehttp/guzzle": "^7.4",
"phpunit/phpunit": "^8.5"
}
}

0 comments on commit 693b202

Please sign in to comment.