Skip to content

Commit

Permalink
bug #22564 Fixing problem where _defaults set to null was seen as a s…
Browse files Browse the repository at this point in the history
…ervice (weaverryan)

This PR was squashed before being merged into the 3.3-dev branch (closes #22564).

Discussion
----------

Fixing problem where _defaults set to null was seen as a service

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

```yml
services:
    _defaults:
```

If you leave `_defaults` empty (i.e. null), you got a bad error before. Now it's better :)

Before:
>The definition for "_defaults" has no class. If you intend to inject this service dynamicall
  y at runtime, please mark it as synthetic=true. If this is an abstract definition solely use
  d by child definitions, please add abstract=true, otherwise specify a class to get rid of th
  is error.

After:
> Service "_defaults" key must be an array, "NULL" given in "/path/to/services.yml"

Commits
-------

4b7e148 Fixing problem where _defaults set to null was seen as a service
  • Loading branch information
stof committed Apr 29, 2017
2 parents f8133cb + 4b7e148 commit ceabf11
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 ceabf11

Please sign in to comment.