File tree 5 files changed +50
-1
lines changed
Bundle/TestBundle/TestServiceContainer
Component/DependencyInjection
5 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,11 @@ protected static function ensureKernelShutdown()
160
160
static ::$ kernel ->shutdown ();
161
161
static ::$ booted = false ;
162
162
163
+ if ($ container ->has ('services_resetter ' )) {
164
+ // Instantiate the service because Container::reset() only resets services that have been used
165
+ $ container ->get ('services_resetter ' );
166
+ }
167
+
163
168
if ($ container instanceof ResetInterface) {
164
169
$ container ->reset ();
165
170
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer ;
13
+
14
+ class ResettableService
15
+ {
16
+ private $ count = 0 ;
17
+
18
+ public function myCustomName (): void
19
+ {
20
+ ++$ this ->count ;
21
+ }
22
+
23
+ public function getCount (): int
24
+ {
25
+ return $ this ->count ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 15
15
use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer \NonPublicService ;
16
16
use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer \PrivateService ;
17
17
use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer \PublicService ;
18
+ use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer \ResettableService ;
18
19
use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \TestBundle \TestServiceContainer \UnusedPrivateService ;
19
20
use Symfony \Component \DependencyInjection \ContainerInterface ;
20
21
@@ -41,4 +42,14 @@ public function testThatPrivateServicesAreAvailableIfTestConfigIsEnabled()
41
42
$ this ->assertTrue ($ container ->has ('private_service ' ));
42
43
$ this ->assertFalse ($ container ->has (UnusedPrivateService::class));
43
44
}
45
+
46
+ public function testServicesAreResetOnEnsureKernelShutdown ()
47
+ {
48
+ static ::bootKernel (['test_case ' => 'TestServiceContainer ' ]);
49
+
50
+ $ resettableService = static ::getContainer ()->get (ResettableService::class);
51
+
52
+ self ::ensureKernelShutdown ();
53
+ self ::assertSame (1 , $ resettableService ->getCount ());
54
+ }
44
55
}
Original file line number Diff line number Diff line change @@ -13,3 +13,8 @@ services:
13
13
arguments :
14
14
- ' @Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService'
15
15
- ' @Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService'
16
+
17
+ Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\ResettableService :
18
+ public : true
19
+ tags :
20
+ - kernel.reset : { method: 'myCustomName' }
Original file line number Diff line number Diff line change @@ -299,7 +299,6 @@ public function initialized(string $id)
299
299
public function reset ()
300
300
{
301
301
$ services = $ this ->services + $ this ->privates ;
302
- $ this ->services = $ this ->factories = $ this ->privates = [];
303
302
304
303
foreach ($ services as $ service ) {
305
304
try {
@@ -310,6 +309,8 @@ public function reset()
310
309
continue ;
311
310
}
312
311
}
312
+
313
+ $ this ->services = $ this ->factories = $ this ->privates = [];
313
314
}
314
315
315
316
/**
You can’t perform that action at this time.
0 commit comments