29
29
use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
30
30
use Symfony \Component \DependencyInjection \Scope ;
31
31
use Symfony \Component \Config \Resource \FileResource ;
32
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
32
33
use Symfony \Component \ExpressionLanguage \Expression ;
33
34
34
35
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -257,6 +258,18 @@ public function testSetReplacesAlias()
257
258
$ this ->assertSame ($ foo , $ builder ->get ('alias ' ), '->set() replaces an existing alias ' );
258
259
}
259
260
261
+ public function testAliasesKeepInvalidBehavior ()
262
+ {
263
+ $ builder = new ContainerBuilder ();
264
+
265
+ $ aliased = new Definition ('stdClass ' );
266
+ $ aliased ->addMethodCall ('setBar ' , array (new Reference ('bar ' , ContainerInterface::IGNORE_ON_INVALID_REFERENCE )));
267
+ $ builder ->setDefinition ('aliased ' , $ aliased );
268
+ $ builder ->setAlias ('alias ' , 'aliased ' );
269
+
270
+ $ this ->assertEquals (new \stdClass (), $ builder ->get ('alias ' ));
271
+ }
272
+
260
273
public function testAddGetCompilerPass ()
261
274
{
262
275
$ builder = new ContainerBuilder ();
@@ -433,7 +446,7 @@ public function testResolveServices()
433
446
434
447
/**
435
448
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
436
- * @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
449
+ * @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
437
450
*/
438
451
public function testResolveServicesWithDecoratedDefinition ()
439
452
{
@@ -445,6 +458,14 @@ public function testResolveServicesWithDecoratedDefinition()
445
458
$ builder ->get ('foo ' );
446
459
}
447
460
461
+ public function testResolveServicesWithCustomDefinitionClass ()
462
+ {
463
+ $ builder = new ContainerBuilder ();
464
+ $ builder ->setDefinition ('foo ' , new CustomDefinition ('stdClass ' ));
465
+
466
+ $ this ->assertInstanceOf ('stdClass ' , $ builder ->get ('foo ' ));
467
+ }
468
+
448
469
public function testMerge ()
449
470
{
450
471
$ container = new ContainerBuilder (new ParameterBag (array ('bar ' => 'foo ' )));
0 commit comments