2018-11-15 21:32:39 +01:00
|
|
|
<?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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var EntityManager
|
|
|
|
*/
|
|
|
|
protected $entityManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var UserRepository
|
|
|
|
*/
|
|
|
|
protected $userRepository;
|
|
|
|
|
2018-11-18 12:16:38 +01:00
|
|
|
/**
|
|
|
|
* @var UserInterface
|
|
|
|
*/
|
|
|
|
protected $loadedUser;
|
|
|
|
|
2018-11-15 21:32:39 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$kernel = self::bootKernel();
|
|
|
|
$this->entityManager = $kernel->getContainer()->get('doctrine')->getManager();
|
|
|
|
$this->userRepository = $this->entityManager->getRepository(User::class);
|
|
|
|
}
|
|
|
|
|
2018-11-17 14:48:48 +01:00
|
|
|
/**
|
|
|
|
* @todo Test double username
|
|
|
|
* @todo Test double email
|
|
|
|
*/
|
2018-11-15 21:32:39 +01:00
|
|
|
public function testCreation(): void
|
|
|
|
{
|
|
|
|
$user = new User();
|
2018-11-17 14:48:48 +01:00
|
|
|
$user->setUsername('Karl Marx');
|
|
|
|
$user->setEmail('mew21@test.de');
|
|
|
|
$user->setPassword('Friedrich ist kein Engel!:)');
|
2018-11-15 21:32:39 +01:00
|
|
|
$this->entityManager->persist($user);
|
|
|
|
$this->entityManager->flush();
|
2018-11-17 14:48:48 +01:00
|
|
|
$userId = $user->getId();
|
2018-11-18 12:16:38 +01:00
|
|
|
/*
|
2018-11-15 21:32:39 +01:00
|
|
|
* @var UserInterface
|
|
|
|
*/
|
2018-11-18 12:16:38 +01:00
|
|
|
$this->loadedUser = $this->userRepository->find($userId);
|
|
|
|
$this->assertEquals($userId, $this->loadedUser->getId());
|
|
|
|
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getId());
|
|
|
|
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getId());
|
2018-11-18 12:25:36 +01:00
|
|
|
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getId());
|
2018-11-20 22:04:29 +01:00
|
|
|
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getFirstNameSource()->getId());
|
|
|
|
$this->assertGreaterThan(0, $this->loadedUser->getSource()->getPersonIdentitySource()->getFullPersonNameSource()->getSurnameSource()->getId());
|
2018-11-18 12:16:38 +01:00
|
|
|
$this->deleteUser();
|
2018-11-17 14:48:48 +01:00
|
|
|
$this->assertNull($this->userRepository->find($userId));
|
2018-11-18 12:16:38 +01:00
|
|
|
$this->loadedUser = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function deleteUser(): void
|
|
|
|
{
|
|
|
|
$this->entityManager->remove($this->loadedUser);
|
|
|
|
$this->entityManager->flush();
|
2018-11-15 21:32:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown()
|
|
|
|
*/
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
$this->entityManager->close();
|
|
|
|
$this->entityManager = null;
|
|
|
|
}
|
|
|
|
}
|