Completed
Pull Request — master (#339)
by Alejandro
18:21 queued 08:22
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
    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