mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-07-11 18:56:11 +09:00
Task 7 - polymorphic
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Country;
|
||||
use App\Models\Role;
|
||||
@@ -104,4 +105,32 @@ class RelationshipsTest extends TestCase
|
||||
$response = $this->get('/countries');
|
||||
$response->assertSee('avg team size 4');
|
||||
}
|
||||
|
||||
// TASK: polymorphic relations
|
||||
public function test_attachments_polymorphic()
|
||||
{
|
||||
$task = Task::create(['name' => 'Some task']);
|
||||
$comment = Comment::create([
|
||||
'task_id' => $task->id,
|
||||
'name' => 'Some name',
|
||||
'comment' => 'Some comment'
|
||||
]);
|
||||
Attachment::create([
|
||||
'filename' => 'something.jpg',
|
||||
'attachable_id' => $task->id,
|
||||
'attachable_type' => Task::class
|
||||
]);
|
||||
Attachment::create([
|
||||
'filename' => 'something.pdf',
|
||||
'attachable_id' => $comment->id,
|
||||
'attachable_type' => Comment::class
|
||||
]);
|
||||
|
||||
$response = $this->get('/attachments');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('something.jpg');
|
||||
$response->assertSee('something.pdf');
|
||||
$response->assertSee('Task');
|
||||
$response->assertSee('Comment');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user