Passed
Push — feature/VSVGVQ-20 ( 9a1232...fb2a39 )
by steven
04:50
created

AbstractDoctrineRepositoryTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 32 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Common\Repositories;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Tools\SchemaTool;
9
use Doctrine\ORM\Tools\Setup;
10
use PHPUnit\Framework\TestCase;
11
12
abstract class AbstractDoctrineRepositoryTest extends TestCase
13
{
14
    /**
15
     * @var EntityManagerInterface
16
     */
17
    protected $entityManager;
18
19
    /**
20
     * @var ObjectRepository
21
     */
22
    protected $objectRepository;
23
24
    /**
25
     * @throws \Doctrine\ORM\ORMException
26
     */
27
    protected function setUp(): void
28
    {
29
        $configuration = Setup::createAnnotationMetadataConfiguration(
30
            [
31
                __DIR__ . '/../../../src/Question/Repositories/Entities',
32
                __DIR__ . '/../../../src/User/Repositories/Entities',
33
            ],
34
            true,
35
            null,
36
            null,
37
            false
38
        );
39
40
        $connection = [
41
            'driver' => 'pdo_sqlite',
42
            'memory' => true,
43
            //'path' => __DIR__.'/db.sqlite',
44
        ];
45
46
        /** @var  entityManager */
47
        $this->entityManager = EntityManager::create(
0 ignored issues
show
Bug introduced by
The property entityManager does not seem to exist on Doctrine\ORM\EntityManager.
Loading history...
48
            $connection,
49
            $configuration
50
        );
51
52
        $this->objectRepository = $this->entityManager->getRepository(
53
            $this->getRepositoryName()
54
        );
55
56
        $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
57
        $schemaTool = new SchemaTool($this->entityManager);
58
        $schemaTool->createSchema($metadata);
59
    }
60
61
    abstract protected function getRepositoryName(): string;
62
}
63