Passed
Pull Request — master (#339)
by Alejandro
05:38
created

DatabaseTestCase::getEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\DbTest;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use PHPUnit\Framework\TestCase;
8
9
abstract class DatabaseTestCase extends TestCase
10
{
11
    protected const ENTITIES_TO_EMPTY = [];
12
13
    /** @var EntityManagerInterface */
14
    private static $em;
15
16
    public static function setEntityManager(EntityManagerInterface $em): void
17
    {
18
        self::$em = $em;
19
    }
20
21
    protected function getEntityManager(): EntityManagerInterface
22
    {
23
        return self::$em;
24
    }
25
26
    public function tearDown()
27
    {
28
        foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
29
            $qb = $this->getEntityManager()->createQueryBuilder();
30
            $qb->delete($entityClass, 'x');
31
            $qb->getQuery()->execute();
32
        }
33
34
        $this->getEntityManager()->clear();
35
    }
36
}
37