Completed
Pull Request — master (#457)
by Alejandro
06:50
created

DatabaseTestCase::getEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\TestUtils\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(): void
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