create([ 'codigo' => 'acme', 'nombre' => 'Acme', 'dominio' => 'acme.com', ]); $attachment = $tenant->attachments()->create([ 'path' => 'attachments/acme/logo.png', 'filename' => 'logo.png', 'type' => AttachmentType::Image, 'mime_type' => 'image/png', 'extension' => 'png', 'size' => 1234, ]); $this->assertSame(AttachmentType::Image, $attachment->type); $this->assertTrue($tenant->attachments->contains($attachment)); $this->assertDatabaseHas('attachments', [ 'id' => $attachment->id, 'attachable_type' => $tenant->getMorphClass(), 'attachable_id' => $tenant->getKey(), 'type' => AttachmentType::Image->value, ]); $freshAttachment = Attachment::query()->findOrFail($attachment->id); $this->assertSame(AttachmentType::Image, $freshAttachment->type); $this->assertTrue($freshAttachment->attachable->is($tenant)); } public function test_it_requires_attachment_type(): void { $tenant = Tenant::query()->create([ 'codigo' => 'globex', 'nombre' => 'Globex', 'dominio' => 'globex.com', ]); $this->expectException(\Illuminate\Database\QueryException::class); Attachment::query()->create([ 'attachable_type' => $tenant->getMorphClass(), 'attachable_id' => $tenant->getKey(), 'path' => 'attachments/globex/manual.pdf', 'filename' => 'manual.pdf', 'mime_type' => 'application/pdf', 'extension' => 'pdf', 'size' => 9876, ]); } }