2024-06-14 15:41:00 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Tests;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
|
|
use Override;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
abstract class DbWebTest extends WebTestCase
|
|
|
|
{
|
|
|
|
abstract public function getEntityClass(): string;
|
|
|
|
|
|
|
|
protected KernelBrowser $client;
|
|
|
|
protected EntityManagerInterface $manager;
|
|
|
|
protected EntityRepository $repository;
|
|
|
|
|
|
|
|
#[Override]
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->client = static::createClient();
|
|
|
|
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
2024-06-14 18:21:16 +00:00
|
|
|
$schemaTool = new SchemaTool($this->manager);
|
|
|
|
$metadata = $this->manager->getMetadataFactory()
|
|
|
|
->getAllMetadata();
|
2024-06-27 14:57:15 +00:00
|
|
|
$schemaTool->dropDatabase();
|
2024-06-14 18:21:16 +00:00
|
|
|
$schemaTool->updateSchema($metadata);
|
2024-06-14 15:41:00 +00:00
|
|
|
$this->repository = $this->manager->getRepository($this->getEntityClass());
|
|
|
|
}
|
|
|
|
}
|