|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\DependencyInjection\Tests\Dumper;
|
13 | 13 |
|
| 14 | +use DummyProxyDumper; |
14 | 15 | use Symfony\Component\Config\FileLocator;
|
15 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
16 | 17 | use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
|
21 | 22 | use Symfony\Component\DependencyInjection\Variable;
|
22 | 23 | use Symfony\Component\ExpressionLanguage\Expression;
|
23 | 24 |
|
| 25 | +require_once __DIR__.'/../Fixtures/includes/classes.php'; |
| 26 | + |
24 | 27 | class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
25 | 28 | {
|
26 | 29 | protected static $fixturesPath;
|
@@ -340,4 +343,52 @@ public function testInitializePropertiesBeforeMethodCalls()
|
340 | 343 | $container = new \Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls();
|
341 | 344 | $this->assertTrue($container->get('bar')->callPassed(), '->dump() initializes properties before method calls');
|
342 | 345 | }
|
| 346 | + |
| 347 | + public function testCircularReferenceAllowanceForLazyServices() |
| 348 | + { |
| 349 | + $container = new ContainerBuilder(); |
| 350 | + $container->register('foo', 'stdClass')->addArgument(new Reference('bar')); |
| 351 | + $container->register('bar', 'stdClass')->setLazy(true)->addArgument(new Reference('foo')); |
| 352 | + $container->compile(); |
| 353 | + |
| 354 | + $dumper = new PhpDumper($container); |
| 355 | + $dumper->dump(); |
| 356 | + } |
| 357 | + |
| 358 | + public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices() |
| 359 | + { |
| 360 | + /* |
| 361 | + * test graph: |
| 362 | + * [connection] -> [event_manager] --> [entity_manager](lazy) |
| 363 | + * | |
| 364 | + * --(call)- addEventListener ("@lazy_service") |
| 365 | + * |
| 366 | + * [lazy_service](lazy) -> [entity_manager](lazy) |
| 367 | + * |
| 368 | + */ |
| 369 | + |
| 370 | + $container = new ContainerBuilder(); |
| 371 | + |
| 372 | + $eventManagerDefinition = new Definition('stdClass'); |
| 373 | + |
| 374 | + $connectionDefinition = $container->register('connection', 'stdClass'); |
| 375 | + $connectionDefinition->addArgument($eventManagerDefinition); |
| 376 | + |
| 377 | + $container->register('entity_manager', 'stdClass') |
| 378 | + ->setLazy(true) |
| 379 | + ->addArgument(new Reference('connection')); |
| 380 | + |
| 381 | + $lazyServiceDefinition = $container->register('lazy_service', 'stdClass'); |
| 382 | + $lazyServiceDefinition->setLazy(true); |
| 383 | + $lazyServiceDefinition->addArgument(new Reference('entity_manager')); |
| 384 | + |
| 385 | + $eventManagerDefinition->addMethodCall('addEventListener', array(new Reference('lazy_service'))); |
| 386 | + |
| 387 | + $container->compile(); |
| 388 | + |
| 389 | + $dumper = new PhpDumper($container); |
| 390 | + |
| 391 | + $dumper->setProxyDumper(new DummyProxyDumper()); |
| 392 | + $dumper->dump(); |
| 393 | + } |
343 | 394 | }
|
0 commit comments