diff --git a/tests/FeaturesTest.php b/tests/FeaturesTest.php index cd3ff51..cb2ee50 100644 --- a/tests/FeaturesTest.php +++ b/tests/FeaturesTest.php @@ -1,8 +1,10 @@ 'testing', ]); + Route::get('test-middleware', function () { + return 'ok'; + })->middleware(VerifyFeatureIsOn::class . ':some-feature'); + cache()->store('array')->clear(); }); @@ -76,9 +82,7 @@ 'state' => FeatureState::dynamic(), ]); - FeatureFlag::registerDynamicHandler('some-feature', function ($feature) { - return true; - }); + FeatureFlag::registerDynamicHandler('some-feature', fn ($feature) => true); expect(FeatureFlag::isOn('some-feature'))->toBeTrue() ->and(FeatureFlag::isOff('some-feature'))->toBeFalse() @@ -91,9 +95,7 @@ 'state' => FeatureState::dynamic(), ]); - FeatureFlag::registerDynamicHandler('some-feature', function ($feature) { - return false; - }); + FeatureFlag::registerDynamicHandler('some-feature', fn ($feature) => false); expect(FeatureFlag::isOn('some-feature'))->toBeFalse() ->and(FeatureFlag::isOff('some-feature'))->toBeTrue() @@ -169,3 +171,54 @@ expect(config('feature-flags.cache_store'))->toBe('file'); }); + +it('returns a 500 status when a feature does not exist', function () { + $this->withoutExceptionHandling(); + + $this->expectException(MissingFeatureException::class); + + $this->get('test-middleware') + ->assertStatus(500); +}); + +it('returns a 404 status when a feature is off', function () { + Feature::factory()->create([ + 'name' => 'some-feature', + 'state' => FeatureState::off() + ]); + + $this->get('test-middleware') + ->assertStatus(404); +}); + +it('returns a 404 status when a feature is dynamic', function () { + Feature::factory()->create([ + 'name' => 'some-feature', + 'state' => FeatureState::dynamic() + ]); + + $this->get('test-middleware') + ->assertStatus(404); +}); + +it('returns an ok status when a feature is dynamic and enabled', function () { + Feature::factory()->create([ + 'name' => 'some-feature', + 'state' => FeatureState::dynamic() + ]); + + FeatureFlag::registerDynamicHandler('some-feature', fn ($feature) => true); + + $this->get('test-middleware') + ->assertOk(); +}); + +it('returns an ok status when a feature is on', function () { + Feature::factory()->create([ + 'name' => 'some-feature', + 'state' => FeatureState::on() + ]); + + $this->get('test-middleware') + ->assertOk(); +});