---
title: "Testing — Enums for Laravel | Roundly"
description: "Assert labels, options and validation in Pest, pin translations with untranslated(), add lines with Lang::addLines(), and run the package suite."
url: https://roundly-consulting.com/open-source/docs/enums-for-laravel/testing
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Enums for Laravel](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)

# Testing

The helpers are plain static and instance methods, so testing your enums needs no fakes. A few patterns worth copying:

```php
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).

## No case ships untranslated

On a #\[TranslatedLabels\] enum, untranslated() lists the cases still missing a line in a locale, so one dataset test covers every language you ship:

```php
it('translates every order status', function (string $locale) {
    expect(OrderStatus::untranslated($locale))->toBeEmpty();
})->with(['en', 'sk']);
```

## The package’s own suite

Contributors run the Pest suite and static analysis from the package root:

```bash
composer test
composer analyse
```

## Show 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/enums-for-laravel.md)
