|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Illuminate\Support\Facades\Route; |
4 | 3 | use Codinglabs\FeatureFlags\Models\Feature; |
5 | 4 | use Codinglabs\FeatureFlags\Enums\FeatureState; |
6 | 5 | use Codinglabs\FeatureFlags\Facades\FeatureFlag; |
7 | | -use Codinglabs\FeatureFlags\Middleware\VerifyFeatureIsOn; |
| 6 | +use Codinglabs\FeatureFlags\Events\FeatureUpdatedEvent; |
8 | 7 | use Codinglabs\FeatureFlags\Exceptions\MissingFeatureException; |
9 | 8 |
|
10 | 9 | beforeEach(function () { |
|
13 | 12 | 'feature-flags.cache_prefix' => 'testing', |
14 | 13 | ]); |
15 | 14 |
|
16 | | - Route::get('test-middleware', function () { |
17 | | - return 'ok'; |
18 | | - })->middleware(VerifyFeatureIsOn::class . ':some-feature'); |
19 | | - |
20 | 15 | cache()->store('array')->clear(); |
21 | 16 | }); |
22 | 17 |
|
|
158 | 153 |
|
159 | 154 | FeatureFlag::updateFeatureState('some-feature', FeatureState::on()); |
160 | 155 |
|
161 | | - Event::assertDispatched(\Codinglabs\FeatureFlags\Events\FeatureUpdatedEvent::class); |
| 156 | + Event::assertDispatched(FeatureUpdatedEvent::class); |
162 | 157 | expect(FeatureFlag::isOn('some-feature'))->toBeTrue() |
163 | 158 | ->and(FeatureFlag::isOff('some-feature'))->toBeFalse() |
164 | 159 | ->and(cache()->store('array')->get('testing.some-feature'))->toBe(FeatureState::on()->value); |
|
171 | 166 |
|
172 | 167 | expect(config('feature-flags.cache_store'))->toBe('file'); |
173 | 168 | }); |
174 | | - |
175 | | -it('returns a 500 status when a feature does not exist', function () { |
176 | | - $this->withoutExceptionHandling(); |
177 | | - |
178 | | - $this->expectException(MissingFeatureException::class); |
179 | | - |
180 | | - $this->get('test-middleware') |
181 | | - ->assertStatus(500); |
182 | | -}); |
183 | | - |
184 | | -it('returns a 404 status when a feature is off', function () { |
185 | | - Feature::factory()->create([ |
186 | | - 'name' => 'some-feature', |
187 | | - 'state' => FeatureState::off() |
188 | | - ]); |
189 | | - |
190 | | - $this->get('test-middleware') |
191 | | - ->assertStatus(404); |
192 | | -}); |
193 | | - |
194 | | -it('returns a 404 status when a feature is dynamic', function () { |
195 | | - Feature::factory()->create([ |
196 | | - 'name' => 'some-feature', |
197 | | - 'state' => FeatureState::dynamic() |
198 | | - ]); |
199 | | - |
200 | | - $this->get('test-middleware') |
201 | | - ->assertStatus(404); |
202 | | -}); |
203 | | - |
204 | | -it('returns an ok status when a feature is dynamic and enabled', function () { |
205 | | - Feature::factory()->create([ |
206 | | - 'name' => 'some-feature', |
207 | | - 'state' => FeatureState::dynamic() |
208 | | - ]); |
209 | | - |
210 | | - FeatureFlag::registerDynamicHandler('some-feature', fn ($feature) => true); |
211 | | - |
212 | | - $this->get('test-middleware') |
213 | | - ->assertOk(); |
214 | | -}); |
215 | | - |
216 | | -it('returns an ok status when a feature is on', function () { |
217 | | - Feature::factory()->create([ |
218 | | - 'name' => 'some-feature', |
219 | | - 'state' => FeatureState::on() |
220 | | - ]); |
221 | | - |
222 | | - $this->get('test-middleware') |
223 | | - ->assertOk(); |
224 | | -}); |
0 commit comments