diff --git a/tests/acceptance/features/bootstrap/Oauth2Context.php b/tests/acceptance/features/bootstrap/Oauth2Context.php index d064706..9112183 100644 --- a/tests/acceptance/features/bootstrap/Oauth2Context.php +++ b/tests/acceptance/features/bootstrap/Oauth2Context.php @@ -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; @@ -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; } @@ -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'] @@ -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' . @@ -186,7 +185,7 @@ public function oAuthAuthorizationRequestUnregisteredClientIdUsingTheWebui() { * * @return void */ - public function theUserAuthorizesOauthAppUsingTheWebUI() { + public function theUserAuthorizesOauthAppUsingTheWebUI(): void { $this->oauth2AuthRequestPage->authorizeApp(); } @@ -197,7 +196,7 @@ public function theUserAuthorizesOauthAppUsingTheWebUI() { * * @return void */ - public function establishOauthSession($user) { + public function establishOauthSession(string $user): void { $this->oauthAuthorizationRequestUsingTheWebui(); $this->webUILoginContext ->userLogInWithUsernameAndPasswordAfterRedirectFromPage( @@ -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 @@ -231,7 +230,7 @@ public function refreshAccessToken() { * * @return void */ - public function switchTheUserToContinueOauthProcess() { + public function switchTheUserToContinueOauthProcess(): void { $this->oauth2AuthRequestPage->switchUsers(); } @@ -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) { @@ -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'], @@ -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, @@ -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 @@ -346,7 +348,7 @@ public function revokeOauthAppUsingTheWebUI($appName) { * * @return void */ - public function theUserBrowsesToTheOauth2AdminSettingsPage() { + public function theUserBrowsesToTheOauth2AdminSettingsPage(): void { $this->oauth2AdminSettingsPage->open(); } @@ -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; @@ -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); @@ -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. @@ -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, @@ -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); } @@ -491,7 +503,7 @@ public function invalidOauthRequestMessageShouldBeShown() { * * @return void */ - public function appShouldNotBeAbleToRefreshToken() { + public function appShouldNotBeAbleToRefreshToken(): void { $this->clientAppRequestsAccessToken( $this->accessTokenResponse->refresh_token ); @@ -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, @@ -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 @@ -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() ); @@ -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); diff --git a/tests/acceptance/features/lib/Oauth2AdminSettingsPage.php b/tests/acceptance/features/lib/Oauth2AdminSettingsPage.php index 4ce96c0..c88af56 100644 --- a/tests/acceptance/features/lib/Oauth2AdminSettingsPage.php +++ b/tests/acceptance/features/lib/Oauth2AdminSettingsPage.php @@ -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) { @@ -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) { diff --git a/tests/acceptance/features/lib/Oauth2AuthRequestPage.php b/tests/acceptance/features/lib/Oauth2AuthRequestPage.php index cbcc8e1..770bc00 100644 --- a/tests/acceptance/features/lib/Oauth2AuthRequestPage.php +++ b/tests/acceptance/features/lib/Oauth2AuthRequestPage.php @@ -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__ . @@ -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__ . @@ -78,12 +78,12 @@ 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__ . @@ -91,7 +91,7 @@ public function getErrorMessageHeading() { "could not find heading of error message" ); } - + return $errorMessageHeadingElement->getText(); } @@ -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) { @@ -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" diff --git a/tests/acceptance/features/lib/Oauth2OnPersonalSecuritySettingsPage.php b/tests/acceptance/features/lib/Oauth2OnPersonalSecuritySettingsPage.php index 2df319f..1d7ad90 100644 --- a/tests/acceptance/features/lib/Oauth2OnPersonalSecuritySettingsPage.php +++ b/tests/acceptance/features/lib/Oauth2OnPersonalSecuritySettingsPage.php @@ -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) { diff --git a/vendor-bin/behat/composer.json b/vendor-bin/behat/composer.json index b458d0c..f90c60e 100644 --- a/vendor-bin/behat/composer.json +++ b/vendor-bin/behat/composer.json @@ -5,10 +5,10 @@ } }, "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", @@ -16,7 +16,7 @@ "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" } }