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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
services:
_defaults:
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
services:
_instanceof:
Original file line number Diff line number Diff line change
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