On my Note model, I have an Eloquent accessor getTypeDescriptionAttribute. It shows correctly in my UI, an unit test is passing, but the feature test that asserts that it sees the retrieved value fails.
Why does the accessor not work in the Blade when being rendered in the test?
Any help on how to debug this?
Model:
public function getTypeDescriptionAttribute()
{
return NoteType::getDescription($this->type) ?? 'Fallback';
}
Enum class:
final class NoteType extends Enum
{
const Interaction = 0;
}
Blade (edit.blade.php)
@foreach ($notes as $note)
<code>{{ $note }}</code>
<li>{{ $note->type }}, {{ $note->type_description }}: {{ $note->body }}</li>
@endforeach
Unit test (green)
/** @test */
public function it_does_get_note_type_description()
{
$note = factory(Note::class)->create();
$this->assertEquals('Interaction', $note->type_description);
}
Feature test (red)
/** @test */
public function user_can_see_list_of_notes_for_contact_with_details()
{
$this->withoutExceptionHandling();
$contact = factory(Contact::class)->create();
$note = factory(Note::class)->create();
$response = $this->get(route('contact.show', $contact));
$response->assertSee(e($note->body));
$this->assertEquals('Interaction', NoteType::getDescription(0));
$this->assertEquals(0, $note->type);
$response->assertSee(NoteType::getDescription($note->type));
}
Error message: https://gist.github.com/minthemiddle/b1fe67c0019ffcc5e448e8ee9378d7c4
UI:
