mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Implemented tests for UserRepository and mapped data schema
This commit is contained in:
parent
5feac4d8ca
commit
a7c58ba135
@ -31,6 +31,7 @@ abstract class AbstractEntity implements EntityInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->version = 0;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
@ -25,6 +25,7 @@ final class Law extends AbstractMeta implements LawInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->rights = new ArrayCollection();
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ final class Relation extends AbstractMeta implements RelationInterface
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id",onDelete="CASCADE")
|
||||
*
|
||||
* @var SourceInterface
|
||||
*/
|
||||
@ -70,6 +70,7 @@ final class Relation extends AbstractMeta implements RelationInterface
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->law = new Law();
|
||||
$this->parents = new ArrayCollection();
|
||||
$this->childs = new ArrayCollection();
|
||||
|
@ -32,7 +32,7 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
/**
|
||||
* @var RelationInterface
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
* @Exclude
|
||||
*/
|
||||
protected $relation;
|
||||
|
@ -18,7 +18,7 @@ class UserSource extends AbstractCombinationSource implements UserSourceInterfac
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\User",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="user_id", referencedColumnName="id",onDelete="CASCADE")
|
||||
*
|
||||
* @var UserInterface
|
||||
*/
|
||||
|
@ -22,7 +22,7 @@ class User extends BaseUser implements UserInterface
|
||||
/**
|
||||
* @var UserSourceInterface
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\Combination\UserSource",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id")
|
||||
* @ORM\JoinColumn(name="source_user_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
@ -51,6 +51,7 @@ class User extends BaseUser implements UserInterface
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->version = 0;
|
||||
$this->isActive = true;
|
||||
$this->source = new UserSource();
|
||||
$this->source->setUser($this);
|
||||
|
@ -21,9 +21,9 @@ class AbstractEntityTest extends TestCase
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertEquals(0, $this->entity->getVersion());
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->entity->getId();
|
||||
$this->entity->getVersion();
|
||||
}
|
||||
|
||||
public function testVersion(): void
|
||||
|
@ -23,6 +23,7 @@ class RelationTest extends TestCase
|
||||
{
|
||||
$this->assertInstanceOf(Collection::class, $this->relation->getChilds());
|
||||
$this->assertInstanceOf(Collection::class, $this->relation->getParents());
|
||||
$this->assertEquals(0, $this->relation->getVersion());
|
||||
$this->expectException(\TypeError::class);
|
||||
$this->relation->getSource();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class UserTest extends TestCase
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$this->assertInstanceOf(UserInterface::class, new User());
|
||||
$this->assertEquals(0, $this->user->getVersion());
|
||||
}
|
||||
|
||||
public function testUsername(): void
|
||||
|
@ -10,7 +10,6 @@ use App\Entity\UserInterface;
|
||||
|
||||
class UserRepositoryTest extends KernelTestCase
|
||||
{
|
||||
const USER_ID = 123456789;
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
@ -28,17 +27,27 @@ class UserRepositoryTest extends KernelTestCase
|
||||
$this->userRepository = $this->entityManager->getRepository(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Test double username
|
||||
* @todo Test double email
|
||||
*/
|
||||
public function testCreation(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setId(self::USER_ID);
|
||||
$user->setUsername('Karl Marx');
|
||||
$user->setEmail('mew21@test.de');
|
||||
$user->setPassword('Friedrich ist kein Engel!:)');
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
$userId = $user->getId();
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
$loadedUser = $this->userRepository->find(self::USER_ID);
|
||||
$this->assertEquals(self::USER_ID, $loadedUser->getId());
|
||||
$loadedUser = $this->userRepository->find($userId);
|
||||
$this->assertEquals($userId, $loadedUser->getId());
|
||||
$this->entityManager->remove($loadedUser);
|
||||
$this->entityManager->flush();
|
||||
$this->assertNull($this->userRepository->find($userId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user