27
27
use Symfony \Component \DependencyInjection \Reference ;
28
28
use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
29
29
use Symfony \Component \Config \Resource \FileResource ;
30
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
30
31
use Symfony \Component \ExpressionLanguage \Expression ;
31
32
32
33
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -236,6 +237,18 @@ public function testSetReplacesAlias()
236
237
$ this ->assertSame ($ foo , $ builder ->get ('alias ' ), '->set() replaces an existing alias ' );
237
238
}
238
239
240
+ public function testAliasesKeepInvalidBehavior ()
241
+ {
242
+ $ builder = new ContainerBuilder ();
243
+
244
+ $ aliased = new Definition ('stdClass ' );
245
+ $ aliased ->addMethodCall ('setBar ' , array (new Reference ('bar ' , ContainerInterface::IGNORE_ON_INVALID_REFERENCE )));
246
+ $ builder ->setDefinition ('aliased ' , $ aliased );
247
+ $ builder ->setAlias ('alias ' , 'aliased ' );
248
+
249
+ $ this ->assertEquals (new \stdClass (), $ builder ->get ('alias ' ));
250
+ }
251
+
239
252
public function testAddGetCompilerPass ()
240
253
{
241
254
$ builder = new ContainerBuilder ();
@@ -383,7 +396,7 @@ public function testResolveServices()
383
396
384
397
/**
385
398
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
386
- * @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
399
+ * @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
387
400
*/
388
401
public function testResolveServicesWithDecoratedDefinition ()
389
402
{
@@ -395,6 +408,14 @@ public function testResolveServicesWithDecoratedDefinition()
395
408
$ builder ->get ('foo ' );
396
409
}
397
410
411
+ public function testResolveServicesWithCustomDefinitionClass ()
412
+ {
413
+ $ builder = new ContainerBuilder ();
414
+ $ builder ->setDefinition ('foo ' , new CustomDefinition ('stdClass ' ));
415
+
416
+ $ this ->assertInstanceOf ('stdClass ' , $ builder ->get ('foo ' ));
417
+ }
418
+
398
419
public function testMerge ()
399
420
{
400
421
$ container = new ContainerBuilder (new ParameterBag (array ('bar ' => 'foo ' )));
0 commit comments