diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index b04fd121..c2fc4820 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -39,6 +39,7 @@ use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter; use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken; @@ -1080,7 +1081,10 @@ public function seeAuthentication(): void $this->fail('There is no user in session'); } - $this->assertTrue($security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is no authenticated user'); + $this->assertTrue( + $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_FULLY), + 'There is no authenticated user' + ); } /** @@ -1133,7 +1137,14 @@ public function seeRememberedAuthentication(): void $this->fail('There is no user in session'); } - $this->assertTrue($security->isGranted('IS_AUTHENTICATED_REMEMBERED'), 'There is no authenticated user'); + $hasRememberMeCookie = $this->client->getCookieJar()->get('REMEMBERME'); + $hasRememberMeRole = $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); + + $isRemembered = $hasRememberMeCookie && $hasRememberMeRole; + $this->assertTrue( + $isRemembered, + 'User does not have remembered authentication' + ); } /** @@ -1149,9 +1160,13 @@ public function dontSeeRememberedAuthentication(): void /** @var Security $security */ $security = $this->grabService('security.helper'); + $hasRememberMeCookie = $this->client->getCookieJar()->get('REMEMBERME'); + $hasRememberMeRole = $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED); + + $isRemembered = $hasRememberMeCookie && $hasRememberMeRole; $this->assertFalse( - $security->isGranted('IS_AUTHENTICATED_REMEMBERED'), - 'There is an user authenticated' + $isRemembered, + 'User does have remembered authentication' ); } @@ -1200,7 +1215,7 @@ public function dontSeeAuthentication(): void $security = $this->grabService('security.helper'); $this->assertFalse( - $security->isGranted('IS_AUTHENTICATED_FULLY'), + $security->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_FULLY), 'There is an user authenticated' ); }