mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Implemented some basic tests for user repository
This commit is contained in:
parent
3648184811
commit
2168eb2a1e
55
application/tests/Unit/Repository/UserRepositoryTest.php
Normal file
55
application/tests/Unit/Repository/UserRepositoryTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Repository;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserInterface;
|
||||
|
||||
class UserRepositoryTest extends KernelTestCase
|
||||
{
|
||||
const USER_ID = 123456789;
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $userRepository;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->entityManager = $kernel->getContainer()->get('doctrine')->getManager();
|
||||
$this->userRepository = $this->entityManager->getRepository(User::class);
|
||||
}
|
||||
|
||||
public function testCreation(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setId(self::USER_ID);
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
$loadedUser = $this->userRepository->find(self::USER_ID);
|
||||
$this->assertEquals(self::USER_ID, $loadedUser->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->entityManager->close();
|
||||
$this->entityManager = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user