File tree 3 files changed +21
-2
lines changed
src/Symfony/Component/FeatureFlag
3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \FeatureFlag ;
13
13
14
14
use Symfony \Component \FeatureFlag \Provider \ProviderInterface ;
15
+ use Symfony \Contracts \Service \ResetInterface ;
15
16
16
17
/**
17
18
* @experimental
18
19
*/
19
- final class FeatureChecker implements FeatureCheckerInterface
20
+ final class FeatureChecker implements FeatureCheckerInterface, ResetInterface
20
21
{
21
22
private array $ cache = [];
22
23
@@ -40,4 +41,9 @@ public function getValue(string $featureName): mixed
40
41
41
42
return $ this ->cache [$ featureName ] = $ feature ();
42
43
}
44
+
45
+ public function reset (): void
46
+ {
47
+ $ this ->cache = [];
48
+ }
43
49
}
Original file line number Diff line number Diff line change 18
18
class FeatureCheckerTest extends TestCase
19
19
{
20
20
private FeatureChecker $ featureChecker ;
21
+ private int $ counter = 0 ;
21
22
22
23
protected function setUp (): void
23
24
{
@@ -26,6 +27,7 @@ protected function setUp(): void
26
27
'feature_false ' => fn () => false ,
27
28
'feature_integer ' => fn () => 42 ,
28
29
'feature_random ' => fn () => random_int (1 , 42 ),
30
+ 'feature_counter ' => fn () => ++$ this ->counter ,
29
31
]));
30
32
}
31
33
@@ -60,4 +62,14 @@ public static function provideIsEnabled(): iterable
60
62
yield 'an integer ' => ['feature_integer ' , false ];
61
63
yield 'an unknown feature ' => ['unknown_feature ' , false ];
62
64
}
65
+
66
+ public function testReset ()
67
+ {
68
+ $ this ->assertSame (1 , $ this ->featureChecker ->getValue ('feature_counter ' ));
69
+ $ this ->assertSame (1 , $ this ->featureChecker ->getValue ('feature_counter ' ));
70
+
71
+ $ this ->featureChecker ->reset ();
72
+
73
+ $ this ->assertSame (2 , $ this ->featureChecker ->getValue ('feature_counter ' ));
74
+ }
63
75
}
Original file line number Diff line number Diff line change 17
17
],
18
18
"require" : {
19
19
"php" : " >=8.2" ,
20
- "psr/container" : " ^1.1|^2.0"
20
+ "psr/container" : " ^1.1|^2.0" ,
21
+ "symfony/service-contracts" : " ^2.5|^3"
21
22
},
22
23
"require-dev" : {
23
24
"symfony/http-kernel" : " ^7.2" ,
You can’t perform that action at this time.
0 commit comments