Completed
Pull Request — master (#692)
by Renan
04:40
created

AbstractDoctrineExtensionTest   F

Complexity

Total Complexity 84

Size/Duplication

Total Lines 1094
Duplicated Lines 17.09 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
wmc 84
lcom 1
cbo 13
dl 187
loc 1094
rs 2.8068
c 0
b 0
f 0

51 Methods

Rating   Name   Duplication   Size   Complexity  
A testDbalLoadSavepointsForNestedTransactions() 0 15 1
loadFromFile() 0 1 ?
A testDbalLoadFromXmlMultipleConnections() 0 62 1
A testDbalLoadFromXmlSingleConnections() 0 13 1
B testDbalLoadSingleMasterSlaveConnection() 0 25 1
B testDbalLoadPoolShardingConnection() 0 25 1
B testLoadSimpleSingleConnection() 6 35 2
B testLoadSimpleSingleConnectionWithoutDbName() 0 39 2
B testLoadSingleConnection() 6 39 2
A testLoadMultipleConnections() 12 63 3
A testLoadLogging() 13 13 1
A testLoadLoggingTag() 11 11 1
B testLoadLoggingAndTag() 0 29 1
A testEntityManagerMetadataCacheDriverConfiguration() 0 10 1
A testEntityManagerMemcacheMetadataCacheDriverConfiguration() 16 16 1
A testEntityManagerRedisMetadataCacheDriverConfigurationWithDatabaseKey() 15 15 1
A testDependencyInjectionImportsOverrideDefaults() 0 10 1
B testSingleEntityManagerMultipleMappingBundleDefinitions() 0 37 1
B testMultipleEntityManagersMappingBundleDefinitions() 0 41 1
A testSingleEntityManagerDefaultTableOptions() 0 19 1
A testSetTypes() 0 10 1
A testSetCustomFunctions() 0 9 1
A testSetNamingStrategy() 13 13 2
A testSetQuoteStrategy() 13 13 2
A testSecondLevelCache() 0 61 2
A testSingleEMSetCustomFunctions() 0 7 1
A testAddCustomHydrationMode() 0 7 1
A testAddFilter() 0 19 1
A testResolveTargetEntity() 0 13 2
A testAttachEntityListeners() 0 56 2
A testDbalAutoCommit() 0 7 1
A testDbalOracleConnectstring() 0 7 1
A testDbalOracleInstancename() 0 7 1
A testDbalSchemaFilter() 0 7 1
A testEntityListenerResolver() 6 20 3
B testAttachEntityListenerTag() 0 27 2
A testAttachEntityListenersTwoConnections() 0 23 2
A testAttachLazyEntityListener() 0 21 2
A testLazyEntityListenerResolverWithoutCorrectInterface() 15 15 2
A testPrivateLazyEntityListener() 15 15 2
A testAbstractLazyEntityListener() 15 15 2
A testRepositoryFactory() 0 7 1
A loadContainer() 0 15 2
A getContainer() 0 17 2
A assertDICDefinitionClass() 0 4 1
A assertDICConstructorArguments() 0 4 1
A assertDICDefinitionMethodCallAt() 11 11 3
B assertDICDefinitionMethodCallOnce() 20 20 6
B assertDICDefinitionMethodCallCount() 0 19 5
A assertDICDefinitionNoMethodCall() 0 13 4
A compileContainer() 0 6 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like AbstractDoctrineExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AbstractDoctrineExtensionTest, and based on these observations, apply Extract Interface, too.

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);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

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.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204
            $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory());
205
        } else {
206
            $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass());
0 ignored issues
show
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
207
            $this->assertEquals('create', $definition->getFactoryMethod());
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$factory was never initialized. Although not strictly required by PHP, it is generally a good practice to add $factory = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
247
            $factory[1] = $definition->getFactoryMethod();
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
284
            $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory());
285
        } else {
286
            $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass());
0 ignored issues
show
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
287
            $this->assertEquals('create', $definition->getFactoryMethod());
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
316
            $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory());
317
        } else {
318
            $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass());
0 ignored issues
show
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
319
            $this->assertEquals('create', $definition->getFactoryMethod());
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
340
            $this->assertEquals(array('%doctrine.orm.entity_manager.class%', 'create'), $definition->getFactory());
341
        } else {
342
            $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getFactoryClass());
0 ignored issues
show
Bug introduced by
The method getFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
343
            $this->assertEquals('create', $definition->getFactoryMethod());
0 ignored issues
show
Bug introduced by
The method getFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean getFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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 View Code Duplication
    public function testLoadLogging()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
    {
364
        $container = $this->loadContainer('dbal_logging', ['YamlBundle'], new DoctrineDBALLoggerPass());
365
366
        $definition = $container->getDefinition('doctrine.dbal.log_connection.configuration');
367
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger')));
368
369
        $definition = $container->getDefinition('doctrine.dbal.profile_connection.configuration');
370
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.profiling.profile')));
371
372
        $definition = $container->getDefinition('doctrine.dbal.both_connection.configuration');
373
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.chain.both')));
374
    }
375
376 View Code Duplication
    public function testLoadLoggingTag()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
    {
378
        $container = $this->loadContainer('dbal_logging_tag', ['YamlBundle'], new DoctrineDBALLoggerPass());
379
380
        $definition = $container->getDefinition('doctrine.dbal.tag_connection.configuration');
381
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.chain.tag')));
382
383
        $definition = $container->getDefinition('doctrine.dbal.logger.chain.tag');
384
        $this->assertDICDefinitionMethodCallAt(0, $definition, 'addLogger', array(new Reference('logger.echo')));
385
        $this->assertDICDefinitionMethodCallAt(1, $definition, 'addLogger', array(new Reference('logger.debug')));
386
    }
387
388
    public function testLoadLoggingAndTag()
389
    {
390
        $container = $this->loadContainer('dbal_logging_and_tag', ['YamlBundle'], new DoctrineDBALLoggerPass());
391
392
        // Log
393
        $definition = $container->getDefinition('doctrine.dbal.log_connection.configuration');
394
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.chain.log')));
395
396
        $definition = $container->getDefinition('doctrine.dbal.logger.chain.log');
397
        $this->assertDICDefinitionMethodCallAt(0, $definition, 'addLogger', array(new Reference('doctrine.dbal.logger')));
398
        $this->assertDICDefinitionMethodCallAt(1, $definition, 'addLogger', array(new Reference('logger.echo')));
399
400
        // Profile
401
        $definition = $container->getDefinition('doctrine.dbal.profile_connection.configuration');
402
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.chain.profile')));
403
404
        $definition = $container->getDefinition('doctrine.dbal.logger.chain.profile');
405
        $this->assertDICDefinitionMethodCallAt(0, $definition, 'addLogger', array(new Reference('doctrine.dbal.logger.profiling.profile')));
406
        $this->assertDICDefinitionMethodCallAt(1, $definition, 'addLogger', array(new Reference('logger.echo')));
407
408
        // Both
409
        $definition = $container->getDefinition('doctrine.dbal.both_connection.configuration');
410
        $this->assertDICDefinitionMethodCallOnce($definition, 'setSQLLogger', array(new Reference('doctrine.dbal.logger.chain.both')));
411
412
        $definition = $container->getDefinition('doctrine.dbal.logger.chain.both');
413
        $this->assertDICDefinitionMethodCallAt(0, $definition, 'addLogger', array(new Reference('doctrine.dbal.logger')));
414
        $this->assertDICDefinitionMethodCallAt(1, $definition, 'addLogger', array(new Reference('doctrine.dbal.logger.profiling.both')));
415
        $this->assertDICDefinitionMethodCallAt(2, $definition, 'addLogger', array(new Reference('logger.echo')));
416
    }
417
418
    public function testEntityManagerMetadataCacheDriverConfiguration()
419
    {
420
        $container = $this->loadContainer('orm_service_multiple_entity_managers');
421
422
        $definition = $container->getDefinition($container->getAlias('doctrine.orm.em1_metadata_cache'));
423
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.xcache.class%');
424
425
        $definition = $container->getDefinition($container->getAlias('doctrine.orm.em2_metadata_cache'));
426
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.apc.class%');
427
    }
428
429 View Code Duplication
    public function testEntityManagerMemcacheMetadataCacheDriverConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
430
    {
431
        $container = $this->loadContainer('orm_service_simple_single_entity_manager');
432
433
        $definition = $container->getDefinition($container->getAlias('doctrine.orm.default_metadata_cache'));
434
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.class%');
435
        $this->assertDICDefinitionMethodCallOnce($definition, 'setMemcache',
436
            array(new Reference('doctrine_cache.services.doctrine.orm.default_metadata_cache.connection'))
437
        );
438
439
        $definition = $container->getDefinition('doctrine_cache.services.doctrine.orm.default_metadata_cache.connection');
440
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.memcache.connection.class%');
441
        $this->assertDICDefinitionMethodCallOnce($definition, 'addServer', array(
442
            'localhost', '11211',
443
        ));
444
    }
445
446 View Code Duplication
    public function testEntityManagerRedisMetadataCacheDriverConfigurationWithDatabaseKey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
447
    {
448
        $container = $this->loadContainer('orm_service_simple_single_entity_manager_redis');
449
450
        $definition = $container->getDefinition($container->getAlias('doctrine.orm.default_metadata_cache'));
451
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.redis.class%');
452
        $this->assertDICDefinitionMethodCallOnce($definition, 'setRedis',
453
            array(new Reference('doctrine_cache.services.doctrine.orm.default_metadata_cache_redis.connection'))
454
        );
455
456
        $definition = $container->getDefinition('doctrine_cache.services.doctrine.orm.default_metadata_cache_redis.connection');
457
        $this->assertDICDefinitionClass($definition, '%doctrine_cache.redis.connection.class%');
458
        $this->assertDICDefinitionMethodCallOnce($definition, 'connect', array('localhost', '6379'));
459
        $this->assertDICDefinitionMethodCallOnce($definition, 'select', array(1));
460
    }
461
462
    public function testDependencyInjectionImportsOverrideDefaults()
463
    {
464
        $container = $this->loadContainer('orm_imports');
465
466
        $cacheDefinition = $container->getDefinition($container->getAlias('doctrine.orm.default_metadata_cache'));
467
        $this->assertEquals('%doctrine_cache.apc.class%', $cacheDefinition->getClass());
468
469
        $configDefinition = $container->getDefinition('doctrine.orm.default_configuration');
470
        $this->assertDICDefinitionMethodCallOnce($configDefinition, 'setAutoGenerateProxyClasses', array('%doctrine.orm.auto_generate_proxy_classes%'));
471
    }
472
473
    public function testSingleEntityManagerMultipleMappingBundleDefinitions()
474
    {
475
        $container = $this->loadContainer('orm_single_em_bundle_mappings', array('YamlBundle', 'AnnotationsBundle', 'XmlBundle'));
476
477
        $definition = $container->getDefinition('doctrine.orm.default_metadata_driver');
478
479
        $this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', array(
480
            new Reference('doctrine.orm.default_annotation_metadata_driver'),
481
            'Fixtures\Bundles\AnnotationsBundle\Entity',
482
        ));
483
484
        $this->assertDICDefinitionMethodCallAt(1, $definition, 'addDriver', array(
485
            new Reference('doctrine.orm.default_yml_metadata_driver'),
486
            'Fixtures\Bundles\YamlBundle\Entity',
487
        ));
488
489
        $this->assertDICDefinitionMethodCallAt(2, $definition, 'addDriver', array(
490
            new Reference('doctrine.orm.default_xml_metadata_driver'),
491
            'Fixtures\Bundles\XmlBundle',
492
        ));
493
494
        $annDef = $container->getDefinition('doctrine.orm.default_annotation_metadata_driver');
495
        $this->assertDICConstructorArguments($annDef, array(
496
            new Reference('doctrine.orm.metadata.annotation_reader'),
497
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'AnnotationsBundle'.DIRECTORY_SEPARATOR.'Entity'),
498
        ));
499
500
        $ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver');
501
        $this->assertDICConstructorArguments($ymlDef, array(
502
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine' => 'Fixtures\Bundles\YamlBundle\Entity'),
503
        ));
504
505
        $xmlDef = $container->getDefinition('doctrine.orm.default_xml_metadata_driver');
506
        $this->assertDICConstructorArguments($xmlDef, array(
507
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine' => 'Fixtures\Bundles\XmlBundle'),
508
        ));
509
    }
510
511
    public function testMultipleEntityManagersMappingBundleDefinitions()
512
    {
513
        $container = $this->loadContainer('orm_multiple_em_bundle_mappings', array('YamlBundle', 'AnnotationsBundle', 'XmlBundle'));
514
515
        $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.");
516
        $this->assertEquals('%doctrine.entity_managers%', $container->getDefinition('doctrine')->getArgument(2), "Set of the existing EntityManagers names is incorrect.");
517
518
        $def1 = $container->getDefinition('doctrine.orm.em1_metadata_driver');
519
        $def2 = $container->getDefinition('doctrine.orm.em2_metadata_driver');
520
521
        $this->assertDICDefinitionMethodCallAt(0, $def1, 'addDriver', array(
522
            new Reference('doctrine.orm.em1_annotation_metadata_driver'),
523
            'Fixtures\Bundles\AnnotationsBundle\Entity',
524
        ));
525
526
        $this->assertDICDefinitionMethodCallAt(0, $def2, 'addDriver', array(
527
            new Reference('doctrine.orm.em2_yml_metadata_driver'),
528
            'Fixtures\Bundles\YamlBundle\Entity',
529
        ));
530
531
        $this->assertDICDefinitionMethodCallAt(1, $def2, 'addDriver', array(
532
            new Reference('doctrine.orm.em2_xml_metadata_driver'),
533
            'Fixtures\Bundles\XmlBundle',
534
        ));
535
536
        $annDef = $container->getDefinition('doctrine.orm.em1_annotation_metadata_driver');
537
        $this->assertDICConstructorArguments($annDef, array(
538
            new Reference('doctrine.orm.metadata.annotation_reader'),
539
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'AnnotationsBundle'.DIRECTORY_SEPARATOR.'Entity'),
540
        ));
541
542
        $ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver');
543
        $this->assertDICConstructorArguments($ymlDef, array(
544
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine' => 'Fixtures\Bundles\YamlBundle\Entity'),
545
        ));
546
547
        $xmlDef = $container->getDefinition('doctrine.orm.em2_xml_metadata_driver');
548
        $this->assertDICConstructorArguments($xmlDef, array(
549
            array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine' => 'Fixtures\Bundles\XmlBundle'),
550
        ));
551
    }
552
553
    public function testSingleEntityManagerDefaultTableOptions()
554
    {
555
        $container = $this->loadContainer('orm_single_em_default_table_options', array('YamlBundle', 'AnnotationsBundle', 'XmlBundle'));
556
557
        $param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0);
558
559
        $this->assertArrayHasKey('defaultTableOptions',$param);
560
561
        $defaults = $param['defaultTableOptions'];
562
563
        $this->assertArrayHasKey('charset', $defaults);
564
        $this->assertArrayHasKey('collate', $defaults);
565
        $this->assertArrayHasKey('engine', $defaults);
566
567
        $this->assertEquals('utf8mb4',$defaults['charset']);
568
        $this->assertEquals('utf8mb4_unicode_ci',$defaults['collate']);
569
        $this->assertEquals('InnoDB',$defaults['engine']);
570
571
    }
572
573
    public function testSetTypes()
574
    {
575
        $container = $this->loadContainer('dbal_types');
576
577
        $this->assertEquals(
578
            array('test' => array('class' => TestType::class, 'commented' => true)),
579
            $container->getParameter('doctrine.dbal.connection_factory.types')
580
        );
581
        $this->assertEquals('%doctrine.dbal.connection_factory.types%', $container->getDefinition('doctrine.dbal.connection_factory')->getArgument(0));
582
    }
583
584
    public function testSetCustomFunctions()
585
    {
586
        $container = $this->loadContainer('orm_functions');
587
588
        $definition = $container->getDefinition('doctrine.orm.default_configuration');
589
        $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomStringFunction', array('test_string', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction'));
590
        $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomNumericFunction', array('test_numeric', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestNumericFunction'));
591
        $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomDatetimeFunction', array('test_datetime', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestDatetimeFunction'));
592
    }
593
594 View Code Duplication
    public function testSetNamingStrategy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
595
    {
596
        if (version_compare(Version::VERSION, "2.3.0-DEV") < 0) {
597
            $this->markTestSkipped('Naming Strategies are not available');
598
        }
599
        $container = $this->loadContainer('orm_namingstrategy');
600
601
        $def1 = $container->getDefinition('doctrine.orm.em1_configuration');
602
        $def2 = $container->getDefinition('doctrine.orm.em2_configuration');
603
604
        $this->assertDICDefinitionMethodCallOnce($def1, 'setNamingStrategy', array(0 => new Reference('doctrine.orm.naming_strategy.default')));
605
        $this->assertDICDefinitionMethodCallOnce($def2, 'setNamingStrategy', array(0 => new Reference('doctrine.orm.naming_strategy.underscore')));
606
    }
607
608 View Code Duplication
    public function testSetQuoteStrategy()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
609
    {
610
        if (version_compare(Version::VERSION, "2.3.0-DEV") < 0) {
611
            $this->markTestSkipped('Quote Strategies are not available');
612
        }
613
        $container = $this->loadContainer('orm_quotestrategy');
614
615
        $def1 = $container->getDefinition('doctrine.orm.em1_configuration');
616
        $def2 = $container->getDefinition('doctrine.orm.em2_configuration');
617
618
        $this->assertDICDefinitionMethodCallOnce($def1, 'setQuoteStrategy', array(0 => new Reference('doctrine.orm.quote_strategy.default')));
619
        $this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', array(0 => new Reference('doctrine.orm.quote_strategy.ansi')));
620
    }
621
622
    public function testSecondLevelCache()
623
    {
624
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
625
            $this->markTestSkipped('Second-level cache requires doctrine-orm 2.5.0 or newer');
626
        }
627
628
        $container = $this->loadContainer('orm_second_level_cache');
629
630
        $this->assertTrue($container->has('doctrine.orm.default_configuration'));
631
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.cache_configuration'));
632
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region_cache_driver'));
633
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.regions_configuration'));
634
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.default_cache_factory'));
635
636
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_chain'));
637
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger_statistics'));
638
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger1'));
639
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.logger.my_service_logger2'));
640
641
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_entity_region'));
642
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_service_region'));
643
        $this->assertTrue($container->has('doctrine.orm.default_second_level_cache.region.my_query_region_filelock'));
644
645
        $slcFactoryDef = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory');
646
        $myEntityRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_entity_region');
647
        $loggerChainDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_chain');
648
        $loggerStatisticsDef = $container->getDefinition('doctrine.orm.default_second_level_cache.logger_statistics');
649
        $myQueryRegionDef = $container->getDefinition('doctrine.orm.default_second_level_cache.region.my_query_region_filelock');
650
        $cacheDriverDef = $container->getDefinition($container->getAlias('doctrine.orm.default_second_level_cache.region_cache_driver'));
651
        $configDef = $container->getDefinition('doctrine.orm.default_configuration');
652
        $myEntityRegionArgs = $myEntityRegionDef->getArguments();
653
        $myQueryRegionArgs = $myQueryRegionDef->getArguments();
654
        $slcFactoryArgs = $slcFactoryDef->getArguments();
655
656
        $this->assertDICDefinitionClass($slcFactoryDef, '%doctrine.orm.second_level_cache.default_cache_factory.class%');
657
        $this->assertDICDefinitionClass($myQueryRegionDef, '%doctrine.orm.second_level_cache.filelock_region.class%');
658
        $this->assertDICDefinitionClass($myEntityRegionDef, '%doctrine.orm.second_level_cache.default_region.class%');
659
        $this->assertDICDefinitionClass($loggerChainDef, '%doctrine.orm.second_level_cache.logger_chain.class%');
660
        $this->assertDICDefinitionClass($loggerStatisticsDef, '%doctrine.orm.second_level_cache.logger_statistics.class%');
661
        $this->assertDICDefinitionClass($cacheDriverDef, '%doctrine_cache.array.class%');
662
        $this->assertDICDefinitionMethodCallOnce($configDef, 'setSecondLevelCacheConfiguration');
663
        $this->assertDICDefinitionMethodCallCount($slcFactoryDef, 'setRegion', array(), 3);
664
        $this->assertDICDefinitionMethodCallCount($loggerChainDef, 'setLogger', array(), 3);
665
666
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[0]);
667
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $slcFactoryArgs[1]);
668
669
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myEntityRegionArgs[1]);
670
        $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $myQueryRegionArgs[0]);
671
672
        $this->assertEquals('my_entity_region', $myEntityRegionArgs[0]);
673
        $this->assertEquals('doctrine.orm.default_second_level_cache.region.my_entity_region_driver', $myEntityRegionArgs[1]);
674
        $this->assertEquals(600, $myEntityRegionArgs[2]);
675
676
        $this->assertEquals('doctrine.orm.default_second_level_cache.region.my_query_region', $myQueryRegionArgs[0]);
677
        $this->assertContains('/doctrine/orm/slc/filelock', $myQueryRegionArgs[1]);
678
        $this->assertEquals(60, $myQueryRegionArgs[2]);
679
680
        $this->assertEquals('doctrine.orm.default_second_level_cache.regions_configuration', $slcFactoryArgs[0]);
681
        $this->assertEquals('doctrine.orm.default_second_level_cache.region_cache_driver', $slcFactoryArgs[1]);
682
    }
683
684
    public function testSingleEMSetCustomFunctions()
685
    {
686
        $container = $this->loadContainer('orm_single_em_dql_functions');
687
688
        $definition = $container->getDefinition('doctrine.orm.default_configuration');
689
        $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomStringFunction', array('test_string', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction'));
690
    }
691
692
    public function testAddCustomHydrationMode()
693
    {
694
        $container = $this->loadContainer('orm_hydration_mode');
695
696
        $definition = $container->getDefinition('doctrine.orm.default_configuration');
697
        $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', array('test_hydrator', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator'));
698
    }
699
700
    public function testAddFilter()
701
    {
702
        $container = $this->loadContainer('orm_filters');
703
704
        $definition = $container->getDefinition('doctrine.orm.default_configuration');
705
        $args = array(
706
            array('soft_delete', 'Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter'),
707
            array('myFilter', 'Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestFilter'),
708
        );
709
        $this->assertDICDefinitionMethodCallCount($definition, 'addFilter', $args, 2);
710
711
        $definition = $container->getDefinition('doctrine.orm.default_manager_configurator');
712
        $this->assertDICConstructorArguments($definition, array(array('soft_delete', 'myFilter'), array('myFilter' => array('myParameter' => 'myValue', 'mySecondParameter' => 'mySecondValue'))));
713
714
        // Let's create the instance to check the configurator work.
715
        /** @var $entityManager \Doctrine\ORM\EntityManager */
716
        $entityManager = $container->get('doctrine.orm.entity_manager');
717
        $this->assertCount(2, $entityManager->getFilters()->getEnabledFilters());
718
    }
719
720
    public function testResolveTargetEntity()
721
    {
722
        $container = $this->loadContainer('orm_resolve_target_entity');
723
724
        $definition = $container->getDefinition('doctrine.orm.listeners.resolve_target_entity');
725
        $this->assertDICDefinitionMethodCallOnce($definition, 'addResolveTargetEntity', array('Symfony\Component\Security\Core\User\UserInterface', 'MyUserClass', array()));
726
727
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
728
            $this->assertEquals(array('doctrine.event_listener' => array(array('event' => 'loadClassMetadata'))), $definition->getTags());
729
        } else {
730
            $this->assertEquals(array('doctrine.event_subscriber' => array(array())), $definition->getTags());
731
        }
732
    }
733
734
    public function testAttachEntityListeners()
735
    {
736
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0 ) {
737
            $this->markTestSkipped('This test requires ORM 2.5-dev.');
738
        }
739
740
        $container = $this->loadContainer('orm_attach_entity_listener');
741
742
        $definition = $container->getDefinition('doctrine.orm.default_listeners.attach_entity_listeners');
743
        $methodCalls = $definition->getMethodCalls();
744
745
        $this->assertDICDefinitionMethodCallCount($definition, 'addEntityListener', array(), 6);
746
        $this->assertEquals(array('doctrine.event_listener' => array( array('event' => 'loadClassMetadata') ) ), $definition->getTags());
747
748
        $this->assertEquals($methodCalls[0], array('addEntityListener', array (
749
            'ExternalBundles\Entities\FooEntity',
750
            'MyBundles\Listeners\FooEntityListener',
751
            'prePersist',
752
            null,
753
        )));
754
755
        $this->assertEquals($methodCalls[1], array('addEntityListener', array (
756
            'ExternalBundles\Entities\FooEntity',
757
            'MyBundles\Listeners\FooEntityListener',
758
            'postPersist',
759
            'postPersist',
760
        )));
761
762
        $this->assertEquals($methodCalls[2], array('addEntityListener', array (
763
            'ExternalBundles\Entities\FooEntity',
764
            'MyBundles\Listeners\FooEntityListener',
765
            'postLoad',
766
            'postLoadHandler',
767
        )));
768
769
        $this->assertEquals($methodCalls[3], array('addEntityListener', array (
770
            'ExternalBundles\Entities\BarEntity',
771
            'MyBundles\Listeners\BarEntityListener',
772
            'prePersist',
773
            'prePersist',
774
        )));
775
776
        $this->assertEquals($methodCalls[4], array('addEntityListener', array (
777
            'ExternalBundles\Entities\BarEntity',
778
            'MyBundles\Listeners\BarEntityListener',
779
            'prePersist',
780
            'prePersistHandler',
781
        )));
782
783
        $this->assertEquals($methodCalls[5], array('addEntityListener', array (
784
            'ExternalBundles\Entities\BarEntity',
785
            'MyBundles\Listeners\LogDeleteEntityListener',
786
            'postDelete',
787
            'postDelete',
788
        )));
789
    }
790
791
    public function testDbalAutoCommit()
792
    {
793
        $container = $this->loadContainer('dbal_auto_commit');
794
795
        $definition = $container->getDefinition('doctrine.dbal.default_connection.configuration');
796
        $this->assertDICDefinitionMethodCallOnce($definition, 'setAutoCommit', array(false));
797
    }
798
799
    public function testDbalOracleConnectstring()
800
    {
801
        $container = $this->loadContainer('dbal_oracle_connectstring');
802
803
        $config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0);
804
        $this->assertSame('scott@sales-server:1521/sales.us.example.com', $config['connectstring']);
805
    }
806
807
    public function testDbalOracleInstancename()
808
    {
809
        $container = $this->loadContainer('dbal_oracle_instancename');
810
811
        $config = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0);
812
        $this->assertSame('mySuperInstance', $config['instancename']);
813
    }
814
815
    public function testDbalSchemaFilter()
816
    {
817
        $container = $this->loadContainer('dbal_schema_filter');
818
819
        $definition = $container->getDefinition('doctrine.dbal.default_connection.configuration');
820
        $this->assertDICDefinitionMethodCallOnce($definition, 'setFilterSchemaAssetsExpression', array('^sf2_'));
821
    }
822
823
    public function testEntityListenerResolver()
824
    {
825
        $container = $this->loadContainer('orm_entity_listener_resolver', array('YamlBundle'), new EntityListenerPass());
826
827
        $definition = $container->getDefinition('doctrine.orm.em1_configuration');
828 View Code Duplication
        if (version_compare(Version::VERSION, "2.4.0-DEV") >= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
829
            $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', array(new Reference('doctrine.orm.em1_entity_listener_resolver')));
830
        }
831
832
        $definition = $container->getDefinition('doctrine.orm.em2_configuration');
833 View Code Duplication
        if (version_compare(Version::VERSION, "2.4.0-DEV") >= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
834
            $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityListenerResolver', array(new Reference('doctrine.orm.em2_entity_listener_resolver')));
835
        }
836
837
        $listener = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver');
838
        $this->assertDICDefinitionMethodCallOnce($listener, 'register', array(new Reference('entity_listener1')));
839
840
        $listener = $container->getDefinition('entity_listener_resolver');
841
        $this->assertDICDefinitionMethodCallOnce($listener, 'register', array(new Reference('entity_listener2')));
842
    }
843
844
    public function testAttachEntityListenerTag()
845
    {
846
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
847
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
848
        }
849
850
        $container = $this->getContainer(array());
851
        $loader = new DoctrineExtension();
852
        $container->registerExtension($loader);
853
        $container->addCompilerPass(new EntityListenerPass());
854
855
        $this->loadFromFile($container, 'orm_attach_entity_listener_tag');
856
857
        $this->compileContainer($container);
858
859
        $listener = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver');
860
        $this->assertDICDefinitionMethodCallOnce($listener, 'register', array(new Reference('entity_listener1')));
861
862
        $listener = $container->getDefinition('doctrine.orm.em2_entity_listener_resolver');
863
        $this->assertDICDefinitionMethodCallOnce($listener, 'register', array(new Reference('entity_listener2')));
864
865
        $attachListener = $container->getDefinition('doctrine.orm.em1_listeners.attach_entity_listeners');
866
        $this->assertDICDefinitionMethodCallOnce($attachListener, 'addEntityListener', array('My/Entity1', 'EntityListener1', 'postLoad'));
867
868
        $attachListener = $container->getDefinition('doctrine.orm.em2_listeners.attach_entity_listeners');
869
        $this->assertDICDefinitionMethodCallOnce($attachListener, 'addEntityListener', array('My/Entity2', 'EntityListener2', 'preFlush', 'preFlushHandler'));
870
    }
871
872
    public function testAttachEntityListenersTwoConnections()
873
    {
874
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
875
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
876
        }
877
878
        $container = $this->getContainer(['YamlBundle']);
879
        $loader = new DoctrineExtension();
880
        $container->registerExtension($loader);
881
        $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass('doctrine.connections', 'doctrine.dbal.%s_connection.event_manager', 'doctrine'));
882
883
        $this->loadFromFile($container, 'orm_attach_entity_listeners_two_connections');
884
885
        $this->compileContainer($container);
886
887
        $defaultEventManager = $container->getDefinition('doctrine.dbal.default_connection.event_manager');
888
        $this->assertDICDefinitionNoMethodCall($defaultEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em2_listeners.attach_entity_listeners')]);
889
        $this->assertDICDefinitionMethodCallOnce($defaultEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em1_listeners.attach_entity_listeners')]);
890
891
        $foobarEventManager = $container->getDefinition('doctrine.dbal.foobar_connection.event_manager');
892
        $this->assertDICDefinitionNoMethodCall($foobarEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em1_listeners.attach_entity_listeners')]);
893
        $this->assertDICDefinitionMethodCallOnce($foobarEventManager, 'addEventListener', [['loadClassMetadata'], new Reference('doctrine.orm.em2_listeners.attach_entity_listeners')]);
894
    }
895
896
    public function testAttachLazyEntityListener()
897
    {
898
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
899
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
900
        }
901
902
        $container = $this->getContainer(array());
903
        $loader = new DoctrineExtension();
904
        $container->registerExtension($loader);
905
        $container->addCompilerPass(new EntityListenerPass());
906
907
        $this->loadFromFile($container, 'orm_attach_lazy_entity_listener');
908
909
        $this->compileContainer($container);
910
911
        $resolver1 = $container->getDefinition('doctrine.orm.em1_entity_listener_resolver');
912
        $this->assertDICDefinitionMethodCallOnce($resolver1, 'registerService', array('EntityListener1', 'entity_listener1'));
913
914
        $resolver2 = $container->findDefinition('custom_entity_listener_resolver');
915
        $this->assertDICDefinitionMethodCallOnce($resolver2, 'registerService', array('EntityListener2', 'entity_listener2'));
916
    }
917
918
    /**
919
     * @expectedException \InvalidArgumentException
920
     * @expectedExceptionMessage EntityListenerServiceResolver
921
     */
922 View Code Duplication
    public function testLazyEntityListenerResolverWithoutCorrectInterface()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
923
    {
924
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
925
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
926
        }
927
928
        $container = $this->getContainer(array());
929
        $loader = new DoctrineExtension();
930
        $container->registerExtension($loader);
931
        $container->addCompilerPass(new EntityListenerPass());
932
933
        $this->loadFromFile($container, 'orm_entity_listener_lazy_resolver_without_interface');
934
935
        $this->compileContainer($container);
936
    }
937
938
    /**
939
     * @expectedException \InvalidArgumentException
940
     * @expectedExceptionMessageRegExp /The service ".*" must be public as this entity listener is lazy-loaded/
941
     */
942 View Code Duplication
    public function testPrivateLazyEntityListener()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
943
    {
944
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
945
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
946
        }
947
948
        $container = $this->getContainer(array());
949
        $loader = new DoctrineExtension();
950
        $container->registerExtension($loader);
951
        $container->addCompilerPass(new EntityListenerPass());
952
953
        $this->loadFromFile($container, 'orm_entity_listener_lazy_private');
954
955
        $this->compileContainer($container);
956
    }
957
958
    /**
959
     * @expectedException \InvalidArgumentException
960
     * @expectedExceptionMessageRegExp /The service ".*" must not be abstract as this entity listener is lazy-loaded/
961
     */
962 View Code Duplication
    public function testAbstractLazyEntityListener()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
963
    {
964
        if (version_compare(Version::VERSION, '2.5.0-DEV') < 0) {
965
            $this->markTestSkipped('Attaching entity listeners by tag requires doctrine-orm 2.5.0 or newer');
966
        }
967
968
        $container = $this->getContainer(array());
969
        $loader = new DoctrineExtension();
970
        $container->registerExtension($loader);
971
        $container->addCompilerPass(new EntityListenerPass());
972
973
        $this->loadFromFile($container, 'orm_entity_listener_lazy_abstract');
974
975
        $this->compileContainer($container);
976
    }
977
978
    public function testRepositoryFactory()
979
    {
980
        $container = $this->loadContainer('orm_repository_factory');
981
982
        $definition = $container->getDefinition('doctrine.orm.default_configuration');
983
        $this->assertDICDefinitionMethodCallOnce($definition, 'setRepositoryFactory', array('repository_factory'));
984
    }
985
986
    private function loadContainer($fixture, array $bundles = array('YamlBundle'), CompilerPassInterface $compilerPass = null)
987
    {
988
        $container = $this->getContainer($bundles);
989
        $container->registerExtension(new DoctrineExtension());
990
991
        $this->loadFromFile($container, $fixture);
992
993
        if (null !== $compilerPass) {
994
            $container->addCompilerPass($compilerPass);
995
        }
996
997
        $this->compileContainer($container);
998
999
        return $container;
1000
    }
1001
1002
    private function getContainer(array $bundles)
1003
    {
1004
        $map = array();
1005
        foreach ($bundles as $bundle) {
1006
            require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php';
1007
1008
            $map[$bundle] = 'Fixtures\\Bundles\\'.$bundle.'\\'.$bundle;
1009
        }
1010
1011
        return new ContainerBuilder(new ParameterBag(array(
1012
            'kernel.debug' => false,
1013
            'kernel.bundles' => $map,
1014
            'kernel.cache_dir' => sys_get_temp_dir(),
1015
            'kernel.environment' => 'test',
1016
            'kernel.root_dir' => __DIR__.'/../../', // src dir
1017
        )));
1018
    }
1019
1020
    /**
1021
     * Assertion on the Class of a DIC Service Definition.
1022
     *
1023
     * @param Definition $definition
1024
     * @param string     $expectedClass
1025
     */
1026
    private function assertDICDefinitionClass(Definition $definition, $expectedClass)
1027
    {
1028
        $this->assertEquals($expectedClass, $definition->getClass(), 'Expected Class of the DIC Container Service Definition is wrong.');
1029
    }
1030
1031
    private function assertDICConstructorArguments(Definition $definition, $args)
1032
    {
1033
        $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '".$definition->getClass()."' don't match.");
1034
    }
1035
1036 View Code Duplication
    private function assertDICDefinitionMethodCallAt($pos, Definition $definition, $methodName, array $params = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1037
    {
1038
        $calls = $definition->getMethodCalls();
1039
        if (isset($calls[$pos][0])) {
1040
            $this->assertEquals($methodName, $calls[$pos][0], "Method '".$methodName."' is expected to be called at position $pos.");
1041
1042
            if ($params !== null) {
1043
                $this->assertEquals($params, $calls[$pos][1], "Expected parameters to methods '".$methodName."' do not match the actual parameters.");
1044
            }
1045
        }
1046
    }
1047
1048
    /**
1049
     * Assertion for the DI Container, check if the given definition contains a method call with the given parameters.
1050
     *
1051
     * @param Definition $definition
1052
     * @param string     $methodName
1053
     * @param array      $params
0 ignored issues
show
Documentation introduced by
Should the type for parameter $params not be null|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1054
     */
1055 View Code Duplication
    private function assertDICDefinitionMethodCallOnce(Definition $definition, $methodName, array $params = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1056
    {
1057
        $calls = $definition->getMethodCalls();
1058
        $called = false;
1059
        foreach ($calls as $call) {
1060
            if ($call[0] == $methodName) {
1061
                if ($called) {
1062
                    $this->fail("Method '".$methodName."' is expected to be called only once, a second call was registered though.");
1063
                } else {
1064
                    $called = true;
1065
                    if ($params !== null) {
1066
                        $this->assertEquals($params, $call[1], "Expected parameters to methods '".$methodName."' do not match the actual parameters.");
1067
                    }
1068
                }
1069
            }
1070
        }
1071
        if (!$called) {
1072
            $this->fail("Method '".$methodName."' is expected to be called once, definition does not contain a call though.");
1073
        }
1074
    }
1075
1076
    private function assertDICDefinitionMethodCallCount(Definition $definition, $methodName, array $params = array(), $nbCalls = 1)
1077
    {
1078
        $calls = $definition->getMethodCalls();
1079
        $called = 0;
1080
        foreach ($calls as $call) {
1081
            if ($call[0] == $methodName) {
1082
                if ($called > $nbCalls) {
1083
                    break;
1084
                }
1085
1086
                if (isset($params[$called])) {
1087
                    $this->assertEquals($params[$called], $call[1], "Expected parameters to methods '".$methodName."' do not match the actual parameters.");
1088
                }
1089
                $called++;
1090
            }
1091
        }
1092
1093
        $this->assertEquals($nbCalls, $called, sprintf('The method "%s" should be called %d times', $methodName, $nbCalls));
1094
    }
1095
1096
    /**
1097
     * Assertion for the DI Container, check if the given definition does not contain a method call with the given parameters.
1098
     *
1099
     * @param Definition $definition
1100
     * @param string     $methodName
1101
     * @param array      $params
0 ignored issues
show
Documentation introduced by
Should the type for parameter $params not be null|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1102
     */
1103
    private function assertDICDefinitionNoMethodCall(Definition $definition, $methodName, array $params = null)
1104
    {
1105
        $calls = $definition->getMethodCalls();
1106
        foreach ($calls as $call) {
1107
            if ($call[0] == $methodName) {
1108
                if ($params !== null) {
1109
                    $this->assertNotEquals($params, $call[1], "Method '" . $methodName . "' is not expected to be called with the given parameters.");
1110
                } else {
1111
                    $this->fail("Method '" . $methodName . "' is not expected to be called");
1112
                }
1113
            }
1114
        }
1115
    }
1116
1117
    private function compileContainer(ContainerBuilder $container)
1118
    {
1119
        $container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
1120
        $container->getCompilerPassConfig()->setRemovingPasses(array());
1121
        $container->compile();
1122
    }
1123
}
1124