Permalink
Browse files

bug #23490 [DependencyInjection] non-conflicting anonymous service id…

…s across files (xabbuh)

This PR was merged into the 3.3 branch.

Discussion
----------

[DependencyInjection] non-conflicting anonymous service ids across files

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23483
| License       | MIT
| Doc PR        |

Commits
-------

8289ca6 non-conflicting anonymous service ids across files
  • Loading branch information...
fabpot committed Jul 12, 2017
2 parents d1cfec1 + 8289ca6 commit e8b9e253e8e0f5a2af23ed5c0f864edccf999016
@@ -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));
}
}
@@ -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();
}
@@ -0,0 +1,4 @@
services:
AppBundle\Foo:
arguments:
- !service {class: AppBundle\Bar }
@@ -0,0 +1,4 @@
services:
AppBundle\Hello:
arguments:
- !service {class: AppBundle\World}
@@ -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()
{
@@ -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());
@@ -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]);
@@ -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();
@@ -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()
{
@@ -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()
{
@@ -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()
{
@@ -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()
{

0 comments on commit e8b9e25

Please sign in to comment.