diff --git a/application/src/Entity/Attribut/PriorityAttribut.php b/application/src/Entity/Attribut/PriorityAttribut.php new file mode 100644 index 0000000..6e4be76 --- /dev/null +++ b/application/src/Entity/Attribut/PriorityAttribut.php @@ -0,0 +1,21 @@ +priority = $priority; + } + + public function getPriority(): int + { + return $this->priority; + } +} diff --git a/application/src/Entity/Attribut/PriorityAttributInterface.php b/application/src/Entity/Attribut/PriorityAttributInterface.php new file mode 100644 index 0000000..57a052c --- /dev/null +++ b/application/src/Entity/Attribut/PriorityAttributInterface.php @@ -0,0 +1,10 @@ +grant = true; + $this->priority = 0; $this->reciever = new Reciever(); $this->reciever->setRight($this); } diff --git a/application/src/Entity/Meta/RightInterface.php b/application/src/Entity/Meta/RightInterface.php index 57ae557..f4207b1 100644 --- a/application/src/Entity/Meta/RightInterface.php +++ b/application/src/Entity/Meta/RightInterface.php @@ -9,10 +9,11 @@ use App\Entity\Attribut\GrantAttributInterface; use App\Entity\Attribut\ConditionAttributInterface; use App\Entity\Attribut\LayerAttributInterface; use App\Entity\Attribut\RelationAttributInterface; +use App\Entity\Attribut\PriorityAttributInterface; /** * @author kevinfrantz */ -interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface +interface RightInterface extends TypeAttributInterface, LawAttributInterface, GrantAttributInterface, RecieverAttributInterface, RelationAttributInterface, ConditionAttributInterface, LayerAttributInterface, MetaInterface, PriorityAttributInterface { } diff --git a/application/src/Repository/RightRepository.php b/application/src/Repository/RightRepository.php new file mode 100644 index 0000000..83e8bf7 --- /dev/null +++ b/application/src/Repository/RightRepository.php @@ -0,0 +1,12 @@ +priorityAttribut = new class() implements PriorityAttributInterface { + use PriorityAttribut; + }; + } + + public function testConstructor(): void + { + $this->expectException(\TypeError::class); + $this->priorityAttribut->getPriority(); + } + + public function testAccessors(): void + { + $priority = 123; + $this->assertNull($this->priorityAttribut->setPriority($priority)); + $this->assertEquals($priority, $this->priorityAttribut->getPriority()); + } +} diff --git a/application/tests/Unit/Entity/Meta/RightTest.php b/application/tests/Unit/Entity/Meta/RightTest.php index c2182d6..4076ecc 100644 --- a/application/tests/Unit/Entity/Meta/RightTest.php +++ b/application/tests/Unit/Entity/Meta/RightTest.php @@ -29,6 +29,7 @@ class RightTest extends TestCase { $this->assertEquals($this->right, $this->right->getReciever()->getRight()); $this->assertTrue($this->right->getGrant()); + $this->assertEquals(0, $this->right->getPriority()); } public function testConstructorLayer(): void diff --git a/application/tests/Unit/Repository/RightRepositoryTest.php b/application/tests/Unit/Repository/RightRepositoryTest.php new file mode 100644 index 0000000..8ab0189 --- /dev/null +++ b/application/tests/Unit/Repository/RightRepositoryTest.php @@ -0,0 +1,100 @@ +entityManager = $kernel->getContainer() + ->get('doctrine') + ->getManager(); + $this->rightRepository = $this->entityManager->getRepository(Right::class); + $this->right = new Right(); + $this->right->setPriority(self::PRIORITY); + $this->right->setLayer(LayerType::SOURCE); + $this->right->setType(RightType::READ); + $this->law = new Law(); + $this->entityManager->persist($this->law); + $this->right->setLaw($this->law); + } + + public function testCreation(): void + { + $this->entityManager->persist($this->right); + $this->entityManager->flush(); + $rightId = $this->right->getId(); + /* + * @var RightInterface + */ + $this->loadedRight = $this->rightRepository->find($rightId); + $this->assertEquals($rightId, $this->loadedRight->getId()); + $this->assertEquals(self::PRIORITY, $this->loadedRight->getPriority()); + $this->deleteRight(); + $this->assertNull($this->rightRepository->find($rightId)); + $this->loadedRight = null; + } + + private function deleteRight(): void + { + $this->entityManager->remove($this->loadedRight); + $this->entityManager->flush(); + $this->entityManager->remove($this->law); + $this->entityManager->flush(); + } + + /** + * {@inheritdoc} + * + * @see \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown() + */ + protected function tearDown(): void + { + parent::tearDown(); + $this->entityManager->close(); + $this->entityManager = null; + } +}