diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index c228fe78..388a2e60 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -979,17 +979,13 @@ public function amOnAction(string $action, array $params = []) /** * Checks that a user is authenticated. - * You can check users logged in with the option 'remember me' passing true as parameter. * * ```php * seeAuthentication(); - * $I->seeAuthentication(true); * ``` - * - * @param bool $remembered */ - public function seeAuthentication(bool $remembered = false) + public function seeAuthentication() { $security = $this->grabService('security.helper'); @@ -999,9 +995,7 @@ public function seeAuthentication(bool $remembered = false) $this->fail('There is no user in session'); } - $role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY'; - - $this->assertTrue($security->isGranted($role), 'There is no authenticated user'); + $this->assertTrue($security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is no authenticated user'); } /** @@ -1035,6 +1029,45 @@ public function submitSymfonyForm(string $name, array $fields) $this->submitForm($selector, $params, $button); } + /** + * Checks that a user is authenticated with the 'remember me' option. + * + * ```php + * seeRememberedAuthentication(); + * ``` + */ + public function seeRememberedAuthentication() + { + $security = $this->grabService('security.helper'); + + $user = $security->getUser(); + + if (!$user) { + $this->fail('There is no user in session'); + } + + $this->assertTrue($security->isGranted('IS_AUTHENTICATED_REMEMBERED'), 'There is no authenticated user'); + } + + /** + * Check that user is not authenticated with the 'remember me' option. + * + * ```php + * dontSeeRememberedAuthentication(); + * ``` + */ + public function dontSeeRememberedAuthentication() + { + $security = $this->grabService('security.helper'); + + $this->assertFalse( + $security->isGranted('IS_AUTHENTICATED_REMEMBERED'), + 'There is an user authenticated' + ); + } + /** * Check that the current user has a role * @@ -1067,23 +1100,18 @@ public function seeUserHasRole(string $role) /** * Check that user is not authenticated. - * You can specify whether users logged in with the 'remember me' option should be ignored by passing 'false' as a parameter. * * ```php * dontSeeAuthentication(); * ``` - * - * @param bool $remembered */ - public function dontSeeAuthentication(bool $remembered = true) + public function dontSeeAuthentication() { $security = $this->grabService('security.helper'); - $role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY'; - $this->assertFalse( - $security->isGranted($role), + $security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is an user authenticated' ); }