for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\TestUtils\DbTest;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
abstract class DatabaseTestCase extends TestCase
{
protected const ENTITIES_TO_EMPTY = [];
private static EntityManagerInterface $em;
public static function setEntityManager(EntityManagerInterface $em): void
self::$em = $em;
}
protected function getEntityManager(): EntityManagerInterface
return self::$em;
public function tearDown(): void
foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->delete($entityClass, 'x');
$qb->getQuery()->execute();
$this->getEntityManager()->clear();