brilo-example/tests/Common/Generators/CommentGeneratorTrait.php

35 lines
758 B
PHP
Raw Permalink Normal View History

2024-08-02 12:13:25 +00:00
<?php
declare(strict_types=1);
namespace App\Tests\Common\Generators;
use App\Entity\Database\Comments\Comment;
use App\Entity\Database\Posts\Post;
use App\Tests\Common\DatabaseTestTrait;
use App\Tests\Common\FakerTrait;
trait CommentGeneratorTrait
{
use FakerTrait;
use DatabaseTestTrait;
private function createComment(int $id, Post $post): Comment
{
$comment = new Comment(
$id,
$post,
$this->getFaker()->name(),
$this->getFaker()->email(),
$this->getFaker()->text(500)
);
$this->getEntityManager()->persist($comment);
$this->getEntityManager()->flush();
$this->getEntityManager()->refresh($post);
return $comment;
}
}