1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass; |
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass; |
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; |
8
|
|
|
use Doctrine\DBAL\Configuration; |
9
|
|
|
use Doctrine\DBAL\Schema\AbstractAsset; |
10
|
|
|
use Doctrine\ORM\EntityManager; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass; |
13
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
|
20
|
|
|
abstract class AbstractDoctrineExtensionTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
abstract protected function loadFromFile(ContainerBuilder $container, $file); |
|
|
|
|
23
|
|
|
|
24
|
|
|
public function testDbalLoadFromXmlMultipleConnections() |
25
|
|
|
{ |
26
|
|
|
$container = $this->loadContainer('dbal_service_multiple_connections'); |
27
|
|
|
|
28
|
|
|
// doctrine.dbal.mysql_connection |
29
|
|
|
$config = $container->getDefinition('doctrine.dbal.mysql_connection')->getArgument(0); |
30
|
|
|
|
31
|
|
|
$this->assertEquals('mysql_s3cr3t', $config['password']); |
32
|
|
|
$this->assertEquals('mysql_user', $config['user']); |
33
|
|
|
$this->assertEquals('mysql_db', $config['dbname']); |
34
|
|
|
$this->assertEquals('/path/to/mysqld.sock', $config['unix_socket']); |
35
|
|
|
|
36
|
|
|
// doctrine.dbal.sqlite_connection |
37
|
|
|
$config = $container->getDefinition('doctrine.dbal.sqlite_connection')->getArgument(0); |
38
|
|
|
$this->assertSame('pdo_sqlite', $config['driver']); |
39
|
|
|
$this->assertSame('sqlite_db', $config['dbname']); |
40
|
|
|
$this->assertSame('sqlite_user', $config['user']); |
41
|
|
|
$this->assertSame('sqlite_s3cr3t', $config['password']); |
42
|
|
|
$this->assertSame('/tmp/db.sqlite', $config['path']); |
43
|
|
|
$this->assertTrue($config['memory']); |
44
|
|
|
|
45
|
|
|
// doctrine.dbal.oci8_connection |
46
|
|
|
$config = $container->getDefinition('doctrine.dbal.oci_connection')->getArgument(0); |
47
|
|
|
$this->assertSame('oci8', $config['driver']); |
48
|
|
|
$this->assertSame('oracle_db', $config['dbname']); |
49
|
|
|
$this->assertSame('oracle_user', $config['user']); |
50
|
|
|
$this->assertSame('oracle_s3cr3t', $config['password']); |
51
|
|
|
$this->assertSame('oracle_service', $config['servicename']); |
52
|
|
|
$this->assertTrue($config['service']); |
53
|
|
|
$this->assertTrue($config['pooled']); |
54
|
|
|
$this->assertSame('utf8', $config['charset']); |
55
|
|
|
|
56
|
|
|
// doctrine.dbal.ibmdb2_connection |
57
|
|
|
$config = $container->getDefinition('doctrine.dbal.ibmdb2_connection')->getArgument(0); |
58
|
|
|
$this->assertSame('ibm_db2', $config['driver']); |
59
|
|
|
$this->assertSame('ibmdb2_db', $config['dbname']); |
60
|
|
|
$this->assertSame('ibmdb2_user', $config['user']); |
61
|
|
|
$this->assertSame('ibmdb2_s3cr3t', $config['password']); |
62
|
|
|
$this->assertSame('TCPIP', $config['protocol']); |
63
|
|
|
|
64
|
|
|
// doctrine.dbal.pgsql_connection |
65
|
|
|
$config = $container->getDefinition('doctrine.dbal.pgsql_connection')->getArgument(0); |
66
|
|
|
$this->assertSame('pdo_pgsql', $config['driver']); |
67
|
|
|
$this->assertSame('pgsql_schema', $config['dbname']); |
68
|
|
|
$this->assertSame('pgsql_user', $config['user']); |
69
|
|
|
$this->assertSame('pgsql_s3cr3t', $config['password']); |
70
|
|
|
$this->assertSame('pgsql_db', $config['default_dbname']); |
71
|
|
|
$this->assertSame('require', $config['sslmode']); |
72
|
|
|
$this->assertSame('postgresql-ca.pem', $config['sslrootcert']); |
73
|
|
|
$this->assertSame('postgresql-cert.pem', $config['sslcert']); |
74
|
|
|
$this->assertSame('postgresql-key.pem', $config['sslkey']); |
75
|
|
|
$this->assertSame('postgresql.crl', $config['sslcrl']); |
76
|
|
|
$this->assertSame('utf8', $config['charset']); |
77
|
|
|
|
78
|
|
|
// doctrine.dbal.sqlanywhere_connection |
79
|
|
|
$config = $container->getDefinition('doctrine.dbal.sqlanywhere_connection')->getArgument(0); |
80
|
|
|
$this->assertSame('sqlanywhere', $config['driver']); |
81
|
|
|
$this->assertSame('localhost', $config['host']); |
82
|
|
|
$this->assertSame(2683, $config['port']); |
83
|
|
|
$this->assertSame('sqlanywhere_server', $config['server']); |
84
|
|
|
$this->assertSame('sqlanywhere_db', $config['dbname']); |
85
|
|
|
$this->assertSame('sqlanywhere_user', $config['user']); |
86
|
|
|
$this->assertSame('sqlanywhere_s3cr3t', $config['password']); |
87
|
|
|
$this->assertTrue($config['persistent']); |
88
|
|
|
$this->assertSame('utf8', $config['charset']); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testDbalLoadFromXmlSingleConnections() |
92
|
|
|
{ |
93
|
|
|
$container = $this->loadContainer('dbal_service_single_connection'); |
94
|
|
|
|
95
|
|
|
// doctrine.dbal.mysql_connection |
96
|
|
|
$config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
97
|
|
|
|
98
|
|
|
$this->assertEquals('mysql_s3cr3t', $config['password']); |
99
|
|
|
$this->assertEquals('mysql_user', $config['user']); |
100
|
|
|
$this->assertEquals('mysql_db', $config['dbname']); |
101
|
|
|
$this->assertEquals('/path/to/mysqld.sock', $config['unix_socket']); |
102
|
|
|
$this->assertEquals('5.6.20', $config['serverVersion']); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testDbalLoadSingleMasterSlaveConnection() |
106
|
|
|
{ |
107
|
|
|
$container = $this->loadContainer('dbal_service_single_master_slave_connection'); |
108
|
|
|
|
109
|
|
|
// doctrine.dbal.mysql_connection |
110
|
|
|
$param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
111
|
|
|
|
112
|
|
|
$this->assertEquals('Doctrine\\DBAL\\Connections\\MasterSlaveConnection', $param['wrapperClass']); |
113
|
|
|
$this->assertTrue($param['keepSlave']); |
114
|
|
|
$this->assertEquals( |
115
|
|
|
[ |
116
|
|
|
'user' => 'mysql_user', |
117
|
|
|
'password' => 'mysql_s3cr3t', |
118
|
|
|
'port' => null, |
119
|
|
|
'dbname' => 'mysql_db', |
120
|
|
|
'host' => 'localhost', |
121
|
|
|
'unix_socket' => '/path/to/mysqld.sock', |
122
|
|
|
], |
123
|
|
|
$param['master'] |
124
|
|
|
); |
125
|
|
|
$this->assertEquals( |
126
|
|
|
[ |
127
|
|
|
'user' => 'slave_user', |
128
|
|
|
'password' => 'slave_s3cr3t', |
129
|
|
|
'port' => null, |
130
|
|
|
'dbname' => 'slave_db', |
131
|
|
|
'host' => 'localhost', |
132
|
|
|
'unix_socket' => '/path/to/mysqld_slave.sock', |
133
|
|
|
], |
134
|
|
|
$param['slaves']['slave1'] |
135
|
|
|
); |
136
|
|
|
$this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testDbalLoadPoolShardingConnection() |
140
|
|
|
{ |
141
|
|
|
$container = $this->loadContainer('dbal_service_pool_sharding_connection'); |
142
|
|
|
|
143
|
|
|
// doctrine.dbal.mysql_connection |
144
|
|
|
$param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
145
|
|
|
|
146
|
|
|
$this->assertEquals('Doctrine\\DBAL\\Sharding\\PoolingShardConnection', $param['wrapperClass']); |
147
|
|
|
$this->assertEquals(new Reference('foo.shard_choser'), $param['shardChoser']); |
148
|
|
|
$this->assertEquals( |
149
|
|
|
[ |
150
|
|
|
'user' => 'mysql_user', |
151
|
|
|
'password' => 'mysql_s3cr3t', |
152
|
|
|
'port' => null, |
153
|
|
|
'dbname' => 'mysql_db', |
154
|
|
|
'host' => 'localhost', |
155
|
|
|
'unix_socket' => '/path/to/mysqld.sock', |
156
|
|
|
], |
157
|
|
|
$param['global'] |
158
|
|
|
); |
159
|
|
|
$this->assertEquals( |
160
|
|
|
[ |
161
|
|
|
'user' => 'shard_user', |
162
|
|
|
'password' => 'shard_s3cr3t', |
163
|
|
|
'port' => null, |
164
|
|
|
'dbname' => 'shard_db', |
165
|
|
|
'host' => 'localhost', |
166
|
|
|
'unix_socket' => '/path/to/mysqld_shard.sock', |
167
|
|
|
'id' => 1, |
168
|
|
|
], |
169
|
|
|
$param['shards'][0] |
170
|
|
|
); |
171
|
|
|
$this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function testDbalLoadSavepointsForNestedTransactions() |
175
|
|
|
{ |
176
|
|
|
$container = $this->loadContainer('dbal_savepoints'); |
177
|
|
|
|
178
|
|
|
$calls = $container->getDefinition('doctrine.dbal.savepoints_connection')->getMethodCalls(); |
179
|
|
|
$this->assertCount(1, $calls); |
|
|
|
|
180
|
|
|
$this->assertEquals('setNestTransactionsWithSavepoints', $calls[0][0]); |
181
|
|
|
$this->assertTrue($calls[0][1][0]); |
182
|
|
|
|
183
|
|
|
$calls = $container->getDefinition('doctrine.dbal.nosavepoints_connection')->getMethodCalls(); |
184
|
|
|
$this->assertCount(0, $calls); |
|
|
|
|
185
|
|
|
|
186
|
|
|
$calls = $container->getDefinition('doctrine.dbal.notset_connection')->getMethodCalls(); |
187
|
|
|
$this->assertCount(0, $calls); |
|
|
|
|
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function testLoadSimpleSingleConnection() |
191
|
|
|
{ |
192
|
|
|
$container = $this->loadContainer('orm_service_simple_single_entity_manager'); |
193
|
|
|
|
194
|
|
|
$definition = $container->getDefinition('doctrine.dbal.default_connection'); |
195
|
|
|
|
196
|
|
|
$this->assertDICConstructorArguments($definition, [ |
197
|
|
|
[ |
198
|
|
|
'dbname' => 'db', |
199
|
|
|
'host' => 'localhost', |
200
|
|
|
'port' => null, |
201
|
|
|
'user' => 'root', |
202
|
|
|
'password' => null, |
203
|
|
|
'driver' => 'pdo_mysql', |
204
|
|
|
'driverOptions' => [], |
205
|
|
|
'defaultTableOptions' => [], |
206
|
|
|
], |
207
|
|
|
new Reference('doctrine.dbal.default_connection.configuration'), |
208
|
|
|
new Reference('doctrine.dbal.default_connection.event_manager'), |
209
|
|
|
[], |
210
|
|
|
]); |
211
|
|
|
|
212
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
213
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
214
|
|
|
$this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
215
|
|
|
|
216
|
|
|
$this->assertDICConstructorArguments($definition, [ |
217
|
|
|
new Reference('doctrine.dbal.default_connection'), |
218
|
|
|
new Reference('doctrine.orm.default_configuration'), |
219
|
|
|
]); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* The PDO driver doesn't require a database name to be to set when connecting to a database server |
224
|
|
|
*/ |
225
|
|
|
public function testLoadSimpleSingleConnectionWithoutDbName() |
226
|
|
|
{ |
227
|
|
|
$container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname'); |
228
|
|
|
|
229
|
|
|
/** @var Definition $definition */ |
230
|
|
|
$definition = $container->getDefinition('doctrine.dbal.default_connection'); |
231
|
|
|
|
232
|
|
|
$this->assertDICConstructorArguments($definition, [ |
233
|
|
|
[ |
234
|
|
|
'host' => 'localhost', |
235
|
|
|
'port' => null, |
236
|
|
|
'user' => 'root', |
237
|
|
|
'password' => null, |
238
|
|
|
'driver' => 'pdo_mysql', |
239
|
|
|
'driverOptions' => [], |
240
|
|
|
'defaultTableOptions' => [], |
241
|
|
|
], |
242
|
|
|
new Reference('doctrine.dbal.default_connection.configuration'), |
243
|
|
|
new Reference('doctrine.dbal.default_connection.event_manager'), |
244
|
|
|
[], |
245
|
|
|
]); |
246
|
|
|
|
247
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
248
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
249
|
|
|
$factory = $definition->getFactory(); |
250
|
|
|
|
251
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $factory[0]); |
252
|
|
|
$this->assertEquals('create', $factory[1]); |
253
|
|
|
|
254
|
|
|
$this->assertDICConstructorArguments($definition, [ |
255
|
|
|
new Reference('doctrine.dbal.default_connection'), |
256
|
|
|
new Reference('doctrine.orm.default_configuration'), |
257
|
|
|
]); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function testLoadSingleConnection() |
261
|
|
|
{ |
262
|
|
|
$container = $this->loadContainer('orm_service_single_entity_manager'); |
263
|
|
|
|
264
|
|
|
$definition = $container->getDefinition('doctrine.dbal.default_connection'); |
265
|
|
|
|
266
|
|
|
$this->assertDICConstructorArguments($definition, [ |
267
|
|
|
[ |
268
|
|
|
'host' => 'localhost', |
269
|
|
|
'driver' => 'pdo_sqlite', |
270
|
|
|
'driverOptions' => [], |
271
|
|
|
'user' => 'sqlite_user', |
272
|
|
|
'port' => null, |
273
|
|
|
'password' => 'sqlite_s3cr3t', |
274
|
|
|
'dbname' => 'sqlite_db', |
275
|
|
|
'memory' => true, |
276
|
|
|
'defaultTableOptions' => [], |
277
|
|
|
], |
278
|
|
|
new Reference('doctrine.dbal.default_connection.configuration'), |
279
|
|
|
new Reference('doctrine.dbal.default_connection.event_manager'), |
280
|
|
|
[], |
281
|
|
|
]); |
282
|
|
|
|
283
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_entity_manager'); |
284
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
285
|
|
|
$this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
286
|
|
|
|
287
|
|
|
$this->assertDICConstructorArguments($definition, [ |
288
|
|
|
new Reference('doctrine.dbal.default_connection'), |
289
|
|
|
new Reference('doctrine.orm.default_configuration'), |
290
|
|
|
]); |
291
|
|
|
|
292
|
|
|
$configDef = $container->getDefinition('doctrine.orm.default_configuration'); |
293
|
|
|
$this->assertDICDefinitionMethodCallOnce($configDef, 'setDefaultRepositoryClassName', ['Acme\Doctrine\Repository']); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function testLoadMultipleConnections() |
297
|
|
|
{ |
298
|
|
|
$container = $this->loadContainer('orm_service_multiple_entity_managers'); |
299
|
|
|
|
300
|
|
|
$definition = $container->getDefinition('doctrine.dbal.conn1_connection'); |
301
|
|
|
|
302
|
|
|
$args = $definition->getArguments(); |
303
|
|
|
$this->assertEquals('pdo_sqlite', $args[0]['driver']); |
304
|
|
|
$this->assertEquals('localhost', $args[0]['host']); |
305
|
|
|
$this->assertEquals('sqlite_user', $args[0]['user']); |
306
|
|
|
$this->assertEquals('doctrine.dbal.conn1_connection.configuration', (string) $args[1]); |
307
|
|
|
$this->assertEquals('doctrine.dbal.conn1_connection.event_manager', (string) $args[2]); |
308
|
|
|
|
309
|
|
|
$this->assertEquals('doctrine.orm.em2_entity_manager', (string) $container->getAlias('doctrine.orm.entity_manager')); |
310
|
|
|
|
311
|
|
|
$definition = $container->getDefinition('doctrine.orm.em1_entity_manager'); |
312
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
313
|
|
|
$this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
314
|
|
|
|
315
|
|
|
$arguments = $definition->getArguments(); |
316
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); |
317
|
|
|
$this->assertEquals('doctrine.dbal.conn1_connection', (string) $arguments[0]); |
318
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); |
319
|
|
|
$this->assertEquals('doctrine.orm.em1_configuration', (string) $arguments[1]); |
320
|
|
|
|
321
|
|
|
$definition = $container->getDefinition('doctrine.dbal.conn2_connection'); |
322
|
|
|
|
323
|
|
|
$args = $definition->getArguments(); |
324
|
|
|
$this->assertEquals('pdo_sqlite', $args[0]['driver']); |
325
|
|
|
$this->assertEquals('localhost', $args[0]['host']); |
326
|
|
|
$this->assertEquals('sqlite_user', $args[0]['user']); |
327
|
|
|
$this->assertEquals('doctrine.dbal.conn2_connection.configuration', (string) $args[1]); |
328
|
|
|
$this->assertEquals('doctrine.dbal.conn2_connection.event_manager', (string) $args[2]); |
329
|
|
|
|
330
|
|
|
$definition = $container->getDefinition('doctrine.orm.em2_entity_manager'); |
331
|
|
|
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); |
332
|
|
|
$this->assertEquals(['%doctrine.orm.entity_manager.class%', 'create'], $definition->getFactory()); |
333
|
|
|
|
334
|
|
|
$arguments = $definition->getArguments(); |
335
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); |
336
|
|
|
$this->assertEquals('doctrine.dbal.conn2_connection', (string) $arguments[0]); |
337
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); |
338
|
|
|
$this->assertEquals('doctrine.orm.em2_configuration', (string) $arguments[1]); |
339
|
|
|
|
340
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_metadata_cache')); |
341
|
|
|
$this->assertEquals('%doctrine_cache.xcache.class%', $definition->getClass()); |
342
|
|
|
|
343
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_query_cache')); |
344
|
|
|
$this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
345
|
|
|
|
346
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_result_cache')); |
347
|
|
|
$this->assertEquals('%doctrine_cache.array.class%', $definition->getClass()); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
public function testLoadLogging() |
351
|
|
|
{ |
352
|
|
|
$container = $this->loadContainer('dbal_logging'); |
353
|
|
|
|
354
|
|
|
$definition = $container->getDefinition('doctrine.dbal.log_connection.configuration'); |
355
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', [new Reference('doctrine.dbal.logger')]); |
356
|
|
|
|
357
|
|
|
$definition = $container->getDefinition('doctrine.dbal.profile_connection.configuration'); |
358
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', [new Reference('doctrine.dbal.logger.profiling.profile')]); |
359
|
|
|
|
360
|
|
|
$definition = $container->getDefinition('doctrine.dbal.both_connection.configuration'); |
361
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', [new Reference('doctrine.dbal.logger.chain.both')]); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
public function testEntityManagerMetadataCacheDriverConfiguration() |
365
|
|
|
{ |
366
|
|
|
$container = $this->loadContainer('orm_service_multiple_entity_managers'); |
367
|
|
|
|
368
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_metadata_cache')); |
369
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.xcache.class%'); |
370
|
|
|
|
371
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em2_metadata_cache')); |
372
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.apc.class%'); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
View Code Duplication |
public function testEntityManagerMemcacheMetadataCacheDriverConfiguration() |
|
|
|
|
376
|
|
|
{ |
377
|
|
|
$container = $this->loadContainer('orm_service_simple_single_entity_manager'); |
378
|
|
|
|
379
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); |
380
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.class%'); |
381
|
|
|
$this->assertDICDefinitionMethodCallOnce( |
382
|
|
|
$definition, |
383
|
|
|
'setMemcache', |
384
|
|
|
[new Reference('doctrine_cache.services.doctrine.orm.default_metadata_cache.connection')] |
385
|
|
|
); |
386
|
|
|
|
387
|
|
|
$definition = $container->getDefinition('doctrine_cache.services.doctrine.orm.default_metadata_cache.connection'); |
388
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.connection.class%'); |
389
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addServer', [ |
390
|
|
|
'localhost', |
391
|
|
|
'11211', |
392
|
|
|
]); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
View Code Duplication |
public function testEntityManagerRedisMetadataCacheDriverConfigurationWithDatabaseKey() |
|
|
|
|
396
|
|
|
{ |
397
|
|
|
$container = $this->loadContainer('orm_service_simple_single_entity_manager_redis'); |
398
|
|
|
|
399
|
|
|
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); |
400
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.redis.class%'); |
401
|
|
|
$this->assertDICDefinitionMethodCallOnce( |
402
|
|
|
$definition, |
403
|
|
|
'setRedis', |
404
|
|
|
[new Reference('doctrine_cache.services.doctrine.orm.default_metadata_cache_redis.connection')] |
405
|
|
|
); |
406
|
|
|
|
407
|
|
|
$definition = $container->getDefinition('doctrine_cache.services.doctrine.orm.default_metadata_cache_redis.connection'); |
408
|
|
|
$this->assertDICDefinitionClass($definition, '%doctrine_cache.redis.connection.class%'); |
409
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'connect', ['localhost', '6379']); |
410
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'select', [1]); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
public function testDependencyInjectionImportsOverrideDefaults() |
414
|
|
|
{ |
415
|
|
|
$container = $this->loadContainer('orm_imports'); |
416
|
|
|
|
417
|
|
|
$cacheDefinition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache')); |
418
|
|
|
$this->assertEquals('%doctrine_cache.apc.class%', $cacheDefinition->getClass()); |
419
|
|
|
|
420
|
|
|
$configDefinition = $container->getDefinition('doctrine.orm.default_configuration'); |
421
|
|
|
$this->assertDICDefinitionMethodCallOnce($configDefinition, 'setAutoGenerateProxyClasses', ['%doctrine.orm.auto_generate_proxy_classes%']); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function testSingleEntityManagerMultipleMappingBundleDefinitions() |
425
|
|
|
{ |
426
|
|
|
$container = $this->loadContainer('orm_single_em_bundle_mappings', ['YamlBundle', 'AnnotationsBundle', 'XmlBundle']); |
427
|
|
|
|
428
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); |
429
|
|
|
|
430
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', [ |
431
|
|
|
new Reference('doctrine.orm.default_annotation_metadata_driver'), |
432
|
|
|
'Fixtures\Bundles\AnnotationsBundle\Entity', |
433
|
|
|
]); |
434
|
|
|
|
435
|
|
|
$this->assertDICDefinitionMethodCallAt(1, $definition, 'addDriver', [ |
436
|
|
|
new Reference('doctrine.orm.default_yml_metadata_driver'), |
437
|
|
|
'Fixtures\Bundles\YamlBundle\Entity', |
438
|
|
|
]); |
439
|
|
|
|
440
|
|
|
$this->assertDICDefinitionMethodCallAt(2, $definition, 'addDriver', [ |
441
|
|
|
new Reference('doctrine.orm.default_xml_metadata_driver'), |
442
|
|
|
'Fixtures\Bundles\XmlBundle', |
443
|
|
|
]); |
444
|
|
|
|
445
|
|
|
$annDef = $container->getDefinition('doctrine.orm.default_annotation_metadata_driver'); |
446
|
|
|
$this->assertDICConstructorArguments($annDef, [ |
447
|
|
|
new Reference('doctrine.orm.metadata.annotation_reader'), |
448
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity'], |
449
|
|
|
]); |
450
|
|
|
|
451
|
|
|
$ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver'); |
452
|
|
|
$this->assertDICConstructorArguments($ymlDef, [ |
453
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'YamlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\YamlBundle\Entity'], |
454
|
|
|
]); |
455
|
|
|
|
456
|
|
|
$xmlDef = $container->getDefinition('doctrine.orm.default_xml_metadata_driver'); |
457
|
|
|
$this->assertDICConstructorArguments($xmlDef, [ |
458
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'XmlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\XmlBundle'], |
459
|
|
|
]); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
public function testMultipleEntityManagersMappingBundleDefinitions() |
463
|
|
|
{ |
464
|
|
|
$container = $this->loadContainer('orm_multiple_em_bundle_mappings', ['YamlBundle', 'AnnotationsBundle', 'XmlBundle']); |
465
|
|
|
|
466
|
|
|
$this->assertEquals(['em1' => 'doctrine.orm.em1_entity_manager', 'em2' => 'doctrine.orm.em2_entity_manager'], $container->getParameter('doctrine.entity_managers'), 'Set of the existing EntityManagers names is incorrect.'); |
467
|
|
|
$this->assertEquals('%doctrine.entity_managers%', $container->getDefinition('doctrine')->getArgument(2), 'Set of the existing EntityManagers names is incorrect.'); |
468
|
|
|
|
469
|
|
|
$def1 = $container->getDefinition('doctrine.orm.em1_metadata_driver'); |
470
|
|
|
$def2 = $container->getDefinition('doctrine.orm.em2_metadata_driver'); |
471
|
|
|
|
472
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $def1, 'addDriver', [ |
473
|
|
|
new Reference('doctrine.orm.em1_annotation_metadata_driver'), |
474
|
|
|
'Fixtures\Bundles\AnnotationsBundle\Entity', |
475
|
|
|
]); |
476
|
|
|
|
477
|
|
|
$this->assertDICDefinitionMethodCallAt(0, $def2, 'addDriver', [ |
478
|
|
|
new Reference('doctrine.orm.em2_yml_metadata_driver'), |
479
|
|
|
'Fixtures\Bundles\YamlBundle\Entity', |
480
|
|
|
]); |
481
|
|
|
|
482
|
|
|
$this->assertDICDefinitionMethodCallAt(1, $def2, 'addDriver', [ |
483
|
|
|
new Reference('doctrine.orm.em2_xml_metadata_driver'), |
484
|
|
|
'Fixtures\Bundles\XmlBundle', |
485
|
|
|
]); |
486
|
|
|
|
487
|
|
|
$annDef = $container->getDefinition('doctrine.orm.em1_annotation_metadata_driver'); |
488
|
|
|
$this->assertDICConstructorArguments($annDef, [ |
489
|
|
|
new Reference('doctrine.orm.metadata.annotation_reader'), |
490
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity'], |
491
|
|
|
]); |
492
|
|
|
|
493
|
|
|
$ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver'); |
494
|
|
|
$this->assertDICConstructorArguments($ymlDef, [ |
495
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'YamlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\YamlBundle\Entity'], |
496
|
|
|
]); |
497
|
|
|
|
498
|
|
|
$xmlDef = $container->getDefinition('doctrine.orm.em2_xml_metadata_driver'); |
499
|
|
|
$this->assertDICConstructorArguments($xmlDef, [ |
500
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'XmlBundle' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' => 'Fixtures\Bundles\XmlBundle'], |
501
|
|
|
]); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testSingleEntityManagerDefaultTableOptions() |
505
|
|
|
{ |
506
|
|
|
$container = $this->loadContainer('orm_single_em_default_table_options', ['YamlBundle', 'AnnotationsBundle', 'XmlBundle']); |
507
|
|
|
|
508
|
|
|
$param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
509
|
|
|
|
510
|
|
|
$this->assertArrayHasKey('defaultTableOptions', $param); |
511
|
|
|
|
512
|
|
|
$defaults = $param['defaultTableOptions']; |
513
|
|
|
|
514
|
|
|
$this->assertArrayHasKey('charset', $defaults); |
515
|
|
|
$this->assertArrayHasKey('collate', $defaults); |
516
|
|
|
$this->assertArrayHasKey('engine', $defaults); |
517
|
|
|
|
518
|
|
|
$this->assertEquals('utf8mb4', $defaults['charset']); |
519
|
|
|
$this->assertEquals('utf8mb4_unicode_ci', $defaults['collate']); |
520
|
|
|
$this->assertEquals('InnoDB', $defaults['engine']); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
public function testSetTypes() |
524
|
|
|
{ |
525
|
|
|
$container = $this->loadContainer('dbal_types'); |
526
|
|
|
|
527
|
|
|
$this->assertEquals( |
528
|
|
|
['test' => ['class' => TestType::class, 'commented' => true]], |
529
|
|
|
$container->getParameter('doctrine.dbal.connection_factory.types') |
530
|
|
|
); |
531
|
|
|
$this->assertEquals('%doctrine.dbal.connection_factory.types%', $container->getDefinition('doctrine.dbal.connection_factory')->getArgument(0)); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
public function testSetCustomFunctions() |
535
|
|
|
{ |
536
|
|
|
$container = $this->loadContainer('orm_functions'); |
537
|
|
|
|
538
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_configuration'); |
539
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomStringFunction', ['test_string', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction']); |
540
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomNumericFunction', ['test_numeric', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestNumericFunction']); |
541
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomDatetimeFunction', ['test_datetime', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestDatetimeFunction']); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
View Code Duplication |
public function testSetNamingStrategy() |
|
|
|
|
545
|
|
|
{ |
546
|
|
|
$container = $this->loadContainer('orm_namingstrategy'); |
547
|
|
|
|
548
|
|
|
$def1 = $container->getDefinition('doctrine.orm.em1_configuration'); |
549
|
|
|
$def2 = $container->getDefinition('doctrine.orm.em2_configuration'); |
550
|
|
|
|
551
|
|
|
$this->assertDICDefinitionMethodCallOnce($def1, 'setNamingStrategy', [0 => new Reference('doctrine.orm.naming_strategy.default')]); |
552
|
|
|
$this->assertDICDefinitionMethodCallOnce($def2, 'setNamingStrategy', [0 => new Reference('doctrine.orm.naming_strategy.underscore')]); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
View Code Duplication |
public function testSetQuoteStrategy() |
|
|
|
|
556
|
|
|
{ |
557
|
|
|
$container = $this->loadContainer('orm_quotestrategy'); |
558
|
|
|
|
559
|
|
|
$def1 = $container->getDefinition('doctrine.orm.em1_configuration'); |
560
|
|
|
$def2 = $container->getDefinition('doctrine.orm.em2_configuration'); |
561
|
|
|
|
562
|
|
|
$this->assertDICDefinitionMethodCallOnce($def1, 'setQuoteStrategy', [0 => new Reference('doctrine.orm.quote_strategy.default')]); |
563
|
|
|
$this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', [0 => new Reference('doctrine.orm.quote_strategy.ansi')]); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
public function testSecondLevelCache() |
567
|
|
|
{ |
568
|
|
|
$container = $this->loadContainer('orm_second_level_cache'); |
569
|
|
|
|
570
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_configuration')); |
571
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.cache_configuration')); |
572
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region_cache_driver')); |
573
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.regions_configuration')); |
574
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.default_cache_factory')); |
575
|
|
|
|
576
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_chain')); |
577
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_statistics')); |
578
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger1')); |
579
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger2')); |
580
|
|
|
|
581
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_entity_region')); |
582
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_service_region')); |
583
|
|
|
$this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_query_region_filelock')); |
584
|
|
|
|
585
|
|
|
$slcFactoryDef = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory'); |
586
|
|
|
$myEntityRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_entity_region'); |
587
|
|
|
$loggerChainDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_chain'); |
588
|
|
|
$loggerStatisticsDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_statistics'); |
589
|
|
|
$myQueryRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_query_region_filelock'); |
590
|
|
|
$cacheDriverDef = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_second_level_cache.region_cache_driver')); |
591
|
|
|
$configDef = $container->getDefinition('doctrine.orm.default_configuration'); |
592
|
|
|
$myEntityRegionArgs = $myEntityRegionDef->getArguments(); |
593
|
|
|
$myQueryRegionArgs = $myQueryRegionDef->getArguments(); |
594
|
|
|
$slcFactoryArgs = $slcFactoryDef->getArguments(); |
595
|
|
|
|
596
|
|
|
$this->assertDICDefinitionClass($slcFactoryDef, '%doctrine.orm.second_level_cache.default_cache_factory.class%'); |
597
|
|
|
$this->assertDICDefinitionClass($myQueryRegionDef, '%doctrine.orm.second_level_cache.filelock_region.class%'); |
598
|
|
|
$this->assertDICDefinitionClass($myEntityRegionDef, '%doctrine.orm.second_level_cache.default_region.class%'); |
599
|
|
|
$this->assertDICDefinitionClass($loggerChainDef, '%doctrine.orm.second_level_cache.logger_chain.class%'); |
600
|
|
|
$this->assertDICDefinitionClass($loggerStatisticsDef, '%doctrine.orm.second_level_cache.logger_statistics.class%'); |
601
|
|
|
$this->assertDICDefinitionClass($cacheDriverDef, '%doctrine_cache.array.class%'); |
602
|
|
|
$this->assertDICDefinitionMethodCallOnce($configDef, 'setSecondLevelCacheConfiguration'); |
603
|
|
|
$this->assertDICDefinitionMethodCallCount($slcFactoryDef, 'setRegion', [], 3); |
604
|
|
|
$this->assertDICDefinitionMethodCallCount($loggerChainDef, 'setLogger', [], 3); |
605
|
|
|
|
606
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[0]); |
607
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[1]); |
608
|
|
|
|
609
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myEntityRegionArgs[1]); |
610
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myQueryRegionArgs[0]); |
611
|
|
|
|
612
|
|
|
$this->assertEquals('my_entity_region', $myEntityRegionArgs[0]); |
613
|
|
|
$this->assertEquals('doctrine.orm.default_second_level_cache.region.my_entity_region_driver', $myEntityRegionArgs[1]); |
614
|
|
|
$this->assertEquals(600, $myEntityRegionArgs[2]); |
615
|
|
|
|
616
|
|
|
$this->assertEquals('doctrine.orm.default_second_level_cache.region.my_query_region', $myQueryRegionArgs[0]); |
617
|
|
|
$this->assertContains('/doctrine/orm/slc/filelock', $myQueryRegionArgs[1]); |
618
|
|
|
$this->assertEquals(60, $myQueryRegionArgs[2]); |
619
|
|
|
|
620
|
|
|
$this->assertEquals('doctrine.orm.default_second_level_cache.regions_configuration', $slcFactoryArgs[0]); |
621
|
|
|
$this->assertEquals('doctrine.orm.default_second_level_cache.region_cache_driver', $slcFactoryArgs[1]); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
public function testSingleEMSetCustomFunctions() |
625
|
|
|
{ |
626
|
|
|
$container = $this->loadContainer('orm_single_em_dql_functions'); |
627
|
|
|
|
628
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_configuration'); |
629
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomStringFunction', ['test_string', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction']); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
public function testAddCustomHydrationMode() |
633
|
|
|
{ |
634
|
|
|
$container = $this->loadContainer('orm_hydration_mode'); |
635
|
|
|
|
636
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_configuration'); |
637
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', ['test_hydrator', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator']); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
public function testAddFilter() |
641
|
|
|
{ |
642
|
|
|
$container = $this->loadContainer('orm_filters'); |
643
|
|
|
|
644
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_configuration'); |
645
|
|
|
$args = [ |
646
|
|
|
['soft_delete', 'Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter'], |
647
|
|
|
['myFilter', 'Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter'], |
648
|
|
|
]; |
649
|
|
|
$this->assertDICDefinitionMethodCallCount($definition, 'addFilter', $args, 2); |
650
|
|
|
|
651
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_manager_configurator'); |
652
|
|
|
$this->assertDICConstructorArguments($definition, [['soft_delete', 'myFilter'], ['myFilter' => ['myParameter' => 'myValue', 'mySecondParameter' => 'mySecondValue']]]); |
653
|
|
|
|
654
|
|
|
// Let's create the instance to check the configurator work. |
655
|
|
|
/** @var EntityManager $entityManager */ |
656
|
|
|
$entityManager = $container->get('doctrine.orm.entity_manager'); |
657
|
|
|
$this->assertCount(2, $entityManager->getFilters()->getEnabledFilters()); |
|
|
|
|
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
public function testResolveTargetEntity() |
661
|
|
|
{ |
662
|
|
|
$container = $this->loadContainer('orm_resolve_target_entity'); |
663
|
|
|
|
664
|
|
|
$definition = $container->getDefinition('doctrine.orm.listeners.resolve_target_entity'); |
665
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'addResolveTargetEntity', ['Symfony\Component\Security\Core\User\UserInterface', 'MyUserClass', []]); |
666
|
|
|
|
667
|
|
|
$this->assertEquals(['doctrine.event_subscriber' => [[]]], $definition->getTags()); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
public function testAttachEntityListeners() |
671
|
|
|
{ |
672
|
|
|
$container = $this->loadContainer('orm_attach_entity_listener'); |
673
|
|
|
|
674
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_listeners.attach_entity_listeners'); |
675
|
|
|
$methodCalls = $definition->getMethodCalls(); |
676
|
|
|
|
677
|
|
|
$this->assertDICDefinitionMethodCallCount($definition, 'addEntityListener', [], 6); |
678
|
|
|
$this->assertEquals(['doctrine.event_listener' => [ ['event' => 'loadClassMetadata'] ] ], $definition->getTags()); |
679
|
|
|
|
680
|
|
|
$this->assertEquals($methodCalls[0], [ |
681
|
|
|
'addEntityListener', |
682
|
|
|
[ |
683
|
|
|
'ExternalBundles\Entities\FooEntity', |
684
|
|
|
'MyBundles\Listeners\FooEntityListener', |
685
|
|
|
'prePersist', |
686
|
|
|
null, |
687
|
|
|
], |
688
|
|
|
]); |
689
|
|
|
|
690
|
|
|
$this->assertEquals($methodCalls[1], [ |
691
|
|
|
'addEntityListener', |
692
|
|
|
[ |
693
|
|
|
'ExternalBundles\Entities\FooEntity', |
694
|
|
|
'MyBundles\Listeners\FooEntityListener', |
695
|
|
|
'postPersist', |
696
|
|
|
'postPersist', |
697
|
|
|
], |
698
|
|
|
]); |
699
|
|
|
|
700
|
|
|
$this->assertEquals($methodCalls[2], [ |
701
|
|
|
'addEntityListener', |
702
|
|
|
[ |
703
|
|
|
'ExternalBundles\Entities\FooEntity', |
704
|
|
|
'MyBundles\Listeners\FooEntityListener', |
705
|
|
|
'postLoad', |
706
|
|
|
'postLoadHandler', |
707
|
|
|
], |
708
|
|
|
]); |
709
|
|
|
|
710
|
|
|
$this->assertEquals($methodCalls[3], [ |
711
|
|
|
'addEntityListener', |
712
|
|
|
[ |
713
|
|
|
'ExternalBundles\Entities\BarEntity', |
714
|
|
|
'MyBundles\Listeners\BarEntityListener', |
715
|
|
|
'prePersist', |
716
|
|
|
'prePersist', |
717
|
|
|
], |
718
|
|
|
]); |
719
|
|
|
|
720
|
|
|
$this->assertEquals($methodCalls[4], [ |
721
|
|
|
'addEntityListener', |
722
|
|
|
[ |
723
|
|
|
'ExternalBundles\Entities\BarEntity', |
724
|
|
|
'MyBundles\Listeners\BarEntityListener', |
725
|
|
|
'prePersist', |
726
|
|
|
'prePersistHandler', |
727
|
|
|
], |
728
|
|
|
]); |
729
|
|
|
|
730
|
|
|
$this->assertEquals($methodCalls[5], [ |
731
|
|
|
'addEntityListener', |
732
|
|
|
[ |
733
|
|
|
'ExternalBundles\Entities\BarEntity', |
734
|
|
|
'MyBundles\Listeners\LogDeleteEntityListener', |
735
|
|
|
'postDelete', |
736
|
|
|
'postDelete', |
737
|
|
|
], |
738
|
|
|
]); |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
public function testDbalAutoCommit() |
742
|
|
|
{ |
743
|
|
|
$container = $this->loadContainer('dbal_auto_commit'); |
744
|
|
|
|
745
|
|
|
$definition = $container->getDefinition('doctrine.dbal.default_connection.configuration'); |
746
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setAutoCommit', [false]); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
public function testDbalOracleConnectstring() |
750
|
|
|
{ |
751
|
|
|
$container = $this->loadContainer('dbal_oracle_connectstring'); |
752
|
|
|
|
753
|
|
|
$config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
754
|
|
|
$this->assertSame('scott@sales-server:1521/sales.us.example.com', $config['connectstring']); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
public function testDbalOracleInstancename() |
758
|
|
|
{ |
759
|
|
|
$container = $this->loadContainer('dbal_oracle_instancename'); |
760
|
|
|
|
761
|
|
|
$config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0); |
762
|
|
|
$this->assertSame('mySuperInstance', $config['instancename']); |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
public function testDbalSchemaFilter() |
766
|
|
|
{ |
767
|
|
|
if (method_exists(Configuration::class, 'setSchemaAssetsFilter')) { |
768
|
|
|
$this->markTestSkipped('Test only applies to doctrine/dbal 2.8 or lower'); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
$container = $this->loadContainer('dbal_schema_filter'); |
772
|
|
|
|
773
|
|
|
$definition = $container->getDefinition('doctrine.dbal.connection1_connection.configuration'); |
774
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setFilterSchemaAssetsExpression', ['~^(?!t_)~']); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
public function testDbalSchemaFilterNewConfig() |
778
|
|
|
{ |
779
|
|
|
if (! method_exists(Configuration::class, 'setSchemaAssetsFilter')) { |
780
|
|
|
$this->markTestSkipped('Test requires doctrine/dbal 2.9 or higher'); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
$container = $this->getContainer([]); |
784
|
|
|
$loader = new DoctrineExtension(); |
785
|
|
|
$container->registerExtension($loader); |
786
|
|
|
$container->addCompilerPass(new DbalSchemaFilterPass()); |
787
|
|
|
|
788
|
|
|
// ignore table1 table on "default" connection |
789
|
|
|
$container->register('dummy_filter1', DummySchemaAssetsFilter::class) |
790
|
|
|
->setArguments(['table1']) |
791
|
|
|
->addTag('doctrine.dbal.schema_filter'); |
792
|
|
|
|
793
|
|
|
// ignore table2 table on "connection2" connection |
794
|
|
|
$container->register('dummy_filter2', DummySchemaAssetsFilter::class) |
795
|
|
|
->setArguments(['table2']) |
796
|
|
|
->addTag('doctrine.dbal.schema_filter', ['connection' => 'connection2']); |
797
|
|
|
|
798
|
|
|
$this->loadFromFile($container, 'dbal_schema_filter'); |
799
|
|
|
|
800
|
|
|
$assetNames = ['table1', 'table2', 'table3', 't_ignored']; |
801
|
|
|
$expectedConnectionAssets = [ |
802
|
|
|
// ignores table1 + schema_filter applies |
803
|
|
|
'connection1' => ['table2', 'table3'], |
804
|
|
|
// ignores table2, no schema_filter applies |
805
|
|
|
'connection2' => ['table1', 'table3', 't_ignored'], |
806
|
|
|
// connection3 has no ignores, handled separately |
807
|
|
|
]; |
808
|
|
|
|
809
|
|
|
$this->compileContainer($container); |
810
|
|
|
|
811
|
|
|
$getConfiguration = static function (string $connectionName) use ($container) : Configuration { |
812
|
|
|
return $container->get(sprintf('doctrine.dbal.%s_connection', $connectionName))->getConfiguration(); |
813
|
|
|
}; |
814
|
|
|
|
815
|
|
|
foreach ($expectedConnectionAssets as $connectionName => $expectedTables) { |
816
|
|
|
$connConfig = $getConfiguration($connectionName); |
817
|
|
|
$this->assertSame($expectedTables, array_values(array_filter($assetNames, $connConfig->getSchemaAssetsFilter())), sprintf('Filtering for connection "%s"', $connectionName)); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
$this->assertNull($connConfig = $getConfiguration('connection3')->getSchemaAssetsFilter()); |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
public function testEntityListenerResolver() |
824
|
|
|
{ |
825
|
|
|
$container = $this->loadContainer('orm_entity_listener_resolver', ['YamlBundle'], new EntityListenerPass()); |
826
|
|
|
|
827
|
|
|
$definition = $container->getDefinition('doctrine.orm.em1_configuration'); |
828
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em1_entity_listener_resolver')]); |
829
|
|
|
|
830
|
|
|
$definition = $container->getDefinition('doctrine.orm.em2_configuration'); |
831
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', [new Reference('doctrine.orm.em2_entity_listener_resolver')]); |
832
|
|
|
|
833
|
|
|
$listener = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver'); |
834
|
|
|
$this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener1')]); |
835
|
|
|
|
836
|
|
|
$listener = $container->getDefinition('entity_listener_resolver'); |
837
|
|
|
$this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener2')]); |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
public function testAttachEntityListenerTag() |
841
|
|
|
{ |
842
|
|
|
$container = $this->getContainer([]); |
843
|
|
|
$loader = new DoctrineExtension(); |
844
|
|
|
$container->registerExtension($loader); |
845
|
|
|
$container->addCompilerPass(new EntityListenerPass()); |
846
|
|
|
|
847
|
|
|
$this->loadFromFile($container, 'orm_attach_entity_listener_tag'); |
848
|
|
|
|
849
|
|
|
$this->compileContainer($container); |
850
|
|
|
|
851
|
|
|
$listener = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver'); |
852
|
|
|
$this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener1')]); |
853
|
|
|
|
854
|
|
|
$listener = $container->getDefinition('doctrine.orm.em2_entity_listener_resolver'); |
855
|
|
|
$this->assertDICDefinitionMethodCallOnce($listener, 'register', [new Reference('entity_listener2')]); |
856
|
|
|
|
857
|
|
|
$attachListener = $container->getDefinition('doctrine.orm.em1_listeners.attach_entity_listeners'); |
858
|
|
|
$this->assertDICDefinitionMethodCallOnce($attachListener, 'addEntityListener', ['My/Entity1', 'EntityListener1', 'postLoad']); |
859
|
|
|
|
860
|
|
|
$attachListener = $container->getDefinition('doctrine.orm.em2_listeners.attach_entity_listeners'); |
861
|
|
|
$this->assertDICDefinitionMethodCallOnce($attachListener, 'addEntityListener', ['My/Entity2', 'EntityListener2', 'preFlush', 'preFlushHandler']); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
public function testAttachEntityListenersTwoConnections() |
865
|
|
|
{ |
866
|
|
|
$container = $this->getContainer(['YamlBundle']); |
867
|
|
|
$loader = new DoctrineExtension(); |
868
|
|
|
$container->registerExtension($loader); |
869
|
|
|
$container->addCompilerPass(new RegisterEventListenersAndSubscribersPass('doctrine.connections', 'doctrine.dbal.%s_connection.event_manager', 'doctrine')); |
870
|
|
|
|
871
|
|
|
$this->loadFromFile($container, 'orm_attach_entity_listeners_two_connections'); |
872
|
|
|
|
873
|
|
|
$this->compileContainer($container); |
874
|
|
|
|
875
|
|
|
$defaultEventManager = $container->getDefinition('doctrine.dbal.default_connection.event_manager'); |
876
|
|
|
$this->assertDICDefinitionNoMethodCall($defaultEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em2_listeners.attach_entity_listeners')]); |
877
|
|
|
$this->assertDICDefinitionMethodCallOnce($defaultEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em1_listeners.attach_entity_listeners')]); |
878
|
|
|
|
879
|
|
|
$foobarEventManager = $container->getDefinition('doctrine.dbal.foobar_connection.event_manager'); |
880
|
|
|
$this->assertDICDefinitionNoMethodCall($foobarEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em1_listeners.attach_entity_listeners')]); |
881
|
|
|
$this->assertDICDefinitionMethodCallOnce($foobarEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em2_listeners.attach_entity_listeners')]); |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
public function testAttachLazyEntityListener() |
885
|
|
|
{ |
886
|
|
|
$container = $this->getContainer([]); |
887
|
|
|
$loader = new DoctrineExtension(); |
888
|
|
|
$container->registerExtension($loader); |
889
|
|
|
$container->addCompilerPass(new EntityListenerPass()); |
890
|
|
|
|
891
|
|
|
$this->loadFromFile($container, 'orm_attach_lazy_entity_listener'); |
892
|
|
|
|
893
|
|
|
$this->compileContainer($container); |
894
|
|
|
|
895
|
|
|
$resolver1 = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver'); |
896
|
|
|
$this->assertDICDefinitionMethodCallOnce($resolver1, 'registerService', ['EntityListener1', 'entity_listener1']); |
897
|
|
|
|
898
|
|
|
$resolver2 = $container->findDefinition('custom_entity_listener_resolver'); |
899
|
|
|
$this->assertDICDefinitionMethodCallOnce($resolver2, 'registerService', ['EntityListener2', 'entity_listener2']); |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
/** |
903
|
|
|
* @expectedException \InvalidArgumentException |
904
|
|
|
* @expectedExceptionMessage EntityListenerServiceResolver |
905
|
|
|
*/ |
906
|
|
View Code Duplication |
public function testLazyEntityListenerResolverWithoutCorrectInterface() |
|
|
|
|
907
|
|
|
{ |
908
|
|
|
$container = $this->getContainer([]); |
909
|
|
|
$loader = new DoctrineExtension(); |
910
|
|
|
$container->registerExtension($loader); |
911
|
|
|
$container->addCompilerPass(new EntityListenerPass()); |
912
|
|
|
|
913
|
|
|
$this->loadFromFile($container, 'orm_entity_listener_lazy_resolver_without_interface'); |
914
|
|
|
|
915
|
|
|
$this->compileContainer($container); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
public function testPrivateLazyEntityListener() |
919
|
|
|
{ |
920
|
|
|
$container = $this->getContainer([]); |
921
|
|
|
$loader = new DoctrineExtension(); |
922
|
|
|
$container->registerExtension($loader); |
923
|
|
|
$container->addCompilerPass(new EntityListenerPass()); |
924
|
|
|
|
925
|
|
|
$this->loadFromFile($container, 'orm_entity_listener_lazy_private'); |
926
|
|
|
|
927
|
|
|
$this->compileContainer($container); |
928
|
|
|
|
929
|
|
|
$this->assertTrue($container->getDefinition('doctrine.orm.em1_entity_listener_resolver')->isPublic()); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* @expectedException \InvalidArgumentException |
934
|
|
|
* @expectedExceptionMessageRegExp /The service ".*" must not be abstract as this entity listener is lazy-loaded/ |
935
|
|
|
*/ |
936
|
|
View Code Duplication |
public function testAbstractLazyEntityListener() |
|
|
|
|
937
|
|
|
{ |
938
|
|
|
$container = $this->getContainer([]); |
939
|
|
|
$loader = new DoctrineExtension(); |
940
|
|
|
$container->registerExtension($loader); |
941
|
|
|
$container->addCompilerPass(new EntityListenerPass()); |
942
|
|
|
|
943
|
|
|
$this->loadFromFile($container, 'orm_entity_listener_lazy_abstract'); |
944
|
|
|
|
945
|
|
|
$this->compileContainer($container); |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
public function testRepositoryFactory() |
949
|
|
|
{ |
950
|
|
|
$container = $this->loadContainer('orm_repository_factory'); |
951
|
|
|
|
952
|
|
|
$definition = $container->getDefinition('doctrine.orm.default_configuration'); |
953
|
|
|
$this->assertDICDefinitionMethodCallOnce($definition, 'setRepositoryFactory', ['repository_factory']); |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
private function loadContainer($fixture, array $bundles = ['YamlBundle'], CompilerPassInterface $compilerPass = null) |
957
|
|
|
{ |
958
|
|
|
$container = $this->getContainer($bundles); |
959
|
|
|
$container->registerExtension(new DoctrineExtension()); |
960
|
|
|
|
961
|
|
|
$this->loadFromFile($container, $fixture); |
962
|
|
|
|
963
|
|
|
if ($compilerPass !== null) { |
964
|
|
|
$container->addCompilerPass($compilerPass); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
$this->compileContainer($container); |
968
|
|
|
|
969
|
|
|
return $container; |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
private function getContainer(array $bundles) |
973
|
|
|
{ |
974
|
|
|
$map = []; |
975
|
|
|
foreach ($bundles as $bundle) { |
976
|
|
|
require_once __DIR__ . '/Fixtures/Bundles/' . $bundle . '/' . $bundle . '.php'; |
977
|
|
|
|
978
|
|
|
$map[$bundle] = 'Fixtures\\Bundles\\' . $bundle . '\\' . $bundle; |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
return new ContainerBuilder(new ParameterBag([ |
982
|
|
|
'kernel.name' => 'app', |
983
|
|
|
'kernel.debug' => false, |
984
|
|
|
'kernel.bundles' => $map, |
985
|
|
|
'kernel.cache_dir' => sys_get_temp_dir(), |
986
|
|
|
'kernel.environment' => 'test', |
987
|
|
|
'kernel.root_dir' => __DIR__ . '/../../', // src dir |
988
|
|
|
])); |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
/** |
992
|
|
|
* Assertion on the Class of a DIC Service Definition. |
993
|
|
|
* |
994
|
|
|
* @param string $expectedClass |
995
|
|
|
*/ |
996
|
|
|
private function assertDICDefinitionClass(Definition $definition, $expectedClass) |
997
|
|
|
{ |
998
|
|
|
$this->assertEquals($expectedClass, $definition->getClass(), 'Expected Class of the DIC Container Service Definition is wrong.'); |
999
|
|
|
} |
1000
|
|
|
|
1001
|
|
|
private function assertDICConstructorArguments(Definition $definition, $args) |
1002
|
|
|
{ |
1003
|
|
|
$this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass() . "' don't match."); |
1004
|
|
|
} |
1005
|
|
|
|
1006
|
|
View Code Duplication |
private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null) |
|
|
|
|
1007
|
|
|
{ |
1008
|
|
|
$calls = $definition->getMethodCalls(); |
1009
|
|
|
if (! isset($calls[$pos][0])) { |
1010
|
|
|
return; |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
$this->assertEquals($methodName, $calls[$pos][0], "Method '" . $methodName . "' is expected to be called at position " . $pos . '.'); |
1014
|
|
|
|
1015
|
|
|
if ($params === null) { |
1016
|
|
|
return; |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
$this->assertEquals($params, $calls[$pos][1], "Expected parameters to methods '" . $methodName . "' do not match the actual parameters."); |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
/** |
1023
|
|
|
* Assertion for the DI Container, check if the given definition contains a method call with the given parameters. |
1024
|
|
|
* |
1025
|
|
|
* @param string $methodName |
1026
|
|
|
* @param array $params |
|
|
|
|
1027
|
|
|
*/ |
1028
|
|
View Code Duplication |
private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null) |
|
|
|
|
1029
|
|
|
{ |
1030
|
|
|
$calls = $definition->getMethodCalls(); |
1031
|
|
|
$called = false; |
1032
|
|
|
foreach ($calls as $call) { |
1033
|
|
|
if ($call[0] !== $methodName) { |
1034
|
|
|
continue; |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
if ($called) { |
1038
|
|
|
$this->fail("Method '" . $methodName . "' is expected to be called only once, a second call was registered though."); |
1039
|
|
|
} else { |
1040
|
|
|
$called = true; |
1041
|
|
|
if ($params !== null) { |
1042
|
|
|
$this->assertEquals($params, $call[1], "Expected parameters to methods '" . $methodName . "' do not match the actual parameters."); |
1043
|
|
|
} |
1044
|
|
|
} |
1045
|
|
|
} |
1046
|
|
|
if ($called) { |
1047
|
|
|
return; |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
$this->fail("Method '" . $methodName . "' is expected to be called once, definition does not contain a call though."); |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
private function assertDICDefinitionMethodCallCount(Definition $definition, $methodName, array $params = [], $nbCalls = 1) |
1054
|
|
|
{ |
1055
|
|
|
$calls = $definition->getMethodCalls(); |
1056
|
|
|
$called = 0; |
1057
|
|
|
foreach ($calls as $call) { |
1058
|
|
|
if ($call[0] !== $methodName) { |
1059
|
|
|
continue; |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
if ($called > $nbCalls) { |
1063
|
|
|
break; |
1064
|
|
|
} |
1065
|
|
|
|
1066
|
|
|
if (isset($params[$called])) { |
1067
|
|
|
$this->assertEquals($params[$called], $call[1], "Expected parameters to methods '" . $methodName . "' do not match the actual parameters."); |
1068
|
|
|
} |
1069
|
|
|
$called++; |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
$this->assertEquals($nbCalls, $called, sprintf('The method "%s" should be called %d times', $methodName, $nbCalls)); |
1073
|
|
|
} |
1074
|
|
|
|
1075
|
|
|
/** |
1076
|
|
|
* Assertion for the DI Container, check if the given definition does not contain a method call with the given parameters. |
1077
|
|
|
* |
1078
|
|
|
* @param string $methodName |
1079
|
|
|
* @param array $params |
|
|
|
|
1080
|
|
|
*/ |
1081
|
|
|
private function assertDICDefinitionNoMethodCall(Definition $definition, $methodName, array $params = null) |
1082
|
|
|
{ |
1083
|
|
|
$calls = $definition->getMethodCalls(); |
1084
|
|
|
foreach ($calls as $call) { |
1085
|
|
|
if ($call[0] !== $methodName) { |
1086
|
|
|
continue; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
if ($params !== null) { |
1090
|
|
|
$this->assertNotEquals($params, $call[1], "Method '" . $methodName . "' is not expected to be called with the given parameters."); |
1091
|
|
|
} else { |
1092
|
|
|
$this->fail("Method '" . $methodName . "' is not expected to be called"); |
1093
|
|
|
} |
1094
|
|
|
} |
1095
|
|
|
} |
1096
|
|
|
|
1097
|
|
|
private function compileContainer(ContainerBuilder $container) |
1098
|
|
|
{ |
1099
|
|
|
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); |
1100
|
|
|
$container->getCompilerPassConfig()->setRemovingPasses([]); |
1101
|
|
|
$container->compile(); |
1102
|
|
|
} |
1103
|
|
|
} |
1104
|
|
|
|
1105
|
|
|
class DummySchemaAssetsFilter |
1106
|
|
|
{ |
1107
|
|
|
/** @var string */ |
1108
|
|
|
private $tableToIgnore; |
1109
|
|
|
|
1110
|
|
|
public function __construct(string $tableToIgnore) |
1111
|
|
|
{ |
1112
|
|
|
$this->tableToIgnore = $tableToIgnore; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
public function __invoke($assetName) : bool |
1116
|
|
|
{ |
1117
|
|
|
if ($assetName instanceof AbstractAsset) { |
1118
|
|
|
$assetName = $assetName->getName(); |
1119
|
|
|
} |
1120
|
|
|
|
1121
|
|
|
return $assetName !== $this->tableToIgnore; |
1122
|
|
|
} |
1123
|
|
|
} |
1124
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.