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