Skip to content

Commit

Permalink
Merge pull request #27 from worksome/test-helper-trait
Browse files Browse the repository at this point in the history
feat: Add a new trait to help with testing with feature flags
  • Loading branch information
jeremynikolic authored Feb 23, 2022
2 parents 612b1c5 + 85d4653 commit 93f37e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Providers/LaunchDarkly/LaunchDarklyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function __construct()
{
/** @var array<string,mixed> */
$config = Config::get('feature-flags.providers.launchdarkly.options', []);

/** @var array<string,mixed> */
$options = array_merge([
'event_publisher' => Guzzle::eventPublisher()
], $config);
Expand All @@ -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);
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/Traits/InteractsWithFeatureFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Worksome\FeatureFlags\Traits;

trait InteractsWithFeatureFlags
{
public function switchFeatureFlag(string $key, bool $onOff): void
{
$this->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);
}
}

0 comments on commit 93f37e8

Please sign in to comment.