|
110 | 110 | 'name' => 'some-other-feature', |
111 | 111 | ]); |
112 | 112 | }); |
| 113 | + |
| 114 | +it('overrides the state when the always on config is used and the environment matches', function () { |
| 115 | + app()->detectEnvironment(fn () => 'staging'); |
| 116 | + |
| 117 | + config([ |
| 118 | + 'feature-flags.features' => [ |
| 119 | + 'some-feature' => FeatureState::on(), |
| 120 | + 'some-other-feature' => FeatureState::off(), |
| 121 | + 'some-dynamic-feature' => FeatureState::dynamic(), |
| 122 | + ], |
| 123 | + 'feature-flags.always_on' => ['staging'], |
| 124 | + ]); |
| 125 | + |
| 126 | + (new SyncFeaturesAction)->__invoke(); |
| 127 | + |
| 128 | + $this->assertDatabaseCount('features', 3); |
| 129 | + |
| 130 | + $this->assertDatabaseHas('features', [ |
| 131 | + 'name' => 'some-feature', |
| 132 | + 'state' => FeatureState::on(), |
| 133 | + ]); |
| 134 | + |
| 135 | + $this->assertDatabaseHas('features', [ |
| 136 | + 'name' => 'some-other-feature', |
| 137 | + 'state' => FeatureState::on(), |
| 138 | + ]); |
| 139 | + |
| 140 | + $this->assertDatabaseHas('features', [ |
| 141 | + 'name' => 'some-dynamic-feature', |
| 142 | + 'state' => FeatureState::on(), |
| 143 | + ]); |
| 144 | +}); |
| 145 | + |
| 146 | +it('does not override the state when the always on environment does not match', function () { |
| 147 | + app()->detectEnvironment(fn () => 'production'); |
| 148 | + |
| 149 | + config([ |
| 150 | + 'feature-flags.features' => [ |
| 151 | + 'some-feature' => FeatureState::on(), |
| 152 | + 'some-other-feature' => FeatureState::off(), |
| 153 | + 'some-dynamic-feature' => FeatureState::dynamic(), |
| 154 | + ], |
| 155 | + 'feature-flags.always_on' => ['local', 'staging'], |
| 156 | + ]); |
| 157 | + |
| 158 | + (new SyncFeaturesAction)->__invoke(); |
| 159 | + |
| 160 | + $this->assertDatabaseCount('features', 3); |
| 161 | + |
| 162 | + $this->assertDatabaseHas('features', [ |
| 163 | + 'name' => 'some-feature', |
| 164 | + 'state' => FeatureState::on(), |
| 165 | + ]); |
| 166 | + |
| 167 | + $this->assertDatabaseHas('features', [ |
| 168 | + 'name' => 'some-other-feature', |
| 169 | + 'state' => FeatureState::off(), |
| 170 | + ]); |
| 171 | + |
| 172 | + $this->assertDatabaseHas('features', [ |
| 173 | + 'name' => 'some-dynamic-feature', |
| 174 | + 'state' => FeatureState::dynamic(), |
| 175 | + ]); |
| 176 | +}); |
0 commit comments