How to perform tests with backed enums

1. $casts is set
protected $casts = [
'name' => EnumsRole::class,
];
protected $casts = [
'name' => EnumsRole::class,
];
2. The enum, in this case, does not implement hasLabel.
enum Role: string
{
case FOO = 'foo';
case BAR= 'bar';
}
enum Role: string
{
case FOO = 'foo';
case BAR= 'bar';
}
3. The test
livewire(ListRoles::class)
->assertTableColumnFormattedStateSet('name', $record->name, record: $record); // Object of class App\Enums\Role could not be converted to string

livewire(ListRoles::class)
->assertTableColumnFormattedStateSet('name', $record->name->value, record: $record); // Failed asserting that a table column with name [name] has a formatted state of [foo] for recordto string
livewire(ListRoles::class)
->assertTableColumnFormattedStateSet('name', $record->name, record: $record); // Object of class App\Enums\Role could not be converted to string

livewire(ListRoles::class)
->assertTableColumnFormattedStateSet('name', $record->name->value, record: $record); // Failed asserting that a table column with name [name] has a formatted state of [foo] for recordto string
4. if I use assertTableColumnStateSet, the errors are exactly the same. Does anyone know what I could be doing wrong?
4 Replies
Babiute🍎🐍
Babiute🍎🐍OP13mo ago
Someone can help me?
DrByte
DrByte13mo ago
The enum, in this case, does not implement hasLabel
Why not?
Babiute🍎🐍
Babiute🍎🐍OP13mo ago
I think your question is the answer I was looking for. Implementing hasLabel solved the problem and now I just need to use
$record->name->getLabel()
$record->name->getLabel()
Thank you very much!
DrByte
DrByte13mo ago
Great! Don't forget to Mark the solution, so this thread shows as resolved. Right-click on the post that you want to mark, choose Apps, and MarkSolution.
Want results from more Discord servers?
Add your server