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