From 26ec99c43371fe325af9272ab3c7a5db2fd38141 Mon Sep 17 00:00:00 2001 From: Gustavo Nieves Date: Thu, 2 May 2024 10:41:57 -0500 Subject: [PATCH] Added amLoggedInWithToken assertion --- composer.lock | 8 ++++---- tests/Functional/SessionCest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index e86033e..59f8627 100644 --- a/composer.lock +++ b/composer.lock @@ -5348,12 +5348,12 @@ "source": { "type": "git", "url": "https://github.com/Codeception/module-symfony.git", - "reference": "e02ff5a4d0dde327aa3caf5e1e2e28fa075871cd" + "reference": "5ef40f667c0db8d5ffc6895c7053756e30a851b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/module-symfony/zipball/e02ff5a4d0dde327aa3caf5e1e2e28fa075871cd", - "reference": "e02ff5a4d0dde327aa3caf5e1e2e28fa075871cd", + "url": "https://api.github.com/repos/Codeception/module-symfony/zipball/5ef40f667c0db8d5ffc6895c7053756e30a851b0", + "reference": "5ef40f667c0db8d5ffc6895c7053756e30a851b0", "shasum": "" }, "require": { @@ -5427,7 +5427,7 @@ "issues": "https://github.com/Codeception/module-symfony/issues", "source": "https://github.com/Codeception/module-symfony/tree/main" }, - "time": "2024-04-17T18:09:08+00:00" + "time": "2024-05-02T14:12:23+00:00" }, { "name": "codeception/stub", diff --git a/tests/Functional/SessionCest.php b/tests/Functional/SessionCest.php index 16b0f09..b29f751 100644 --- a/tests/Functional/SessionCest.php +++ b/tests/Functional/SessionCest.php @@ -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 { @@ -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('/');