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

38 lines
852 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\Posts\Post;
use App\Tests\Common\DatabaseTestTrait;
use App\Tests\Common\FakerTrait;
use Doctrine\Common\Collections\ArrayCollection;
trait PostGeneratorTrait
{
use UserGeneratorTrait;
use FakerTrait;
use DatabaseTestTrait;
private const int POST_GENERATOR_SYSTEM_POST_USER = 1000;
private function createPost(int $id): Post
{
$user = $this->createUser($id + self::POST_GENERATOR_SYSTEM_POST_USER);
$post = new Post(
$id,
$user,
$this->getFaker()->text(500),
$this->getFaker()->text(5000),
new ArrayCollection(),
);
$this->getEntityManager()->persist($post);
$this->getEntityManager()->flush();
return $post;
}
}