DatabaseTestCase::tearDown()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\TestUtils\DbTest;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use PHPUnit\Framework\TestCase;
9
10
abstract class DatabaseTestCase extends TestCase
11
{
12
    protected const ENTITIES_TO_EMPTY = [];
13
14
    private static EntityManagerInterface $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