8000 [DependencyInjection] non-conflicting anonymous service ids across files by xabbuh · Pull Request #23490 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] non-conflicting anonymous service ids across files #23490

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

Merged
merged 1 commit into from
Jul 12, 2017
Merged
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
non-conflicting anonymous service ids across files
  • Loading branch information
xabbuh committed Jul 12, 2017
commit 8289ca6d1ad758cfe7843c8277cfb37f19597629
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public function load($resource, $type = null)
// parameters
if (isset($content['parameters'])) {
if (!is_array($content['parameters'])) {
throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $resource));
throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $path));
}

foreach ($content['parameters'] as $key => $value) {
$this->container->setParameter($key, $this->resolveServices($value, $resource, true));
$this->container->setParameter($key, $this->resolveServices($value, $path, true));
}
}

Expand All @@ -136,7 +136,7 @@ public function load($resource, $type = null)
$this->anonymousServicesCount = 0;
$this->setCurrentDir(dirname($path));
try {
$this->parseDefinitions($content, $resource);
$this->parseDefinitions($content, $path);
} finally {
$this->instanceof = array();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
AppBundle\Foo:
arguments:
- !service {class: AppBundle\Bar }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
AppBundle\Hello:
arguments:
- !service {class: AppBundle\World}
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function testDecoratedServicesWithWrongSyntaxThrowsException()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Parameter "tags" must be an array for service "Foo\Bar" in services31_invalid_tags.yml. Check your YAML syntax.
* @expectedExceptionMessageRegExp /Parameter "tags" must be an array for service "Foo\\Bar" in .+services31_invalid_tags\.yml\. Check your YAML syntax./
*/
public function testInvalidTagsWithDefaults()
{
Expand Down Expand Up @@ -534,7 +534,7 @@ public function testAnonymousServices()
$this->assertCount(1, $args);
$this->assertInstanceOf(Reference::class, $args[0]);
$this->assertTrue($container->has((string) $args[0]));
$this->assertStringStartsWith('2', (string) $args[0]);
$this->assertRegExp('/^\d+_[A-Za-z0-9]{64}$/', (string) $args[0]);

$anonymous = $container->getDefinition((string) $args[0]);
$this->assertEquals('Bar', $anonymous->getClass());
Expand All @@ -546,7 +546,7 @@ public function testAnonymousServices()
$this->assertInternalType('array', $factory);
$this->assertInstanceOf(Reference::class, $factory[0]);
$this->assertTrue($container->has((string) $factory[0]));
$this->assertStringStartsWith('1', (string) $factory[0]);
$this->assertRegExp('/^\d+_[A-Za-z0-9]{64}$/', (string) $factory[0]);
$this->assertEquals('constructFoo', $factory[1]);

$anonymous = $container->getDefinition((string) $factory[0]);
Expand All @@ -555,6 +555,19 @@ public function testAnonymousServices()
$this->assertFalse($anonymous->isAutowired());
}

public function testAnonymousServicesInDifferentFilesWithSameNameDoNotConflict()
{
$container = new ContainerBuilder();

$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml/foo'));
$loader->load('services.yml');

$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml/bar'));
$loader->load('services.yml');

$this->assertCount(5, $container->getDefinitions());
}

public function testAnonymousServicesInInstanceof()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -582,7 +595,7 @@ public function testAnonymousServicesInInstanceof()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Creating an alias using the tag "!service" is not allowed in "anonymous_services_alias.yml".
* @expectedExceptionMessageRegExp /Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./
*/
public function testAnonymousServicesWithAliases()
{
Expand All @@ -593,7 +606,7 @@ public function testAnonymousServicesWithAliases()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Using an anonymous service in a parameter is not allowed in "anonymous_services_in_parameters.yml".
* @expectedExceptionMessageRegExp /Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./
*/
public function testAnonymousServicesInParameters()
{
Expand All @@ -614,7 +627,7 @@ public function testAutoConfigureInstanceof()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Service "_defaults" key must be an array, "NULL" given in "bad_empty_defaults.yml".
* @expectedExceptionMessageRegExp /Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./
*/
public function testEmptyDefaultsThrowsClearException()
{
Expand All @@ -625,7 +638,7 @@ public function testEmptyDefaultsThrowsClearException()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Service "_instanceof" key must be an array, "NULL" given in "bad_empty_instanceof.yml".
* @expectedExceptionMessageRegExp /Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./
*/
public function testEmptyInstanceofThrowsClearException()
{
Expand Down
0