-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Fix service reset between tests #58240
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Dif 8000 f line change |
---|---|---|
|
@@ -160,6 +160,11 @@ protected static function ensureKernelShutdown() | |
static::$kernel->shutdown(); | ||
static::$booted = false; | ||
|
||
if ($container->has('services_resetter')) { | ||
// Instantiate the service because Container::reset() only resets services that have been used | ||
$container->get('services_resetter'); | ||
} | ||
|
||
if ($container instanceof ResetInterface) { | ||
$container->reset(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Btw, if you ensure that the The reason it was not called is because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof Fixed, see https://github.com/symfony/symfony/compare/549ada5257c771da92d51aff76e224e1ac5d31f4..5491aa54a3205acfaf5ba62c134bddc26d794a36 Initially, I wanted to just instantiate the The downside of the current approach is that some services will get reset twice, but I don’t see a better solution at the moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah indeed. The container resets itself before resetting the services. I think this might actually be an issue if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; | ||
|
||
class ResettableService | ||
{ | ||
private $count = 0; | ||
OskarStark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public function myCustomName(): void | ||
{ | ||
++$this->count; | ||
} | ||
|
||
public function getCount(): int | ||
{ | ||
return $this->count; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.