2017-10-22 19:03:35 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Common\DbUnit;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
|
|
|
}
|
|
|
|
}
|