feat(db): add entities
This commit is contained in:
34
tests/Common/Generators/CommentGeneratorTrait.php
Normal file
34
tests/Common/Generators/CommentGeneratorTrait.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
37
tests/Common/Generators/PostGeneratorTrait.php
Normal file
37
tests/Common/Generators/PostGeneratorTrait.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
55
tests/Common/Generators/UserGeneratorTrait.php
Normal file
55
tests/Common/Generators/UserGeneratorTrait.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Common\Generators;
|
||||
|
||||
use App\Entity\Database\Users\Address;
|
||||
use App\Entity\Database\Users\Company;
|
||||
use App\Entity\Database\Users\User;
|
||||
use App\Tests\Common\DatabaseTestTrait;
|
||||
use App\Tests\Common\FakerTrait;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
trait UserGeneratorTrait
|
||||
{
|
||||
use FakerTrait;
|
||||
use DatabaseTestTrait;
|
||||
|
||||
private function createUser(int $id): User
|
||||
{
|
||||
$user = new User(
|
||||
$id,
|
||||
$this->getFaker()->name(),
|
||||
$this->getFaker()->userName(),
|
||||
$this->getFaker()->email(),
|
||||
$this->getFaker()->phoneNumber(),
|
||||
$this->getFaker()->url(),
|
||||
new Address(
|
||||
1,
|
||||
null,
|
||||
$this->getFaker()->streetAddress(),
|
||||
(string) $this->getFaker()->randomNumber(),
|
||||
$this->getFaker()->city(),
|
||||
$this->getFaker()->postcode(),
|
||||
$this->getFaker()->randomNumber(),
|
||||
$this->getFaker()->randomNumber(),
|
||||
),
|
||||
new Company(
|
||||
1,
|
||||
new ArrayCollection(),
|
||||
$this->getFaker()->company(),
|
||||
$this->getFaker()->text(10),
|
||||
$this->getFaker()->text(100)
|
||||
)
|
||||
);
|
||||
|
||||
$this->getEntityManager()->persist($user->address);
|
||||
$this->getEntityManager()->persist($user->company);
|
||||
$this->getEntityManager()->persist($user);
|
||||
$this->getEntityManager()->refresh($user->address);
|
||||
$this->getEntityManager()->refresh($user->company);
|
||||
$this->getEntityManager()->flush();
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user