Skip to content

Commit

Permalink
Added amLoggedInWithToken assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez committed May 2, 2024
1 parent aeaf521 commit 26ec99c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/Functional/SessionCest.php
Expand Up @@ -7,6 +7,7 @@
use App\Entity\User;
use App\Tests\Support\FunctionalTester;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;

final class SessionCest
{
Expand All @@ -24,6 +25,21 @@ public function amLoggedInAs(FunctionalTester $I)
$I->see('You are in the Dashboard!');
}

public function amLoggedInWithToken(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com'
]);
$token = new PostAuthenticationToken($user, 'main', $user->getRoles());
$I->amLoggedInWithToken($token);
$I->amOnPage('/dashboard');
$I->seeAuthentication();
/** @var TokenStorageInterface $tokenStorage */
$tokenStorage = $I->grabService('security.token_storage');
$I->assertNotNull($tokenStorage->getToken());
$I->see('You are in the Dashboard!');
}

public function dontSeeInSession(FunctionalTester $I)
{
$I->amOnPage('/');
Expand Down

0 comments on commit 26ec99c

Please sign in to comment.