Skip to content

Commit a793ab5

Browse files
committed
rename isEnabled to isOn
1 parent 83a1988 commit a793ab5

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ FeatureState::dynamic()
9595
```php
9696
use Codinglabs\FeatureFlags\Facades\FeatureFlag;
9797

98-
if (FeatureFlag::isEnabled('search-v2')) {
98+
if (FeatureFlag::isOn('search-v2')) {
9999
// new feature code
100100
} else {
101101
// old code
@@ -178,7 +178,7 @@ If a handler for missing features has been defined then an exception will **not*
178178
Inertia::share([
179179
'features' => function () {
180180
return collect(config('app.features'))
181-
->filter(fn ($feature) => FeatureFlag::isEnabled($feature['name']))
181+
->filter(fn ($feature) => FeatureFlag::isOn($feature['name']))
182182
->pluck('name');
183183
}
184184
]);

config/feature-flags.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
| feature. You can also configure a prefix for all keys in the cache.
1212
*/
1313

14-
'cache_store' => env('FEATURES_CACHE_STORE'),
14+
'cache_store' => env('FEATURES_CACHE_STORE', config('cache.default')),
15+
1516
'cache_prefix' => 'features',
1617

1718
/*

src/Facades/FeatureFlag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @see \Codinglabs\FeatureFlags\FeatureFlags
1010
*
11-
* @method static bool isEnabled(string $feature)
11+
* @method static bool isOn(string $feature)
1212
* @method static void updateFeatureState(string $feature, FeatureState $state)
1313
* @method static void turnOn(string $feature)
1414
* @method static void turnOff(string $feature)

src/FeatureFlags.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FeatureFlags
1818

1919
private static function cache(): Repository
2020
{
21-
return Cache::store(config('feature-flags.cache_store'));
21+
return Cache::store(config('feature-flags.cache_store', config('cache.default')));
2222
}
2323

2424
public static function getFeatureCacheKey(string $feature): string
@@ -69,7 +69,7 @@ public static function handleMissingFeatureWith(Closure $closure): void
6969
self::$handleMissingFeatureClosure = $closure;
7070
}
7171

72-
public static function isEnabled(string $feature): bool
72+
public static function isOn(string $feature): bool
7373
{
7474
return match (self::getState($feature)) {
7575
FeatureState::on() => true,

src/FeatureFlagsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function packageRegistered()
2727
public function packageBooted()
2828
{
2929
Blade::if('feature', function ($value) {
30-
return FeatureFlag::isEnabled($value);
30+
return FeatureFlag::isOn($value);
3131
});
3232
}
3333
}

tests/FeaturesTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
FeatureFlag::reset();
1919
});
2020

21-
it('throws an exception if calling isEnabled for a feature that does not exist', function () {
21+
it('throws an exception if calling isOn for a feature that does not exist', function () {
2222
$this->expectException(MissingFeatureException::class);
2323

24-
FeatureFlag::isEnabled('some-feature');
24+
FeatureFlag::isOn('some-feature');
2525
expect(cache()->store('array')->get('testing.some-feature'))->toBeNull();
2626
});
2727

@@ -36,31 +36,31 @@
3636
// handling...
3737
});
3838

39-
expect(FeatureFlag::isEnabled('some-feature'))->toBeFalse();
39+
expect(FeatureFlag::isOn('some-feature'))->toBeFalse();
4040
expect(cache()->store('array')->get('testing.some-feature'))->toBeNull();
4141
});
4242

43-
it('resolves isEnabled to false when the features state is "off"', function () {
43+
it('resolves isOn to false when the features state is "off"', function () {
4444
Feature::factory()->create([
4545
'name' => 'some-feature',
4646
'state' => FeatureState::off()
4747
]);
4848

49-
expect(FeatureFlag::isEnabled('some-feature'))->toBeFalse();
49+
expect(FeatureFlag::isOn('some-feature'))->toBeFalse();
5050
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::off()->value);
5151
});
5252

53-
it('resolves isEnabled to true when the features state is "on"', function () {
53+
it('resolves isOn to true when the features state is "on"', function () {
5454
Feature::factory()->create([
5555
'name' => 'some-feature',
5656
'state' => FeatureState::on()
5757
]);
5858

59-
expect(FeatureFlag::isEnabled('some-feature'))->toBeTrue();
59+
expect(FeatureFlag::isOn('some-feature'))->toBeTrue();
6060
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value);
6161
});
6262

63-
it('resolves isEnabled to true when feature state is "restricted" and the closure returns true', function () {
63+
it('resolves isOn to true when feature state is "dynamic" and the closure returns true', function () {
6464
Feature::factory()->create([
6565
'name' => 'some-feature',
6666
'state' => FeatureState::dynamic(),
@@ -70,11 +70,11 @@
7070
return true;
7171
});
7272

73-
expect(FeatureFlag::isEnabled('some-feature'))->toBeTrue();
73+
expect(FeatureFlag::isOn('some-feature'))->toBeTrue();
7474
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value);
7575
});
7676

77-
it('resolves isEnabled to false when feature state is "restricted" and the closure returns false', function () {
77+
it('resolves isOn to false when feature state is "dynamic" and the closure returns false', function () {
7878
Feature::factory()->create([
7979
'name' => 'some-feature',
8080
'state' => FeatureState::dynamic(),
@@ -84,11 +84,11 @@
8484
return false;
8585
});
8686

87-
expect(FeatureFlag::isEnabled('some-feature'))->toBeFalse();
87+
expect(FeatureFlag::isOn('some-feature'))->toBeFalse();
8888
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value);
8989
});
9090

91-
it('uses the default restricted closure if no feature specific closure has been defined', function () {
91+
it('uses the default dynamic closure if no feature specific closure has been defined', function () {
9292
Feature::factory()->create([
9393
'name' => 'some-feature',
9494
'state' => FeatureState::dynamic(),
@@ -98,17 +98,17 @@
9898
return true;
9999
});
100100

101-
expect(FeatureFlag::isEnabled('some-feature'))->toBeTrue();
101+
expect(FeatureFlag::isOn('some-feature'))->toBeTrue();
102102
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value);
103103
});
104104

105-
it('resolves isEnabled to false when feature state is "restricted" and no restricted closure has been defined', function () {
105+
it('resolves isOn to false when feature state is "dynamic" and no dynamic closure has been defined', function () {
106106
Feature::factory()->create([
107107
'name' => 'some-feature',
108108
'state' => FeatureState::dynamic(),
109109
]);
110110

111-
expect(FeatureFlag::isEnabled('some-feature'))->toBeFalse();
111+
expect(FeatureFlag::isOn('some-feature'))->toBeFalse();
112112
});
113113

114114
it('can update a features state', function () {
@@ -124,6 +124,14 @@
124124
FeatureFlag::updateFeatureState('some-feature', FeatureState::on());
125125

126126
Event::assertDispatched(\Codinglabs\FeatureFlags\Events\FeatureUpdatedEvent::class);
127-
expect(FeatureFlag::isEnabled('some-feature'))->toBeTrue();
127+
expect(FeatureFlag::isOn('some-feature'))->toBeTrue();
128128
expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value);
129129
});
130+
131+
it('uses the default cache store when cache store has not been set', function() {
132+
config(['cache.default' => 'file']);
133+
134+
config(['feature-flags.cache_store' => env('FEATURES_CACHE_STORE', config('cache.default'))]);
135+
136+
expect(config('feature-flags.cache_store'))->toBe('file');
137+
});

0 commit comments

Comments
 (0)