From 85d4653da529f0c1775b5fd543df4d89c68b5b2c Mon Sep 17 00:00:00 2001 From: Jeremy Nikolic Date: Fri, 18 Feb 2022 13:34:05 +0100 Subject: [PATCH] feat: Add a new trait to help with testing with feature flags Implement InteractsWithFeatureFlags trait to help with testing with feature flags --- .../LaunchDarkly/LaunchDarklyProvider.php | 3 +++ src/Traits/InteractsWithFeatureFlags.php | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Traits/InteractsWithFeatureFlags.php diff --git a/src/Providers/LaunchDarkly/LaunchDarklyProvider.php b/src/Providers/LaunchDarkly/LaunchDarklyProvider.php index 0b85e80..e8fd130 100644 --- a/src/Providers/LaunchDarkly/LaunchDarklyProvider.php +++ b/src/Providers/LaunchDarkly/LaunchDarklyProvider.php @@ -24,6 +24,8 @@ public function __construct() { /** @var array */ $config = Config::get('feature-flags.providers.launchdarkly.options', []); + + /** @var array */ $options = array_merge([ 'event_publisher' => Guzzle::eventPublisher() ], $config); @@ -32,6 +34,7 @@ public function __construct() $key = Config::get('feature-flags.providers.launchdarkly.key'); if ($key) { + /** @phpstan-ignore-next-line */ $this->client = new LDClient($key, $options); } } diff --git a/src/Traits/InteractsWithFeatureFlags.php b/src/Traits/InteractsWithFeatureFlags.php new file mode 100644 index 0000000..f1ae1e8 --- /dev/null +++ b/src/Traits/InteractsWithFeatureFlags.php @@ -0,0 +1,25 @@ +app['config']->set('feature-flags.overrides.'.$key, $onOff); + } + + public function enableFeatureFlag(string $key): void + { + + $this->switchFeatureFlag($key, true); + } + + public function disableFeatureFlag(string $key): void + { + + $this->switchFeatureFlag($key, false); + } +}