Skip to content

Commit 09921b3

Browse files
committed
Added amLoggedInWithToken assertion
1 parent 1526b70 commit 09921b3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

composer.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Functional/SessionCest.php

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\User;
88
use App\Tests\Support\FunctionalTester;
99
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
10+
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
1011

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

28+
public function amLoggedInWithToken(FunctionalTester $I)
29+
{
30+
$user = $I->grabEntityFromRepository(User::class, [
31+
'email' => '[email protected]'
32+
]);
33+
$token = new PostAuthenticationToken($user, 'main', $user->getRoles());
34+
$I->amLoggedInWithToken($token);
35+
$I->amOnPage('/dashboard');
36+
$I->seeAuthentication();
37+
/** @var TokenStorageInterface $tokenStorage */
38+
$tokenStorage = $I->grabService('security.token_storage');
39+
$I->assertNotNull($tokenStorage->getToken());
40+
$I->see('You are in the Dashboard!');
41+
}
42+
2743
public function dontSeeInSession(FunctionalTester $I)
2844
{
2945
$I->amOnPage('/');

0 commit comments

Comments
 (0)