1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Fidry\AliceBundleExtension package. |
5
|
|
|
* |
6
|
|
|
* (c) Théo FIDRY <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Fidry\AliceBundleExtension\Context\Doctrine; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
15
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
16
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Context to load fixtures files with Alice loader. |
20
|
|
|
* |
21
|
|
|
* @author Théo FIDRY <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class AliceORMContext extends AbstractAliceContext |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function createSchema() |
29
|
|
|
{ |
30
|
|
|
$this->getSchemaTool()->createSchema($this->getAllMetadatas()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function dropSchema() |
37
|
|
|
{ |
38
|
|
|
$this->getSchemaTool()->dropSchema($this->getAllMetadatas()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function emptyDatabase() |
45
|
|
|
{ |
46
|
|
|
$this->dropSchema(); |
47
|
|
|
$this->createSchema(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
protected function getPersister() |
54
|
|
|
{ |
55
|
|
|
return $this->resolvePersister($this->getEntityManager()); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
protected function getFixturesFinder() |
62
|
|
|
{ |
63
|
|
|
return $this->kernel->getContainer()->get('hautelook_alice.doctrine.orm.fixtures_finder'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return SchemaTool |
68
|
|
|
*/ |
69
|
|
|
private function getSchemaTool() |
70
|
|
|
{ |
71
|
|
|
return new SchemaTool($this->getEntityManager()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return ClassMetadata[] |
76
|
|
|
*/ |
77
|
|
|
private function getAllMetadatas() |
78
|
|
|
{ |
79
|
|
|
return $this->getEntityManager()->getMetadataFactory()->getAllMetadata(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return EntityManagerInterface |
84
|
|
|
*/ |
85
|
|
|
private function getEntityManager() |
86
|
|
|
{ |
87
|
|
|
return $this->kernel->getContainer()->get('doctrine.orm.entity_manager'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: