Skip to content

Commit

Permalink
Fixing problem where _defaults set to null was seen as a service
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan authored and stof committed Apr 29, 2017
1 parent 9d9f628 commit 4b7e148
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Expand Up @@ -205,7 +205,7 @@ private function parseDefinitions(array $content, $file)
throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
}

if (isset($content['services']['_instanceof'])) {
if (array_key_exists('_instanceof', $content['services'])) {
$instanceof = $content['services']['_instanceof'];
unset($content['services']['_instanceof']);

Expand Down Expand Up @@ -242,7 +242,7 @@ private function parseDefinitions(array $content, $file)
*/
private function parseDefaults(array &$content, $file)
{
if (!isset($content['services']['_defaults'])) {
if (!array_key_exists('_defaults', $content['services'])) {
return array();
}
$defaults = $content['services']['_defaults'];
Expand Down
@@ -0,0 +1,2 @@
services:
_defaults:
@@ -0,0 +1,2 @@
services:
_instanceof:
Expand Up @@ -577,6 +577,28 @@ public function testAutoConfigureInstanceof()
$this->assertTrue($container->getDefinition('use_defaults_settings')->isAutoconfigured());
$this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->isAutoconfigured());
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Service "_defaults" key must be an array, "NULL" given in "bad_empty_defaults.yml".
*/
public function testEmptyDefaultsThrowsClearException()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_defaults.yml');
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Service "_instanceof" key must be an array, "NULL" given in "bad_empty_instanceof.yml".
*/
public function testEmptyInstanceofThrowsClearException()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_instanceof.yml');
}
}

interface FooInterface
Expand Down

0 comments on commit 4b7e148

Please sign in to comment.