Passed
Pull Request — master (#339)
by Alejandro
06:16
created

DatabaseTestCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 9 2
A getEntityManager() 0 3 1
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
    public static $em;
15
16
    protected function getEntityManager(): EntityManagerInterface
17
    {
18
        return static::$em;
19
    }
20
21
    public function tearDown()
22
    {
23
        foreach (static::ENTITIES_TO_EMPTY as $entityClass) {
24
            $qb = $this->getEntityManager()->createQueryBuilder();
25
            $qb->delete($entityClass, 'x');
26
            $qb->getQuery()->execute();
27
        }
28
29
        $this->getEntityManager()->clear();
30
    }
31
}
32