-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Deprecate (un)setting pre-defined services #21533
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
Conversation
@@ -190,7 +190,14 @@ public function set($id, $service) | |||
@trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); | |||
unset($this->privates[$id]); | |||
} else { | |||
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0. A new public service will be created instead.', $id), E_USER_DEPRECATED); | |||
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this tail:
A new public service will be created instead.
it's not obvious to me that this will be the behavior we should implement in 4.0 :)
bcb4b45
to
90eb386
Compare
Shouldnt we deprecate the |
That's the point of this PR: #19668 is deprecating much more than technically required to enhance the dumped containers in 4.0. In fact, even if I listen to the "best practice" arguments in #19668, we know that forbidding altogether not-best-practices can break legitimate edge-case use cases (remember the deprecation of "get" in non dumped containers that we reverted). Thus, I'm not sure at all we should merge #19668 - but I'm sure we should merge this one, because it will make SF4 better at the technical level. |
90eb386
to
fdb2140
Compare
👍 |
Thank you @nicolas-grekas. |
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Deprecate (un)setting pre-defined services | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | #19192 | License | MIT | Doc PR | - This PR is the subset of #19668 that fixes #19192: it deprecates (un)setting pre-defined services. This opens the path to some optimizations in the dumped container in 4.0. Commits ------- fdb2140 [DI] Deprecate (un)setting pre-defined services
I am testing SF 3.3BETA1 and I've got a trouble with that Pull Request:
When I try to replace Service with
What is my solution for this kind of functional tests ? Thanks for the answer. |
By loading dedicated config files in your tests? See https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolClearCommandTest.php https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePoolClear for inspiration |
@xkobal injecting a PHPUnit mock to replace a service instance is a very fragile setup: if any other services depending on this service got instantiated already before your |
The config approach is indeed much stronger. I also used to mock services with the |
I'm agree with you on that point, and I'll change my tests, but, thats a way to test services, very very used on a lot of project ! It'll be a painful point for a lot of projects to upgrade to SF 3.3 Thanks for your answers. |
Note that you don't need to fix the deprecations when moving to 3.3. |
I never upgrade a project letting some deprecations, our CI is failing on phpunit tests when there are some deprecations, but that's our choice, others can ignore them. |
Well, you can mark these tests as |
…rvices (ro0NL) This PR was merged into the 4.0-dev branch. Discussion ---------- [DI] Removed deprecated setting private/pre-defined services | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> See #21533, #19708 and #19146 @nicolas-grekas privates should be excluded from `getServiceIds` right? i also wondered.. did we forget to deprecate checking privates with `initialized()`? Commits ------- 9f96952 [DI] Removed deprecated setting private/pre-defined services
This is going to be difficult for my use case -- I replace guzzle clients with guzzle mock handlers loaded with responses (per test), and I validate both the response and the request made. @chalasr "use config files" assumes that a service can be reconfigured (or replaced) by way of configuration alone, and also that tests can all use the same configuration. @stof We're talking about testing here -- tests are supposed to be fragile. This isn't looking good. Am I going to have to forgo booting a kernel and just build my services by hand before testing them? Or, perhaps, I create intermediary objects that can know how to replace themselves on demand? Either way, I have to take over work that I could previously count on my framework to do. |
Please open an issue to discuss this. |
I'm adding a comment to #23311. |
You should open a new issue really. Comments on closed tickets aren't tracked. |
This PR is the subset of #19668 that fixes #19192: it deprecates (un)setting pre-defined services.
This opens the path to some optimizations in the dumped container in 4.0.