The helpers are plain static and instance methods, so testing your enums needs no fakes. A few patterns worth copying:
use App\Enums\NewsCategory;
use Illuminate\Support\Facades\Lang;
it('labels every category', function () {
expect(NewsCategory::labels()->all())
->toBe(['Hot News', 'Regular News', 'Private News']);
});
it('keeps the validation rule in sync with the cases', function () {
expect(NewsCategory::validationRule())
->toBe('in:hot-news,regular-news,private-news');
});
it('uses the translated label', function () {
Lang::addLines(['*.Hot News' => 'Breaking'], 'en', '*');
expect(NewsCategory::HotNews->label())->toBe('Breaking');
});
it('picks a real case at random', function () {
expect(NewsCategory::cases())->toContain(NewsCategory::random());
});
it('rejects an unknown category', function () {
$this->postJson('/articles', ['title' => 'Launch day', 'category' => 'breaking-news'])
->assertJsonValidationErrors('category');
});random() is random by design — assert membership in cases(), not a specific case. Label assertions run through the translator, so test translated labels by adding lines with Lang::addLines() (JSON lines use the * group).
The package’s own suite
Contributors run the Pest suite and static analysis from the package root:
composer test
composer analyseShow your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.