Implemented ActionTypeAttribut

This commit is contained in:
Kevin Frantz 2019-01-19 23:15:58 +01:00
parent 4b86acb372
commit 7e9916b27b
4 changed files with 108 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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

View File

@ -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');
}
}