mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented ActionTypeAttribut
This commit is contained in:
		| @@ -0,0 +1,38 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\Exception\NoValidChoiceException; | ||||
| use App\DBAL\Types\ActionType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait ActionTypeAttribut | ||||
| { | ||||
|     /** | ||||
|      * @see ActionType | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $actionType; | ||||
|  | ||||
|     /** | ||||
|      * @param string $actionType | ||||
|      */ | ||||
|     public function setActionType(string $actionType): void | ||||
|     { | ||||
|         if (!array_key_exists($actionType, ActionType::getChoices())) { | ||||
|             throw new NoValidChoiceException('The type is not a valid action type.'); | ||||
|         } | ||||
|         $this->actionType = $actionType; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getActionType(): string | ||||
|     { | ||||
|         return $this->actionType; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Attribut; | ||||
|  | ||||
| use App\DBAL\Types\ActionType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  * | ||||
|  * @see ActionType | ||||
|  */ | ||||
| interface ActionTypeAttributInterface | ||||
| { | ||||
|     /** | ||||
|      * @see ActionType | ||||
|      * | ||||
|      * @param string $actionType | ||||
|      */ | ||||
|     public function setActionType(string $actionType): void; | ||||
|  | ||||
|     /** | ||||
|      * @see ActionType | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getActionType(): string; | ||||
| } | ||||
| @@ -6,8 +6,6 @@ use App\Exception\NoValidChoiceException; | ||||
| use App\DBAL\Types\Meta\Right\CRUDType; | ||||
|  | ||||
| /** | ||||
|  * @todo Implement a trait for crud which substitute this one. | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait CrudAttribut | ||||
|   | ||||
| @@ -0,0 +1,43 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Unit\Entity\Attribut; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Exception\NoValidChoiceException; | ||||
| use App\Entity\Attribut\ActionTypeAttributInterface; | ||||
| use App\Entity\Attribut\ActionTypeAttribut; | ||||
| use App\DBAL\Types\ActionType; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class ActionTypeAttributTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @var ActionTypeAttributInterface | ||||
|      */ | ||||
|     protected $actionTypeAttribut; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         $this->actionTypeAttribut = new class() implements ActionTypeAttributInterface { | ||||
|             use ActionTypeAttribut; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function testConstructor(): void | ||||
|     { | ||||
|         $this->expectException(\TypeError::class); | ||||
|         $this->actionTypeAttribut->getActionType(); | ||||
|     } | ||||
|  | ||||
|     public function testAccessors(): void | ||||
|     { | ||||
|         foreach (ActionType::getChoices() as $enum) { | ||||
|             $this->assertNull($this->actionTypeAttribut->setActionType($enum)); | ||||
|             $this->assertEquals($enum, $this->actionTypeAttribut->getActionType()); | ||||
|         } | ||||
|         $this->expectException(NoValidChoiceException::class); | ||||
|         $this->actionTypeAttribut->setActionType('NoneValidType'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user