|
15 | 15 | use Symfony\Component\Config\FileLocator;
|
16 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
17 | 17 | use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
| 18 | +use Symfony\Component\DependencyInjection\LazyArgument; |
18 | 19 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
19 | 20 | use Symfony\Component\DependencyInjection\Reference;
|
20 | 21 | use Symfony\Component\DependencyInjection\Definition;
|
@@ -391,4 +392,60 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
|
391 | 392 | $dumper->setProxyDumper(new DummyProxyDumper());
|
392 | 393 | $dumper->dump();
|
393 | 394 | }
|
| 395 | + |
| 396 | + public function testLazyArgumentProvideGenerator() |
| 397 | + { |
| 398 | + require_once self::$fixturesPath.'/includes/classes.php'; |
| 399 | + |
| 400 | + $container = new ContainerBuilder(); |
| 401 | + $container->register('lazy_referenced', 'stdClass'); |
| 402 | + $container |
| 403 | + ->register('lazy_context', 'LazyContext') |
| 404 | + ->setArguments(array(new LazyArgument(array('foo', new Reference('lazy_referenced'), 'k1' => array('foo' => 'bar'), true, 'k2' => new Reference('service_container'))))) |
| 405 | + ; |
| 406 | + $container->compile(); |
| 407 | + |
| 408 | + $dumper = new PhpDumper($container); |
| 409 | + eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator'))); |
| 410 | + |
| 411 | + $container = new \Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator(); |
| 412 | + $lazyContext = $container->get('lazy_context'); |
| 413 | + |
| 414 | + $this->assertInstanceOf('\Generator', $lazyContext->lazyValues); |
| 415 | + |
| 416 | + $i = -1; |
| 417 | + foreach ($lazyContext->lazyValues as $k => $v) { |
| 418 | + $i++; |
| 419 | + |
| 420 | + if ($i === 0) { |
| 421 | + $this->assertEquals(0, $k); |
| 422 | + $this->assertEquals('foo', $v); |
| 423 | + continue; |
| 424 | + } |
| 425 | + |
| 426 | + if ($i === 1) { |
| 427 | + $this->assertEquals(1, $k); |
| 428 | + $this->assertInstanceOf('\stdClass', $v); |
| 429 | + continue; |
| 430 | + } |
| 431 | + |
| 432 | + if ($i === 2) { |
| 433 | + $this->assertEquals('k1', $k); |
| 434 | + $this->assertEquals(array('foo' => 'bar'), $v); |
| 435 | + continue; |
| 436 | + } |
| 437 | + |
| 438 | + if ($i === 3) { |
| 439 | + $this->assertEquals(2, $k); |
| 440 | + $this->assertTrue($v); |
| 441 | + continue; |
| 442 | + } |
| 443 | + |
| 444 | + if ($i === 4) { |
| 445 | + $this->assertEquals('k2', $k); |
| 446 | + $this->assertInstanceOf('\Symfony_DI_PhpDumper_Test_Lazy_Argument_Provide_Generator', $v); |
| 447 | + continue; |
| 448 | + } |
| 449 | + } |
| 450 | + } |
394 | 451 | }
|
0 commit comments