File tree Expand file tree Collapse file tree 5 files changed +47
-2
lines changed
Expand file tree Collapse file tree 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
2222
2323 public function enforce (): void
2424 {
25- /** @noinspection PhpParamsInspection */
2625 throw_if (! $ this ->enabled (), FeatureException::notEnabled ($ this ));
2726 }
2827
Original file line number Diff line number Diff line change 1919 Feature::welcome_email->enforce ();
2020
2121 expect (fn () => Feature::other_feature->enforce ())
22- ->toThrow (FeatureException::notEnabled ( Feature:: other_feature) );
22+ ->toThrow (FeatureException::class, ' Feature [ other_feature] is not enabled ' );
2323});
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 22
33namespace DefStudio \EnumFeatures \Tests ;
44
5+ use DefStudio \EnumFeatures \Tests \Fixtures \CustomFeature ;
56use DefStudio \EnumFeatures \Tests \Fixtures \Feature ;
67use Orchestra \Testbench \TestCase as Orchestra ;
78
@@ -13,5 +14,9 @@ public function getEnvironmentSetUp($app): void
1314 Feature::multi_language,
1415 Feature::welcome_email,
1516 ]);
17+
18+ config ()->set ('my_package.enabled_features ' , [
19+ CustomFeature::guest_account,
20+ ]);
1621 }
1722}
You can’t perform that action at this time.
0 commit comments