1 | <?php |
||
33 | abstract class DoctrineOrmTestCase extends \PHPUnit\Framework\TestCase |
||
34 | { |
||
35 | /** |
||
36 | * @var EntityManager |
||
37 | */ |
||
38 | protected $em; |
||
39 | |||
40 | /** |
||
41 | * EntityManager mock object together with |
||
42 | * annotation mapping driver and pdo_sqlite |
||
43 | * database in memory. |
||
44 | * |
||
45 | * @param EventManager $evm |
||
46 | * @param Configuration $config |
||
47 | * |
||
48 | * @return EntityManager |
||
49 | */ |
||
50 | final protected function getMockSqliteEntityManager(?EventManager $evm = null, ?Configuration $config = null) |
||
51 | { |
||
52 | $conn = [ |
||
53 | 'driver' => 'pdo_sqlite', |
||
54 | 'memory' => true, |
||
55 | ]; |
||
56 | |||
57 | $em = EntityManager::create($conn, $config ?: $this->getMockAnnotatedConfig(), $evm ?: new EventManager()); |
||
58 | |||
59 | $schema = array_map(static function ($class) use ($em) { |
||
60 | return $em->getClassMetadata($class); |
||
61 | }, (array) $this->getUsedEntityFixtures()); |
||
62 | |||
63 | $schemaTool = new SchemaTool($em); |
||
64 | $schemaTool->dropSchema([]); |
||
65 | $schemaTool->createSchema($schema); |
||
66 | |||
67 | return $this->em = $em; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Creates default mapping driver. |
||
72 | * |
||
73 | * @return AnnotationDriver |
||
74 | */ |
||
75 | final protected function getMetadataDriverImplementation() |
||
76 | { |
||
77 | return new AnnotationDriver(new AnnotationReader()); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Get a list of used fixture classes. |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | abstract protected function getUsedEntityFixtures(); |
||
86 | |||
87 | /** |
||
88 | * Get annotation mapping configuration. |
||
89 | * |
||
90 | * @return Configuration |
||
91 | */ |
||
92 | final protected function getMockAnnotatedConfig() |
||
101 | } |
||
102 |