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