File tree 5 files changed +47
-2
lines changed
5 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ public function enabled(): bool
22
22
23
23
public function enforce (): void
24
24
{
25
- /** @noinspection PhpParamsInspection */
26
25
throw_if (! $ this ->enabled (), FeatureException::notEnabled ($ this ));
27
26
}
28
27
Original file line number Diff line number Diff line change 19
19
Feature::welcome_email->enforce ();
20
20
21
21
expect (fn () => Feature::other_feature->enforce ())
22
- ->toThrow (FeatureException::notEnabled ( Feature:: other_feature) );
22
+ ->toThrow (FeatureException::class, ' Feature [ other_feature] is not enabled ' );
23
23
});
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use DefStudio \EnumFeatures \Exceptions \FeatureException ;
4
+ use DefStudio \EnumFeatures \Tests \Fixtures \CustomFeature ;
5
+
6
+ it ('can check if a feature is enabled ' , function () {
7
+ expect (CustomFeature::guest_account->enabled ())->toBeTrue ();
8
+
9
+ expect (CustomFeature::payments->enabled ())->toBeFalse ();
10
+ });
11
+
12
+ it ('can check if a feature is not enabled ' , function () {
13
+ expect (CustomFeature::guest_account->disabled ())->toBeFalse ();
14
+
15
+ expect (CustomFeature::payments->disabled ())->toBeTrue ();
16
+ });
17
+
18
+ it ('can enforce a feature to be enabled ' , function () {
19
+ CustomFeature::guest_account->enforce ();
20
+
21
+ expect (fn () => CustomFeature::payments->enforce ())
22
+ ->toThrow (FeatureException::class, 'Feature [payments] is not enabled ' );
23
+ });
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace DefStudio \EnumFeatures \Tests \Fixtures ;
4
+
5
+ use DefStudio \EnumFeatures \Concerns \DefinesFeatures ;
6
+
7
+ enum CustomFeature
8
+ {
9
+ use DefinesFeatures;
10
+
11
+ case guest_account;
12
+ case payments;
13
+
14
+ public static function enabledFeatures (): array
15
+ {
16
+ return config ('my_package.enabled_features ' , []);
17
+ }
18
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace DefStudio \EnumFeatures \Tests ;
4
4
5
+ use DefStudio \EnumFeatures \Tests \Fixtures \CustomFeature ;
5
6
use DefStudio \EnumFeatures \Tests \Fixtures \Feature ;
6
7
use Orchestra \Testbench \TestCase as Orchestra ;
7
8
@@ -13,5 +14,9 @@ public function getEnvironmentSetUp($app): void
13
14
Feature::multi_language,
14
15
Feature::welcome_email,
15
16
]);
17
+
18
+ config ()->set ('my_package.enabled_features ' , [
19
+ CustomFeature::guest_account,
20
+ ]);
16
21
}
17
22
}
You can’t perform that action at this time.
0 commit comments