more tests

This commit is contained in:
renanbr 2019-04-12 14:54:30 +02:00 committed by Nicolas Grekas
parent 35a40ace6f
commit 7e805eae2b
7 changed files with 48 additions and 3 deletions

View File

@ -13,8 +13,11 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
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)

View File

@ -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>

View File

@ -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>

View File

@ -8,4 +8,4 @@ services:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
foo:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy
class: stdClass

View File

@ -1,7 +1,7 @@
services:
_defaults:
bind:
$quz: ~
$quz: overridden
bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar

View File

@ -17,6 +17,7 @@ use Symfony\Component\Config\Loader\LoaderResolver;
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;
@ -820,4 +821,20 @@ class XmlFileLoaderTest extends TestCase
$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);
}
}

View File

@ -747,6 +747,6 @@ class YamlFileLoaderTest extends TestCase
(new ResolveBindingsPass())->process($container);
$this->assertTrue(true);
$this->assertSame('overridden', $container->get('bar')->quz);
}
}