Skip to content

Added logout by path #134

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

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Codeception/Module/Symfony/SessionAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -81,14 +82,41 @@ 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
* <?php
* $I->logout();
* ```
*/
public function logout(): void
{
$this->logoutProgrammatically();
}

/**
* Invalidates the current user's session and expires the session cookies.
* This method does not include any redirects after logging out.
*
* ```php
* <?php
* $I->logoutProgrammatically();
* ```
*/
public function logoutProgrammatically(): void
{
if ($tokenStorage = $this->getTokenStorage()) {
$tokenStorage->setToken();
Expand Down Expand Up @@ -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 getCurrentSession(): SessionInterface
{
return $this->grabService('session');
Expand Down