From 8535ef908228fb308967c14bc9abe5912567f281 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 8 Jan 2023 23:10:57 +0100 Subject: [PATCH] refactor(test): apply php-cs-fixer add select user by email --- tests/Core/Auth/LoginTest.php | 28 ++++++++++++++++++++++++--- tests/Core/Command/CreateUserTest.php | 10 +++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/Core/Auth/LoginTest.php b/tests/Core/Auth/LoginTest.php index 8cf820f..2b8c96e 100644 --- a/tests/Core/Auth/LoginTest.php +++ b/tests/Core/Auth/LoginTest.php @@ -2,17 +2,39 @@ namespace App\Tests\Core\Auth; +use App\Repository\UserRepositoryQuery; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +/** + * @internal + * @coversNothing + */ class LoginTest extends WebTestCase { + protected UserRepositoryQuery $query; + protected KernelBrowser $client; + + protected function setUp(): void + { + $this->client = static::createClient(); + $this->query = self::$container->get(UserRepositoryQuery::class); + } + public function testLoginRedirect(): void { - $client = static::createClient(); - $crawler = $client->request('GET', '/admin'); + $crawler = $this->client->request('GET', '/admin'); $this->assertResponseStatusCodeSame(302); - $client->followRedirect(); + $this->client->followRedirect(); $this->assertResponseIsSuccessful(); } + + public function testLoginUser(): void + { + $user = $this->query->create()->andWhere('.email=\'admin@localhost\'')->findOne(); + $this->client->loginUser($user); + $this->client->request('GET', '/admin/account/'); + $this->assertResponseStatusCodeSame(200); + } } diff --git a/tests/Core/Command/CreateUserTest.php b/tests/Core/Command/CreateUserTest.php index 306f120..63af056 100644 --- a/tests/Core/Command/CreateUserTest.php +++ b/tests/Core/Command/CreateUserTest.php @@ -2,11 +2,15 @@ namespace App\Tests\Core\Command; +use App\Repository\UserRepositoryQuery; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; -use App\Repository\UserRepositoryQuery; +/** + * @internal + * @coversNothing + */ class CreateUserTest extends KernelTestCase { protected UserRepositoryQuery $query; @@ -31,7 +35,7 @@ class CreateUserTest extends KernelTestCase 'y', 'n', ]); - $commandTester->execute(['command' => $command->getName()]); + $commandTester->execute(['command' => $command->getName()]); $output = $commandTester->getDisplay(); $this->assertStringContainsString('User created!', $output); @@ -41,7 +45,7 @@ class CreateUserTest extends KernelTestCase 'n', 'y', ]); - $commandTester->execute(['command' => $command->getName()]); + $commandTester->execute(['command' => $command->getName()]); $output = $commandTester->getDisplay(); $this->assertStringContainsString('User created!', $output); }