shlink/module/Common/test-db/DbTest/DatabaseTestCase.php

37 lines
846 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\DbTest;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
abstract class DatabaseTestCase extends TestCase
{
protected const ENTITIES_TO_EMPTY = [];
/** @var EntityManagerInterface */
2019-01-27 12:30:38 +03:00
private static $em;
public static function setEntityManager(EntityManagerInterface $em): void
{
self::$em = $em;
}
protected function getEntityManager(): EntityManagerInterface
{
2019-01-27 12:30:38 +03:00
return self::$em;
}
public function tearDown()
{
foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->delete($entityClass, 'x');
$qb->getQuery()->execute();
}
$this->getEntityManager()->clear();
}
}