From 588a96abbd6489d52e533fd9808f77d7bf721fdb Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Sat, 29 May 2021 16:40:38 -0500 Subject: [PATCH] Added logout by path --- .../Module/Symfony/SessionAssertionsTrait.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Module/Symfony/SessionAssertionsTrait.php b/src/Codeception/Module/Symfony/SessionAssertionsTrait.php index 92a60fe8..f9e00478 100644 --- a/src/Codeception/Module/Symfony/SessionAssertionsTrait.php +++ b/src/Codeception/Module/Symfony/SessionAssertionsTrait.php @@ -10,6 +10,7 @@ use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken; +use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; use function is_int; use function serialize; @@ -81,7 +82,20 @@ public function dontSeeInSession(string $attribute, $value = null): void } /** - * Invalidate the current session. + * Go to the configured logout url (by default: `/logout`). + * This method includes redirection to the destination page configured after logout. + * + * See the Symfony documentation on ['Logging Out'](https://symfony.com/doc/current/security.html#logging-out). + */ + public function goToLogoutPath(): void + { + $logoutUrlGenerator = $this->getLogoutUrlGenerator(); + $logoutPath = $logoutUrlGenerator->getLogoutPath(); + $this->amOnPage($logoutPath); + } + + /** + * Alias method for [`logoutProgrammatically()`](https://codeception.com/docs/modules/Symfony#logoutProgrammatically) * * ```php * logoutProgrammatically(); + } + + /** + * Invalidates the current user's session and expires the session cookies. + * This method does not include any redirects after logging out. + * + * ```php + * logoutProgrammatically(); + * ``` + */ + public function logoutProgrammatically(): void { if ($tokenStorage = $this->getTokenStorage()) { $tokenStorage->setToken(); @@ -164,6 +192,11 @@ protected function getTokenStorage(): ?TokenStorageInterface return $this->getService('security.token_storage'); } + protected function getLogoutUrlGenerator(): ?LogoutUrlGenerator + { + return $this->getService('security.logout_url_generator'); + } + protected function grabSessionService(): SessionInterface { return $this->grabService('session');