Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renanbr authored and nicolas-grekas committed Apr 12, 2019
1 parent 35a40ac commit 1ad8e81
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
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
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

echo new \Exception();
/**
class FactoryDummy extends FactoryParent
{
public static function createFactory(): FactoryDummy
Expand Down Expand Up @@ -42,3 +44,4 @@ class FactoryParent
function factoryFunction(): FactoryDummy
{
}
*/
@@ -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="Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy"/>
</services>
</container>
@@ -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>
@@ -1,7 +1,7 @@
services:
_defaults:
bind:
$quz: ~
$quz: overridden

bar:
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Bar
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);
}
}
Expand Up @@ -747,6 +747,6 @@ public function testOverriddenDefaultsBindings()

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

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

0 comments on commit 1ad8e81

Please sign in to comment.