8000 [DependencyInjection] Fix typo in test name by signor-pedro · Pull Request #35507 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Fix typo in test name #35507

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

Conversation

signor-pedro
Copy link
Contributor

Rename testThrowsExceptionWhenAddServiceOnACompiledContainer to testNoExceptionWhenAddServiceOnACompiledContainer.

Q A
Branch? 3.4
Bug fix? yes (technically)
New feature? no
Deprecations? no
Tickets #35505
License MIT
Doc PR symfony/symfony-docs#...

Rename testThrowsExceptionWhenAddServiceOnACompiledContainer to testNoExceptionWhenAddServiceOnACompiledContainer.
@Nyholm
Copy link
Member
Nyholm commented Jan 29, 2020

Thank you for this PR.

Here is the code for ContainerBuilder::set:

public function set(string $id, ?object $service)
{
    if ($this->isCompiled() && (isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())) {
        // setting a synthetic service on a compiled container is alright
        throw new BadMethodCallException(sprintf('Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed.', $id));
    }
    // ...

I think there are more things that are not correct here. The exception message is

Setting service "%s" for an unknown or non-synthetic service definition on a compiled container is not allowed

So currently, If the container is compiled:

  • We can set a new service
  • We can set a defined service if it is synthetic
  • We cannot set a defined service if it is non-synthetic

I would like someone to confirm the correct logic.

If the current logic is correct, I believe the exception message should be updated too. IE:

Service "%s" is defined as non-synthetic and it cannot be updated with a service on a compiled container.

@signor-pedro
Copy link
Contributor Author
signor-pedro commented Jan 30, 2020

I am in favour of updating the exception message:

  1. I find your wording a bit more natural
  2. since you can do this:
$container = new ContainerBuilder();
$container->compile();
$container->set('foo', new \stdClass()); // this was set normally

I find the word "unknown" in the current message confusing - if the definition is unknown, you are simply setting a new service.

By the way, if the definition is known, you are setting the service anyways

$container = new ContainerBuilder();
$container->setDefinition('foo', new Definition(\stdClass::class));
$container->compile();
$container->set('foo', new MyClass()); // this was set normally

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jan 31, 2020
Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Please submit any improved messages to the master branch.

@nicolas-grekas nicolas-grekas changed the title [DependencyInjection] #35505 Fix typo in test name [DependencyInjection] Fix typo in test name Feb 3, 2020
@nicolas-grekas
Copy link
Member

Thank you @signor-pedro.

nicolas-grekas added a commit that referenced this pull request Feb 3, 2020
This PR was merged into the 3.4 branch.

Discussion
----------

[DependencyInjection] Fix typo in test name

Rename testThrowsExceptionWhenAddServiceOnACompiledContainer to testNoExceptionWhenAddServiceOnACompiledContainer.

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes (technically)
| New feature?  | no
| Deprecations? | no
| Tickets       | #35505
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Commits
-------

9cbfad5 [DependencyInjection] #35505 Fix typo in test name
@nicolas-grekas nicolas-grekas merged commit 9cbfad5 into symfony:3.4 Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0