Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ceabf11

Browse files
committed
bug #22564 Fixing problem where _defaults set to null was seen as a service (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
2 parents f8133cb + 4b7e148 commit ceabf11

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function parseDefinitions(array $content, $file)
205205
throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
206206
}
207207

208-
if (isset($content['services']['_instanceof'])) {
208+
if (array_key_exists('_instanceof', $content['services'])) {
209209
$instanceof = $content['services']['_instanceof'];
210210
unset($content['services']['_instanceof']);
211211

@@ -242,7 +242,7 @@ private function parseDefinitions(array $content, $file)
242242
*/
243243
private function parseDefaults(array &$content, $file)
244244
{
245-
if (!isset($content['services']['_defaults'])) {
245+
if (!array_key_exists('_defaults', $content['services'])) {
246246
return array();
247247
}
248248
$defaults = $content['services']['_defaults'];
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
services:
2+
_defaults:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
services:
2+
_instanceof:

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,28 @@ public function testAutoConfigureInstanceof()
577577
$this->assertTrue($container->getDefinition('use_defaults_settings')->isAutoconfigured());
578578
$this->assertFalse($container->getDefinition('override_defaults_settings_to_false')->isAutoconfigured());
579579
}
580+
581+
/**
582+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
583+
* @expectedExceptionMessage Service "_defaults" key must be an array, "NULL" given in "bad_empty_defaults.yml".
584+
*/
585+
public function testEmptyDefaultsThrowsClearException()
586+
{
587+
$container = new ContainerBuilder();
588+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
589+
$loader->load('bad_empty_defaults.yml');
590+
}
591+
592+
/**
593+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
594+
* @expectedExceptionMessage Service "_instanceof" key must be an array, "NULL" given in "bad_empty_instanceof.yml".
595+
*/
596+
public function testEmptyInstanceofThrowsClearException()
597+
{
598+
$container = new ContainerBuilder();
599+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
600+
$loader->load('bad_empty_instanceof.yml');
601+
}
580602
}
581603

582604
interface FooInterface

0 commit comments

Comments
 (0)