File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 33namespace YlsIdeas \FeatureFlags \Facades ;
44
55use Illuminate \Support \Facades \Facade ;
6+ use Illuminate \Support \Testing \Fakes \Fake ;
67use YlsIdeas \FeatureFlags \Contracts \Features as FeaturesContract ;
78use YlsIdeas \FeatureFlags \Support \FeatureFake ;
89
@@ -44,7 +45,11 @@ class Features extends Facade
4445 */
4546 public static function fake (array $ flagsToFake = []): FeatureFake
4647 {
47- static ::swap ($ fake = new FeatureFake (static ::getFacadeRoot (), $ flagsToFake ));
48+ $ manager = static ::isFake ()
49+ ? static ::getFacadeRoot ()->manager
50+ : static ::getFacadeRoot ();
51+
52+ static ::swap ($ fake = new FeatureFake ($ manager , $ flagsToFake ));
4853
4954 return $ fake ;
5055 }
Original file line number Diff line number Diff line change @@ -109,15 +109,13 @@ protected function schedulingMacros()
109109 /** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
110110 Event::macro ('skipWithoutFeature ' , fn (string $ feature ): Event =>
111111 /** @var Event $this */
112- /** @phpstan-ignore-next-line annoying issue with macros */
113112 $ this ->skip (fn () => ! Features::accessible ($ feature )));
114113 }
115114
116115 if (! Event::hasMacro ('skipWithFeature ' )) {
117116 /** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
118117 Event::macro ('skipWithFeature ' , fn ($ feature ): Event =>
119118 /** @var Event $this */
120- /** @phpstan-ignore-next-line annoying issue with macros */
121119 $ this ->skip (fn () => Features::accessible ($ feature )));
122120 }
123121 }
Original file line number Diff line number Diff line change 44
55use Illuminate \Support \Arr ;
66use Illuminate \Support \Facades \Event ;
7+ use Illuminate \Support \Testing \Fakes \Fake ;
78use Illuminate \Support \Traits \ForwardsCalls ;
89use PHPUnit \Framework \Assert ;
910use YlsIdeas \FeatureFlags \Contracts \Features ;
1415/**
1516 * @see \YlsIdeas\FeatureFlags\Tests\Support\FeatureFakeTest
1617 */
17- class FeatureFake implements Features
18+ class FeatureFake implements Features, Fake
1819{
1920 use ForwardsCalls;
2021
@@ -23,7 +24,7 @@ class FeatureFake implements Features
2324 /**
2425 * @param array<string, bool|array> $featureFlags
2526 */
26- public function __construct (protected Manager $ manager , protected array $ featureFlags = [])
27+ public function __construct (public Manager $ manager , protected array $ featureFlags = [])
2728 {
2829 }
2930
Original file line number Diff line number Diff line change @@ -148,6 +148,14 @@ public function test_it_fires_events_still()
148148 Event::assertDispatched (FeatureAccessed::class);
149149 }
150150
151+ public function test_it_can_switch_a_feature_multiple_times ()
152+ {
153+ Features::fake (['my-feature ' => true ]);
154+ Features::fake (['my-feature ' => false ]);
155+
156+ $ this ->assertFalse (Features::accessible ('my-feature ' ));
157+ }
158+
151159 protected function getFake ($ manager , $ features )
152160 {
153161 return new class ($ manager , $ features ) extends FeatureFake {
You can’t perform that action at this time.
0 commit comments