saufen/tests/TestCase.php
2025-05-31 21:43:13 +02:00

35 lines
951 B
PHP

<?php
declare(strict_types=1);
namespace Tests;
use App\Settings;
use DI\Bridge\Slim\Bridge;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psr\Container\ContainerInterface;
use Slim\App;
abstract class TestCase extends BaseTestCase
{
public ContainerInterface $container;
public App $app;
public function setUp(): void
{
$this->container = (require __DIR__ . '/../config/container.php')(new Settings(true));
$this->app = Bridge::create($this->container);
}
public function setUpDB(): void
{
$entityManager = $this->container->get(EntityManagerInterface::class);
// Create schema from entities
$metadata = $entityManager->getMetadataFactory()->getAllMetadata();
$tool = new SchemaTool($entityManager);
$tool->dropSchema($metadata);
$tool->createSchema($metadata);
}
}