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