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( |
|
|
|
|
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
|
|
|
|