Skip to content

removeDefinition fix for removing first added one #72

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 1 commit 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
2 changes: 1 addition & 1 deletion src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function getByType($class)
return;

} elseif (count($this->classes[$class][TRUE]) === 1) {
return $this->classes[$class][TRUE][0];
return reset($this->classes[$class][TRUE]);

} else {
throw new ServiceCreationException("Multiple services of type $class found: " . implode(', ', $this->classes[$class][TRUE]));
Expand Down
4 changes: 2 additions & 2 deletions tests/DI/ContainerBuilder.removeDefinition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Assert::exception(function () use ($builder) {
Assert::count( 4, $builder->findByType('stdClass') );


$builder->removeDefinition('two');
$builder->removeDefinition('one');
$builder->removeDefinition('four');

Assert::same( 'one', $builder->getByType('stdClass') );
Assert::same( 'two', $builder->getByType('stdClass') );

Assert::count( 2, $builder->findByType('stdClass') );

Expand Down