diff --git a/application/symfony/src/Entity/Attribut/CrudAttribut.php b/application/symfony/src/Entity/Attribut/CrudAttribut.php index 7cf5b9e..8b4c0d3 100644 --- a/application/symfony/src/Entity/Attribut/CrudAttribut.php +++ b/application/symfony/src/Entity/Attribut/CrudAttribut.php @@ -2,6 +2,9 @@ namespace App\Entity\Attribut; +use App\Exception\NoValidChoiceException; +use App\DBAL\Types\Meta\Right\CRUDType; + /** * @todo Implement a trait for crud which substitute this one. * @@ -10,6 +13,8 @@ namespace App\Entity\Attribut; trait CrudAttribut { /** + * @see CRUDType + * * @var string */ protected $crud; @@ -19,6 +24,9 @@ trait CrudAttribut */ public function setCrud(string $crud): void { + if (!array_key_exists($crud, CRUDType::getChoices())) { + throw new NoValidChoiceException(); + } $this->crud = $crud; } diff --git a/application/symfony/src/Entity/Meta/Right.php b/application/symfony/src/Entity/Meta/Right.php index a2dd975..80b994e 100644 --- a/application/symfony/src/Entity/Meta/Right.php +++ b/application/symfony/src/Entity/Meta/Right.php @@ -99,19 +99,6 @@ class Right extends AbstractMeta implements RightInterface $this->priority = 0; } - /** - * {@inheritdoc} - * - * @see \App\Entity\Attribut\CrudAttributInterface::setCrud() - */ - public function setCrud(string $crud): void - { - if (!array_key_exists($crud, CRUDType::getChoices())) { - throw new NoValidChoiceException(); - } - $this->crud = $crud; - } - /** * {@inheritdoc} * diff --git a/application/symfony/tests/Unit/Entity/Attribut/TypeAttributTest.php b/application/symfony/tests/Unit/Entity/Attribut/CrudAttributTest.php similarity index 51% rename from application/symfony/tests/Unit/Entity/Attribut/TypeAttributTest.php rename to application/symfony/tests/Unit/Entity/Attribut/CrudAttributTest.php index 1b0e8d0..4792be3 100644 --- a/application/symfony/tests/Unit/Entity/Attribut/TypeAttributTest.php +++ b/application/symfony/tests/Unit/Entity/Attribut/CrudAttributTest.php @@ -5,6 +5,8 @@ namespace Tests\Unit\Entity\Attribut; use PHPUnit\Framework\TestCase; use App\Entity\Attribut\CrudAttributInterface; use App\Entity\Attribut\CrudAttribut; +use App\DBAL\Types\Meta\Right\CRUDType; +use App\Exception\NoValidChoiceException; /** * @author kevinfrantz @@ -14,11 +16,11 @@ class CrudAttributTest extends TestCase /** * @var CrudAttributInterface */ - protected $typeAttribut; + protected $crudAttribut; public function setUp(): void { - $this->typeAttribut = new class() implements CrudAttributInterface { + $this->crudAttribut = new class() implements CrudAttributInterface { use CrudAttribut; }; } @@ -26,13 +28,16 @@ class CrudAttributTest extends TestCase public function testConstructor(): void { $this->expectException(\TypeError::class); - $this->typeAttribut->getCrud(); + $this->crudAttribut->getCrud(); } public function testAccessors(): void { - $type = 'Hello World!'; - $this->assertNull($this->typeAttribut->setCrud($type)); - $this->assertEquals($type, $this->typeAttribut->getCrud()); + foreach (CRUDType::getChoices() as $enum) { + $this->assertNull($this->crudAttribut->setCrud($enum)); + $this->assertEquals($enum, $this->crudAttribut->getCrud()); + } + $this->expectException(NoValidChoiceException::class); + $this->crudAttribut->setCrud('NoneValidType'); } } diff --git a/application/symfony/tests/Unit/Entity/Meta/RightTest.php b/application/symfony/tests/Unit/Entity/Meta/RightTest.php index 4e3aa9d..b8a42ad 100644 --- a/application/symfony/tests/Unit/Entity/Meta/RightTest.php +++ b/application/symfony/tests/Unit/Entity/Meta/RightTest.php @@ -73,9 +73,9 @@ class RightTest extends TestCase public function testRight(): void { - foreach (CRUDType::getChoices() as $key => $value) { - $this->assertNull($this->right->setCrud($key)); - $this->assertEquals($key, $this->right->getCrud()); + foreach (CRUDType::getChoices() as $enum) { + $this->assertNull($this->right->setCrud($enum)); + $this->assertEquals($enum, $this->right->getCrud()); } $this->expectException(NoValidChoiceException::class); $this->right->setCrud('NoneValidType');