1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Doctrine\Tests; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\Doctrine\ApiEntityManager; |
6
|
|
|
use Bankiru\Api\Doctrine\ApiFactory\ApiFactoryRegistryFactory; |
7
|
|
|
use Bankiru\Api\Doctrine\ApiFactory\ChainApiFactoryRegistry; |
8
|
|
|
use Bankiru\Api\Doctrine\ApiFactory\StaticApiFactoryFactory; |
9
|
|
|
use Bankiru\Api\Doctrine\ApiFactoryRegistryInterface; |
10
|
|
|
use Bankiru\Api\Doctrine\ClientRegistry; |
11
|
|
|
use Bankiru\Api\Doctrine\ClientRegistryInterface; |
12
|
|
|
use Bankiru\Api\Doctrine\Configuration; |
13
|
|
|
use Bankiru\Api\Doctrine\EntityManager; |
14
|
|
|
use Bankiru\Api\Doctrine\EntityMetadataFactory; |
15
|
|
|
use Bankiru\Api\Doctrine\Mapping\Driver\YmlMetadataDriver; |
16
|
|
|
use Bankiru\Api\Doctrine\Test\TestApiFactory; |
17
|
|
|
use Bankiru\Api\Doctrine\Type\BaseTypeRegistry; |
18
|
|
|
use Bankiru\Api\Doctrine\Type\TypeRegistry; |
19
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; |
20
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; |
21
|
|
|
use ScayTrase\Api\Rpc\Test\RpcMockClient; |
22
|
|
|
use ScayTrase\Api\Rpc\Tests\AbstractRpcTest; |
23
|
|
|
|
24
|
|
|
abstract class AbstractEntityManagerTest extends AbstractRpcTest |
25
|
|
|
{ |
26
|
|
|
const DEFAULT_CLIENT = 'test-client'; |
27
|
|
|
/** @var ClientRegistryInterface */ |
28
|
|
|
private $clientRegistry; |
29
|
|
|
/** @var ApiEntityManager */ |
30
|
|
|
private $manager; |
31
|
|
|
/** @var RpcMockClient[] */ |
32
|
|
|
private $clients = []; |
33
|
|
|
/** @var ApiFactoryRegistryInterface */ |
34
|
|
|
private $factoryRegistry; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function getClientRegistry() |
40
|
|
|
{ |
41
|
|
|
return $this->clientRegistry; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ApiEntityManager |
46
|
|
|
*/ |
47
|
|
|
protected function getManager() |
48
|
|
|
{ |
49
|
|
|
return $this->manager; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function setUp() |
53
|
|
|
{ |
54
|
|
|
$this->createEntityManager($this->getClientNames()); |
55
|
|
|
parent::setUp(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function createEntityManager($clients = [self::DEFAULT_CLIENT]) |
59
|
|
|
{ |
60
|
|
|
$this->clientRegistry = new ClientRegistry(); |
61
|
|
|
foreach ($clients as $name) { |
62
|
|
|
$this->clientRegistry->add($name, $this->getClient($name)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->factoryRegistry = new ChainApiFactoryRegistry(); |
66
|
|
|
|
67
|
|
|
$factory = new ApiFactoryRegistryFactory(); |
68
|
|
|
foreach ($this->getFactoryApis() as $name => $api) { |
69
|
|
|
$factory->set($name, $api); |
70
|
|
|
} |
71
|
|
|
$this->factoryRegistry->add($factory); |
72
|
|
|
$this->factoryRegistry->add(new StaticApiFactoryFactory()); |
73
|
|
|
|
74
|
|
|
$configuration = $this->createConfiguration(); |
75
|
|
|
|
76
|
|
|
$this->manager = new EntityManager($configuration); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $name |
81
|
|
|
* |
82
|
|
|
* @return RpcMockClient |
83
|
|
|
*/ |
84
|
|
|
protected function getClient($name = self::DEFAULT_CLIENT) |
85
|
|
|
{ |
86
|
|
|
if (!array_key_exists($name, $this->clients)) { |
87
|
|
|
$this->clients[$name] = new RpcMockClient(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->clients[$name]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
protected function getClientNames() |
94
|
|
|
{ |
95
|
|
|
return [self::DEFAULT_CLIENT]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function tearDown() |
99
|
|
|
{ |
100
|
|
|
foreach ($this->clients as $name => $client) { |
101
|
|
|
self::assertCount(0, $client, sprintf('Response not used for "%s" client', $name)); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$this->manager = null; |
105
|
|
|
$this->clients = []; |
106
|
|
|
parent::tearDown(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return Configuration |
111
|
|
|
*/ |
112
|
|
|
protected function createConfiguration() |
113
|
|
|
{ |
114
|
|
|
$configuration = new Configuration(); |
115
|
|
|
$configuration->setMetadataFactory(new EntityMetadataFactory()); |
|
|
|
|
116
|
|
|
$configuration->setClientRegistry($this->clientRegistry); |
117
|
|
|
$configuration->setTypeRegistry(new BaseTypeRegistry(new TypeRegistry())); |
118
|
|
|
$configuration->setFactoryRegistry($this->factoryRegistry); |
119
|
|
|
$configuration->setProxyDir(CACHE_DIR.'/doctrine/proxy/'); |
120
|
|
|
$configuration->setProxyNamespace('Bankiru\Api\Doctrine\Test\Proxy'); |
121
|
|
|
$driver = new MappingDriverChain(); |
122
|
|
|
$driver->addDriver( |
123
|
|
|
new YmlMetadataDriver( |
124
|
|
|
new SymfonyFileLocator( |
125
|
|
|
[ |
126
|
|
|
__DIR__.'/../Test/Resources/config/api/' => 'Bankiru\Api\Doctrine\Test\Entity', |
127
|
|
|
], |
128
|
|
|
'.api.yml', |
129
|
|
|
DIRECTORY_SEPARATOR |
130
|
|
|
) |
131
|
|
|
), |
132
|
|
|
'Bankiru\Api\Doctrine\Test\Entity' |
133
|
|
|
); |
134
|
|
|
$configuration->setDriver($driver); |
135
|
|
|
|
136
|
|
|
return $configuration; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
protected function getFactoryApis() |
140
|
|
|
{ |
141
|
|
|
return []; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
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: