mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-04 11:17:58 +00:00 
			
		
		
		
	Implemented getChoices and getValues from Doctrine ENUM on the right way
This commit is contained in:
		@@ -22,7 +22,7 @@ trait ActionTypeAttribut
 | 
			
		||||
     */
 | 
			
		||||
    public function setActionType(string $actionType): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!array_key_exists($actionType, ActionType::getChoices())) {
 | 
			
		||||
        if (!in_array($actionType, ActionType::getValues())) {
 | 
			
		||||
            throw new NoValidChoiceException('The type is not a valid action type.');
 | 
			
		||||
        }
 | 
			
		||||
        $this->actionType = $actionType;
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ trait CrudAttribut
 | 
			
		||||
     */
 | 
			
		||||
    public function setCrud(string $crud): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!array_key_exists($crud, CRUDType::getChoices())) {
 | 
			
		||||
        if (!in_array($crud, CRUDType::getValues())) {
 | 
			
		||||
            throw new NoValidChoiceException();
 | 
			
		||||
        }
 | 
			
		||||
        $this->crud = $crud;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ trait LayerAttribut
 | 
			
		||||
     */
 | 
			
		||||
    public function setLayer(string $layer): void
 | 
			
		||||
    {
 | 
			
		||||
        if (!array_key_exists($layer, LayerType::getChoices())) {
 | 
			
		||||
        if (!in_array($layer, LayerType::getValues())) {
 | 
			
		||||
            throw new NoValidChoiceException("'$layer' is not a correct layer type.");
 | 
			
		||||
        }
 | 
			
		||||
        $this->layer = $layer;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,8 +30,8 @@ final class LayerType extends AbstractEnumType
 | 
			
		||||
        self::SOURCE => 'source',
 | 
			
		||||
        self::LAW => 'law',
 | 
			
		||||
        self::RIGHT => 'right',
 | 
			
		||||
        self::MEMBER => 'member',
 | 
			
		||||
        self::HEREDITY => 'heredity',
 | 
			
		||||
        self::CREATOR => 'creator',
 | 
			
		||||
        self::MEMBER => 'member relation',
 | 
			
		||||
        self::HEREDITY => 'heredity relation',
 | 
			
		||||
        self::CREATOR => 'creator relation',
 | 
			
		||||
    ];
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -47,8 +47,8 @@ final class RightLayerCombinationService implements RightLayerCombinationService
 | 
			
		||||
 | 
			
		||||
    private function setCombination(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (LayerType::getChoices() as $layer) {
 | 
			
		||||
            foreach (CRUDType::getChoices() as $crud) {
 | 
			
		||||
        foreach (LayerType::getValues() as $layer) {
 | 
			
		||||
            foreach (CRUDType::getValues() as $crud) {
 | 
			
		||||
                if (!array_key_exists($layer, $this->possibleCombinations)) {
 | 
			
		||||
                    $this->possibleCombinations[$layer] = [];
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ interface RightLayerCombinationServiceInterface
 | 
			
		||||
    /**
 | 
			
		||||
     * For layer parameter see:.
 | 
			
		||||
     *
 | 
			
		||||
     * @see LayerType::getChoices()
 | 
			
		||||
     * @see LayerType::getValues()
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $layer
 | 
			
		||||
     *
 | 
			
		||||
@@ -26,7 +26,7 @@ interface RightLayerCombinationServiceInterface
 | 
			
		||||
    /**
 | 
			
		||||
     * For layer parameter see:.
 | 
			
		||||
     *
 | 
			
		||||
     * @see CRUDType::getChoices()
 | 
			
		||||
     * @see CRUDType::getValues()
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $crud
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ final class ActionTemplateDataStoreService implements ActionTemplateDataStoreSer
 | 
			
		||||
     */
 | 
			
		||||
    private function isValidActionType(string $actionType): bool
 | 
			
		||||
    {
 | 
			
		||||
        if (in_array($actionType, ActionType::getChoices())) {
 | 
			
		||||
        if (in_array($actionType, ActionType::getValues())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        throw new NoValidChoiceException("The action type <<$actionType>> is not defined and not valid!");
 | 
			
		||||
 
 | 
			
		||||
@@ -34,8 +34,8 @@ class RestRoutesReachableIntegrationTest extends KernelTestCase
 | 
			
		||||
            '12314123',
 | 
			
		||||
            'testslug',
 | 
			
		||||
        ] as $uri) {
 | 
			
		||||
            foreach (RESTResponseType::getChoices() as $format) {
 | 
			
		||||
                foreach (LayerType::getChoices() as $layer) {
 | 
			
		||||
            foreach (RESTResponseType::getValues() as $format) {
 | 
			
		||||
                foreach (LayerType::getValues() as $layer) {
 | 
			
		||||
                    $actions = LayerActionMap::getActions($layer);
 | 
			
		||||
                    foreach ($actions as $action) {
 | 
			
		||||
                        foreach (ActionHttpMethodMap::getHttpMethods($action) as $method) {
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ class ActionTypeAttributTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testAccessors(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (ActionType::getChoices() as $enum) {
 | 
			
		||||
        foreach (ActionType::getValues() as $enum) {
 | 
			
		||||
            $this->assertNull($this->actionTypeAttribut->setActionType($enum));
 | 
			
		||||
            $this->assertEquals($enum, $this->actionTypeAttribut->getActionType());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ class CrudAttributTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testAccessors(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (CRUDType::getChoices() as $enum) {
 | 
			
		||||
        foreach (CRUDType::getValues() as $enum) {
 | 
			
		||||
            $this->assertNull($this->crudAttribut->setCrud($enum));
 | 
			
		||||
            $this->assertEquals($enum, $this->crudAttribut->getCrud());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ class LayerAttributTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testAccessors(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (LayerType::getChoices() as $enum) {
 | 
			
		||||
        foreach (LayerType::getValues() as $enum) {
 | 
			
		||||
            $this->assertNull($this->layerAttribut->setLayer($enum));
 | 
			
		||||
            $this->assertEquals($enum, $this->layerAttribut->getLayer());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ class DefaultControllerTest extends WebTestCase
 | 
			
		||||
    public function testImprint(): void
 | 
			
		||||
    {
 | 
			
		||||
        $client = static::createClient();
 | 
			
		||||
        foreach (RESTResponseType::getChoices() as $format) {
 | 
			
		||||
        foreach (RESTResponseType::getValues() as $format) {
 | 
			
		||||
            $format = 'html';
 | 
			
		||||
            $url = '/api/rest/source/imprint.'.$format;
 | 
			
		||||
            $client->request('GET', $url);
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,6 @@ class ActionTypeTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testAmountOfActions(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals(5, count(ActionType::getChoices()));
 | 
			
		||||
        $this->assertEquals(5, count(ActionType::getValues()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ class LayerActionMapTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testGetLayersBySource(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (ActionType::getChoices() as $action) {
 | 
			
		||||
        foreach (ActionType::getValues() as $action) {
 | 
			
		||||
            $layers = LayerActionMap::getLayers($action);
 | 
			
		||||
            $this->assertArraySubset([LayerType::SOURCE], $layers);
 | 
			
		||||
        }
 | 
			
		||||
@@ -23,7 +23,7 @@ class LayerActionMapTest extends TestCase
 | 
			
		||||
    public function testGetActionsBySource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $actions = LayerActionMap::getActions(LayerType::SOURCE);
 | 
			
		||||
        foreach (ActionType::getChoices() as $action) {
 | 
			
		||||
        foreach (ActionType::getValues() as $action) {
 | 
			
		||||
            $this->assertTrue(in_array($action, $actions));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,7 @@ class RequestedActionTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testCrud(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (CRUDType::getChoices() as $crud) {
 | 
			
		||||
        foreach (CRUDType::getValues() as $crud) {
 | 
			
		||||
            $this->action->setActionType($crud);
 | 
			
		||||
            $this->assertEquals($crud, $this->action->getActionType());
 | 
			
		||||
            $this->assertEquals($crud, $this->requestedRight->getActionType());
 | 
			
		||||
@@ -66,7 +66,7 @@ class RequestedActionTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testLayer(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (LayerType::getChoices() as $LayerType) {
 | 
			
		||||
        foreach (LayerType::getValues() as $LayerType) {
 | 
			
		||||
            $this->action->setLayer($LayerType);
 | 
			
		||||
            $this->assertEquals($LayerType, $this->action->getLayer());
 | 
			
		||||
            $this->assertEquals($LayerType, $this->requestedRight->getLayer());
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ class RightLayerCombinationServiceTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testBySource(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (CRUDType::getChoices() as $crudType) {
 | 
			
		||||
        foreach (CRUDType::getValues() as $crudType) {
 | 
			
		||||
            $layers = $this->rightLayerCombinationService->getPossibleLayers($crudType);
 | 
			
		||||
            $this->assertContains(LayerType::SOURCE, $layers);
 | 
			
		||||
            $sourceCruds = $this->rightLayerCombinationService->getPossibleCruds(LayerType::SOURCE);
 | 
			
		||||
 
 | 
			
		||||
@@ -59,7 +59,7 @@ class ActionTemplateDataStoreServiceTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testAccessors(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (ActionType::getChoices() as $actionType) {
 | 
			
		||||
        foreach (ActionType::getValues() as $actionType) {
 | 
			
		||||
            $instance = ActionTemplateDataStoreService::ACTION_DATA_MAPPING[$actionType];
 | 
			
		||||
            $data = $this->createMock($instance);
 | 
			
		||||
            $this->assertFalse($this->actionTemplateDataStoreService->isDataStored($actionType));
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ class TemplatePathFormAndViewTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testTypeReload(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (RESTResponseType::getChoices() as $type) {
 | 
			
		||||
        foreach (RESTResponseType::getValues() as $type) {
 | 
			
		||||
            $this->templatePathFormAndView->reloadType($type);
 | 
			
		||||
            $this->assertEquals(self::BASE_PATH.$type.'.twig', $this->templatePathFormAndView->getView()->getAtomTemplatePath());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ class TemplatePathInformationTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testSetType(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (RESTResponseType::getChoices() as $type) {
 | 
			
		||||
        foreach (RESTResponseType::getValues() as $type) {
 | 
			
		||||
            $this->templateMeta->reloadType($type);
 | 
			
		||||
            $this->assertEquals($this->getExpectedPath($type, 'atom'), $this->templateMeta->getAtomTemplatePath());
 | 
			
		||||
            $this->assertEquals($this->getExpectedPath($type, 'molecule'), $this->templateMeta->getMoleculeTemplatePath());
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ class ActionIconClassMapTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testAllActionsSet(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (ActionType::getChoices() as $action) {
 | 
			
		||||
        foreach (ActionType::getValues() as $action) {
 | 
			
		||||
            $this->assertIsString($this->actionIconClassMap->getIconClass($action));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ class RightTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testRight(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (CRUDType::getChoices() as $enum) {
 | 
			
		||||
        foreach (CRUDType::getValues() as $enum) {
 | 
			
		||||
            $this->assertNull($this->right->setActionType($enum));
 | 
			
		||||
            $this->assertEquals($enum, $this->right->getActionType());
 | 
			
		||||
        }
 | 
			
		||||
@@ -83,7 +83,7 @@ class RightTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function testLayer(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (LayerType::getChoices() as $choice) {
 | 
			
		||||
        foreach (LayerType::getValues() as $choice) {
 | 
			
		||||
            $this->assertNull($this->right->setLayer($choice));
 | 
			
		||||
            $this->assertEquals($choice, $this->right->getLayer());
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user