2017-10-22 11:03:35 -05:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Common\DbUnit;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2018-03-26 12:09:10 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-10-22 11:03:35 -05:00
|
|
|
|
|
|
|
abstract class DatabaseTestCase extends TestCase
|
|
|
|
{
|
2018-03-26 12:09:10 -05:00
|
|
|
protected const ENTITIES_TO_EMPTY = [];
|
2017-10-22 11:03:35 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EntityManagerInterface
|
|
|
|
*/
|
|
|
|
public static $em;
|
|
|
|
|
|
|
|
protected function getEntityManager(): EntityManagerInterface
|
|
|
|
{
|
|
|
|
return static::$em;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
// Empty all entity tables defined by this test after each test
|
|
|
|
foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
|
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
|
|
|
$qb->delete($entityClass, 'x');
|
|
|
|
$qb->getQuery()->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear entity manager
|
|
|
|
$this->getEntityManager()->clear();
|
|
|
|
}
|
|
|
|
}
|