8000 [DI] Fix circular-aliases message by nicolas-grekas · Pull Request #25382 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Fix circular-aliases message #25382

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
Dec 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -998,10 +998,14 @@ public function findDefinition($id)
$id = (string) $this->aliasDefinitions[$id];

if (isset($seen[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($seen));
$seen = array_values($seen);
$seen = array_slice($seen, array_search($id, $seen));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the slicing part is not covered by the test (as the tests cover only the case where the loop starts at the beginning of the list).
Can you add another test covering this ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test updated

$seen[] = $id;

throw new ServiceCircularReferenceException($id, $seen);
}

$seen[$id] = true;
$seen[$id] = $id;
}

return $this->getDefinition($id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,18 +1046,19 @@ public function testInlinedDefinitions()

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
* @expectedExceptionMessage Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass".
* @expectedExceptionMessage Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass -> app.test_class".
*/
public function testThrowsCircularExceptionForCircularAliases()
{
$builder = new ContainerBuilder();

$builder->setAliases(array(
'foo' => new Alias('app.test_class'),
'app.test_class' => new Alias('App\\TestClass'),
'App\\TestClass' => new Alias('app.test_class'),
));

$builder->findDefinition('App\\TestClass');
$builder->findDefinition('foo');
}

public function testInitializePropertiesBeforeMethodCalls()
Expand Down
0