8000 [DI] Overriding services autowired by name under _defaults bind not working by przemyslaw-bogusz · Pull Request #29944 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Overriding services autowired by name under _defaults bind not working #29944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
more tests
  • Loading branch information
renanbr authored and nicolas-grekas committed Apr 12, 2019
commit 7e805eae2bb29745d735c41678a7ba16eec1903d
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

class Bar implements BarInterface
{
public $quz;

public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [])
{
$this->quz = $quz;
}

public static function create(\NonExistent $nonExistent = null, $factory = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults>
<bind key="$quz">value</bind>
<bind key="$foo" type="collection">
<bind>value</bind>
</bind>
</defaults>

<service id="bar" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar"/>

<service id="foo" class="stdClass"/>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults>
<bind key="$quz">overridden</bind>
</defaults>

<service id="bar" class="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar"/>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar

foo:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy
class: stdClass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
_defaults:
bind:
$quz: ~
$quz: overridden

bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
Expand Down Expand Up @@ -820,4 +821,20 @@ public function testTsantosContainer()
$dump = $dumper->dump();
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_tsantos.php', $dumper->dump());
}

/**
* The pass may throw an exception, which will cause the test to fail.
*/
public function testOverriddenDefaultsBindings()
{
$container = new ContainerBuilder();

$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('defaults_bindings.xml');
$loader->load('defaults_bindings2.xml');

(new ResolveBindingsPass())->process($container);

$this->assertSame('overridden', $container->get('bar')->quz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,6 @@ public function testOverriddenDefaultsBindings()

(new ResolveBindingsPass())->process($container);

$this->assertTrue(true);
$this->assertSame('overridden', $container->get('bar')->quz);
}
}
0