Task 7 - polymorphic

This commit is contained in:
PovilasKorop
2021-11-22 10:30:12 +02:00
parent a3538e1014
commit fc0bf0d079
7 changed files with 110 additions and 0 deletions
+29
View File
@@ -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');
}
}