DatabaseTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 2
b 0
f 0
dl 0
loc 25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setEntityManager() 0 3 1
A tearDown() 0 9 2
A getEntityManager() 0 3 1
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