|
19 | 19 | FeatureFlag::reset(); |
20 | 20 | }); |
21 | 21 |
|
| 22 | +it('throws an exception if casting to a feature state that does not exist', function () { |
| 23 | + $this->expectException(\InvalidArgumentException::class); |
| 24 | + |
| 25 | + Feature::factory()->create([ |
| 26 | + 'name' => 'some-feature', |
| 27 | + 'state' => 'foo', |
| 28 | + ]); |
| 29 | +}); |
| 30 | + |
22 | 31 | it('throws an exception if calling isOn on a feature that does not exist', function () { |
23 | 32 | $this->expectException(MissingFeatureException::class); |
24 | 33 |
|
|
141 | 150 | ->and(FeatureFlag::getState('some-on-feature'))->toBe(FeatureState::on()); |
142 | 151 | }); |
143 | 152 |
|
| 153 | +it('can turn on a feature', function () { |
| 154 | + Event::fake(); |
| 155 | + |
| 156 | + Feature::factory()->create([ |
| 157 | + 'name' => 'some-feature', |
| 158 | + 'state' => FeatureState::off() |
| 159 | + ]); |
| 160 | + |
| 161 | + cache()->store('array')->set('testing.some-feature', 'off'); |
| 162 | + |
| 163 | + FeatureFlag::turnOn('some-feature'); |
| 164 | + |
| 165 | + Event::assertDispatched(FeatureUpdatedEvent::class); |
| 166 | + expect(FeatureFlag::isOn('some-feature'))->toBeTrue() |
| 167 | + ->and(FeatureFlag::isOff('some-feature'))->toBeFalse() |
| 168 | + ->and(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value); |
| 169 | +}); |
| 170 | + |
| 171 | +it('can turn off a feature', function () { |
| 172 | + Event::fake(); |
| 173 | + |
| 174 | + Feature::factory()->create([ |
| 175 | + 'name' => 'some-feature', |
| 176 | + 'state' => FeatureState::on() |
| 177 | + ]); |
| 178 | + |
| 179 | + cache()->store('array')->set('testing.some-feature', 'on'); |
| 180 | + |
| 181 | + FeatureFlag::turnOff('some-feature'); |
| 182 | + |
| 183 | + Event::assertDispatched(FeatureUpdatedEvent::class); |
| 184 | + expect(FeatureFlag::isOn('some-feature'))->toBeFalse() |
| 185 | + ->and(FeatureFlag::isOff('some-feature'))->toBeTrue() |
| 186 | + ->and(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::off()->value); |
| 187 | +}); |
| 188 | + |
| 189 | +it('can make a feature dynamic', function () { |
| 190 | + Event::fake(); |
| 191 | + |
| 192 | + Feature::factory()->create([ |
| 193 | + 'name' => 'some-feature', |
| 194 | + 'state' => FeatureState::on() |
| 195 | + ]); |
| 196 | + |
| 197 | + cache()->store('array')->set('testing.some-feature', 'on'); |
| 198 | + |
| 199 | + FeatureFlag::makeDynamic('some-feature'); |
| 200 | + |
| 201 | + Event::assertDispatched(FeatureUpdatedEvent::class); |
| 202 | + expect(FeatureFlag::isOn('some-feature'))->toBeFalse() |
| 203 | + ->and(FeatureFlag::isOff('some-feature'))->toBeTrue() |
| 204 | + ->and(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::dynamic()->value); |
| 205 | +}); |
| 206 | + |
144 | 207 | it('can update a features state', function () { |
145 | 208 | Event::fake(); |
146 | 209 |
|
|
0 commit comments