Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,15 @@ $I->haveHttpHeader('Client_Id', 'Codeception');
Invalidate previously cached routes.


### logout

Invalidate the current session.
```php
<?php
$I->logout();
```


### makeHtmlSnapshot

Saves current page's HTML into a temprary file.
Expand Down
38 changes: 38 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,42 @@ private function getPossibleKernelClasses()

return [$this->config['kernel_class']];
}

/**
* Invalidate the current session.
* ```php
* <?php
* $I->logout();
* ```
*/
public function logout()
{
$container = $this->_getContainer();

if ($container->has('security.token_storage')) {
$tokenStorage = $this->grabService('security.token_storage');
$tokenStorage->setToken(null);
}

if (!$container->has('session')) {
$this->fail("Symfony container doesn't have 'session' service");
return;
}
$session = $this->grabService('session');

$sessionName = $session->getName();
$session->invalidate();

$cookieJar = $this->client->getCookieJar();
foreach ($cookieJar->all() as $cookie) {
$cookieName = $cookie->getName();
if ($cookieName === 'MOCKSESSID' ||
$cookieName === 'REMEMBERME' ||
$cookieName === $sessionName
) {
$cookieJar->expire($cookieName);
}
}
$cookieJar->flushExpiredCookies();
}
}