Skip to content

Commit e5d7a5b

Browse files
committed
add tests
1 parent e276620 commit e5d7a5b

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

src/Concerns/DefinesFeatures.php

-1
Original file line numberDiff line numberDiff 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

tests/FeatureTest.php renamed to tests/BaseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
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
});

tests/CustomConfigTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
});

tests/Fixtures/CustomFeature.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

tests/TestCase.php

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace DefStudio\EnumFeatures\Tests;
44

5+
use DefStudio\EnumFeatures\Tests\Fixtures\CustomFeature;
56
use DefStudio\EnumFeatures\Tests\Fixtures\Feature;
67
use 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
}

0 commit comments

Comments
 (0)