<?php
declare(strict_types=1);
namespace Tests\Adawolfa\Fucktura;
use PHPUnit;
use Doctrine\ORM;
abstract class TestCase extends PHPUnit\Framework\TestCase
{
private ?ORM\EntityManager $em = null;
private ?EntityFactory $ef = null;
private function createEntityManager(): ORM\EntityManager
{
$configuration = ORM\Tools\Setup::createConfiguration(isDevMode: true);
$configuration->setMetadataDriverImpl(new ORM\Mapping\Driver\AttributeDriver([__DIR__ . '/../src']));
$em = ORM\EntityManager::create(
connection: [
'driver' => 'pdo_sqlite',
'memory' => true,
],
config: $configuration,
);
$schemaTool = new ORM\Tools\SchemaTool($em);
$schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
return $em;
}
protected function getEntityManager(): ORM\EntityManager
{
$this->em ??= $this->createEntityManager();
return $this->em;
}
protected function getEntityFactory(): EntityFactory
{
$this->ef ??= new EntityFactory($this->getEntityManager());
return $this->ef;
}
}