|
18 | 18 | FeatureFlag::reset(); |
19 | 19 | }); |
20 | 20 |
|
21 | | -it('throws an exception if calling isOn for a feature that does not exist', function () { |
| 21 | +it('throws an exception if calling isOn on a feature that does not exist', function () { |
22 | 22 | $this->expectException(MissingFeatureException::class); |
23 | 23 |
|
24 | 24 | FeatureFlag::isOn('some-feature'); |
25 | 25 | expect(cache()->store('array')->get('testing.some-feature'))->toBeNull(); |
26 | 26 | }); |
27 | 27 |
|
| 28 | +it('throws an exception if calling isOff on a feature that does not exist', function () { |
| 29 | + $this->expectException(MissingFeatureException::class); |
| 30 | + |
| 31 | + FeatureFlag::isOff('some-feature'); |
| 32 | + expect(cache()->store('array')->get('testing.some-feature'))->toBeNull(); |
| 33 | +}); |
| 34 | + |
28 | 35 | it('generates the correct cache key', function () { |
29 | 36 | config(['feature-flags.cache_prefix' => 'some-prefix']); |
30 | 37 |
|
|
37 | 44 | }); |
38 | 45 |
|
39 | 46 | expect(FeatureFlag::isOn('some-feature'))->toBeFalse(); |
| 47 | + expect(FeatureFlag::isOff('some-feature'))->toBeTrue(); |
40 | 48 | expect(cache()->store('array')->get('testing.some-feature'))->toBeNull(); |
41 | 49 | }); |
42 | 50 |
|
|
47 | 55 | ]); |
48 | 56 |
|
49 | 57 | expect(FeatureFlag::isOn('some-feature'))->toBeFalse(); |
| 58 | + expect(FeatureFlag::isOff('some-feature'))->toBeTrue(); |
50 | 59 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::off()->value); |
51 | 60 | }); |
52 | 61 |
|
|
57 | 66 | ]); |
58 | 67 |
|
59 | 68 | expect(FeatureFlag::isOn('some-feature'))->toBeTrue(); |
| 69 | + expect(FeatureFlag::isOff('some-feature'))->toBeFalse(); |
60 | 70 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value); |
61 | 71 | }); |
62 | 72 |
|
|
71 | 81 | }); |
72 | 82 |
|
73 | 83 | expect(FeatureFlag::isOn('some-feature'))->toBeTrue(); |
| 84 | + expect(FeatureFlag::isOff('some-feature'))->toBeFalse(); |
74 | 85 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value); |
75 | 86 | }); |
76 | 87 |
|
|
85 | 96 | }); |
86 | 97 |
|
87 | 98 | expect(FeatureFlag::isOn('some-feature'))->toBeFalse(); |
| 99 | + expect(FeatureFlag::isOff('some-feature'))->toBeTrue(); |
88 | 100 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value); |
89 | 101 | }); |
90 | 102 |
|
|
99 | 111 | }); |
100 | 112 |
|
101 | 113 | expect(FeatureFlag::isOn('some-feature'))->toBeTrue(); |
| 114 | + expect(FeatureFlag::isOff('some-feature'))->toBeFalse(); |
102 | 115 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value); |
103 | 116 | }); |
104 | 117 |
|
|
109 | 122 | ]); |
110 | 123 |
|
111 | 124 | expect(FeatureFlag::isOn('some-feature'))->toBeFalse(); |
| 125 | + expect(FeatureFlag::isOff('some-feature'))->toBeTrue(); |
| 126 | +}); |
| 127 | + |
| 128 | +it('resolves the current state', function () { |
| 129 | + Feature::factory()->create([ |
| 130 | + 'name' => 'some-off-feature', |
| 131 | + 'state' => FeatureState::off() |
| 132 | + ]); |
| 133 | + Feature::factory()->create([ |
| 134 | + 'name' => 'some-dynamic-feature', |
| 135 | + 'state' => FeatureState::dynamic() |
| 136 | + ]); |
| 137 | + Feature::factory()->create([ |
| 138 | + 'name' => 'some-on-feature', |
| 139 | + 'state' => FeatureState::on() |
| 140 | + ]); |
| 141 | + |
| 142 | + expect(FeatureFlag::getState('some-off-feature'))->toBe(FeatureState::off()); |
| 143 | + expect(FeatureFlag::getState('some-dynamic-feature'))->toBe(FeatureState::dynamic()); |
| 144 | + expect(FeatureFlag::getState('some-on-feature'))->toBe(FeatureState::on()); |
112 | 145 | }); |
113 | 146 |
|
114 | 147 | it('can update a features state', function () { |
|
125 | 158 |
|
126 | 159 | Event::assertDispatched(\Codinglabs\FeatureFlags\Events\FeatureUpdatedEvent::class); |
127 | 160 | expect(FeatureFlag::isOn('some-feature'))->toBeTrue(); |
| 161 | + expect(FeatureFlag::isOff('some-feature'))->toBeFalse(); |
128 | 162 | expect(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value); |
129 | 163 | }); |
130 | 164 |
|
|
0 commit comments