12245759ac
CI / test (push) Has been cancelled
Web app: new entities (Image, RenderedAsset, SharedImage, Token, DeviceImageHistory), enums, repositories, controllers, message handlers, migrations, tests, frontend upload/library/sticker UI, Vue components. Firmware: EPD background screen binaries + gen scripts, setup_bg header. Infra: ddev config, test bundle, gitignore coverage dir. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Functional;
|
|
|
|
use App\Entity\User;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
|
|
abstract class AppWebTestCase extends WebTestCase
|
|
{
|
|
protected KernelBrowser $client;
|
|
|
|
private ?EntityManagerInterface $em = null;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
// Create the client first — this boots the kernel and makes getContainer() available.
|
|
$this->client = static::createClient();
|
|
$this->em = null;
|
|
}
|
|
|
|
protected function em(): EntityManagerInterface
|
|
{
|
|
if ($this->em === null) {
|
|
$this->em = static::getContainer()->get(EntityManagerInterface::class);
|
|
}
|
|
return $this->em;
|
|
}
|
|
|
|
protected function createUser(string $email, string $password = 'password'): User
|
|
{
|
|
$hasher = static::getContainer()->get(UserPasswordHasherInterface::class);
|
|
|
|
$user = new User();
|
|
$user->setEmail($email);
|
|
$user->setPassword($hasher->hashPassword($user, $password));
|
|
|
|
$this->em()->persist($user);
|
|
$this->em()->flush();
|
|
|
|
return $user;
|
|
}
|
|
|
|
protected function loginAs(User $user): KernelBrowser
|
|
{
|
|
$this->client->loginUser($user);
|
|
return $this->client;
|
|
}
|
|
}
|