mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Optimized RequestedActionFormBuilderService
This commit is contained in:
parent
22c9a92853
commit
d3379630c8
@ -6,11 +6,11 @@ use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Domain\FormManagement\RequestedEntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Repository\RepositoryInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -38,9 +38,9 @@ final class ActionService implements ActionServiceInterface
|
||||
private $layerRepositoryFactoryService;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityFormBuilderServiceInterface
|
||||
* @var RequestedActionFormBuilderServiceInterface
|
||||
*/
|
||||
private $entityFormBuilderService;
|
||||
private $requestedActionFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
@ -50,13 +50,13 @@ final class ActionService implements ActionServiceInterface
|
||||
/**
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*/
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, RequestedEntityFormBuilderServiceInterface $requestedEntityFormBuilderService, EntityManagerInterface $entityManager)
|
||||
public function __construct(RequestedActionInterface $requestedAction, SecureRequestedRightCheckerInterface $secureRequestedRightChecker, RequestStack $requestStack, LayerRepositoryFactoryServiceInterface $layerRepositoryFactoryService, RequestedActionFormBuilderServiceInterface $requestedActionFormBuilderService, EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->requestedAction = $requestedAction;
|
||||
$this->secureRequestedRightChecker = $secureRequestedRightChecker;
|
||||
$this->requestStack = $requestStack;
|
||||
$this->layerRepositoryFactoryService = $layerRepositoryFactoryService;
|
||||
$this->entityFormBuilderService = $requestedEntityFormBuilderService;
|
||||
$this->requestedActionFormBuilderService = $requestedActionFormBuilderService;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
@ -85,9 +85,7 @@ final class ActionService implements ActionServiceInterface
|
||||
*/
|
||||
public function getForm(): FormBuilderInterface
|
||||
{
|
||||
$requestedEntity = $this->requestedAction->getRequestedEntity();
|
||||
|
||||
return $this->entityFormBuilderService->create($requestedEntity);
|
||||
return $this->requestedActionFormBuilderService->createByService();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,12 +3,12 @@
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RequestedEntityFormBuilderService implements RequestedEntityFormBuilderServiceInterface
|
||||
class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var FormBuilderInterface
|
||||
@ -30,14 +30,16 @@ final class RequestedEntityFormBuilderService implements RequestedEntityFormBuil
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*
|
||||
* @see \App\Domain\FormManagement\EntityFormBuilderServiceInterface::create()
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function create(RequestedEntityInterface $requestedEntity): FormBuilderInterface
|
||||
public function create(RequestedActionInterface $requestedAction): FormBuilderInterface
|
||||
{
|
||||
$requestedEntity = $requestedAction->getRequestedEntity();
|
||||
$actionType = $requestedAction->getActionType();
|
||||
$origineClass = $requestedEntity->getClass();
|
||||
$class = $this->formClassNameService->getClass($origineClass);
|
||||
$class = $this->formClassNameService->getClass($origineClass, $actionType);
|
||||
if ($requestedEntity->hasIdentity()) {
|
||||
$entity = $requestedEntity->getEntity();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
|
||||
/**
|
||||
* Allowes to create an form which fits to an entity.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedActionFormBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @param RequestedActionInterface $requestedAction
|
||||
*
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function create(RequestedActionInterface $requestedAction): FormBuilderInterface;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RequestedActionFormBuilderService extends RequestedActionFormBuilder implements RequestedActionFormBuilderServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var RequestedActionServiceInterface
|
||||
*/
|
||||
private $requestedActionService;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\FormManagement\RequestedActionFormBuilder::__construct()
|
||||
*/
|
||||
public function __construct(FormBuilderInterface $formBuilder, FormClassNameServiceInterface $formClassNameService, RequestedActionServiceInterface $requestedActionService)
|
||||
{
|
||||
parent::__construct($formBuilder, $formClassNameService);
|
||||
$this->requestedActionService = $requestedActionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface::createByRequestedActionService()
|
||||
*/
|
||||
public function createByService(): FormBuilderInterface
|
||||
{
|
||||
return parent::create($this->requestedActionService);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedActionFormBuilderServiceInterface extends RequestedActionFormBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @return FormBuilderInterface Created by RequestedActionService
|
||||
*/
|
||||
public function createByService(): FormBuilderInterface;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntity;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
|
||||
/**
|
||||
* Allowes to create an form which fits to an entity.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface RequestedEntityFormBuilderServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param RequestedEntityInterface $requestedEntity
|
||||
*
|
||||
* @return FormBuilderInterface
|
||||
*/
|
||||
public function create(RequestedEntityInterface $requestedEntity): FormBuilderInterface;
|
||||
}
|
@ -6,7 +6,6 @@ use App\Domain\ActionManagement\Create\CreateSourceAction;
|
||||
use App\Domain\ActionManagement\ActionService;
|
||||
use App\Domain\ActionManagement\Create\CreateActionInterface;
|
||||
use App\Domain\ActionManagement\ActionServiceInterface;
|
||||
use App\Domain\FormManagement\RequestedEntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
@ -19,6 +18,7 @@ use App\DBAL\Types\ActionType;
|
||||
use App\Domain\RequestManagement\User\RequestedUserService;
|
||||
use App\Domain\UserManagement\UserSourceDirectorService;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
|
||||
/**
|
||||
* @todo Implement test and logic!!!!!
|
||||
@ -54,7 +54,7 @@ class CreateSourceActionIntegrationTest extends KernelTestCase
|
||||
$requestedUserService = new RequestedUserService($userSourceDirectorService, $requestedRightService);
|
||||
$this->requestedActionService = new RequestedActionService($userSourceDirectorService, $requestedUserService);
|
||||
$this->requestedActionService->setActionType(ActionType::CREATE);
|
||||
$entityFormBuilderService = $this->createMock(RequestedEntityFormBuilderServiceInterface::class);
|
||||
$entityFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
|
||||
$requestStack = $this->createMock(RequestStack::class);
|
||||
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
|
||||
|
@ -7,7 +7,6 @@ use App\Domain\ActionManagement\ActionService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Domain\FormManagement\RequestedEntityFormBuilderServiceInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use App\Domain\ActionManagement\ActionServiceInterface;
|
||||
@ -17,6 +16,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use App\Entity\EntityInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -34,9 +34,9 @@ class ActionServiceTest extends TestCase
|
||||
private $secureRequestedRightChecker;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityFormBuilderServiceInterface|MockObject
|
||||
* @var RequestedActionFormBuilderServiceInterface|MockObject
|
||||
*/
|
||||
private $requestedEntityFormBuilderService;
|
||||
private $requestedActionFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var RequestStack|MockObject
|
||||
@ -77,12 +77,13 @@ class ActionServiceTest extends TestCase
|
||||
|
||||
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||
$this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity);
|
||||
|
||||
$this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
|
||||
$this->requestedEntityFormBuilderService = $this->createMock(RequestedEntityFormBuilderServiceInterface::class);
|
||||
$this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
|
||||
$this->requestStack = $this->createMock(RequestStack::class);
|
||||
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$this->entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedEntityFormBuilderService, $this->entityManager);
|
||||
$this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager);
|
||||
}
|
||||
|
||||
public function testIsRequestedActionSecure(): void
|
||||
@ -120,7 +121,7 @@ class ActionServiceTest extends TestCase
|
||||
public function testGetForm(): void
|
||||
{
|
||||
$form = $this->createMock(FormBuilderInterface::class);
|
||||
$this->requestedEntityFormBuilderService->method('create')->willReturn($form);
|
||||
$this->requestedActionFormBuilderService->method('createByService')->willReturn($form);
|
||||
$result = $this->actionService->getForm();
|
||||
$this->assertEquals($form, $result);
|
||||
}
|
||||
|
@ -7,12 +7,13 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\FormManagement\FormClassNameServiceInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use App\Entity\Source\PureSource;
|
||||
use App\Domain\FormManagement\RequestedEntityFormBuilderService;
|
||||
use App\Domain\FormManagement\RequestedActionFormBuilderService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class EntityFormBuilderServiceTest extends TestCase
|
||||
class RequestedActionFormBuilderServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Could be that this test includes a bit to much mocking -.-.
|
||||
@ -24,12 +25,15 @@ class EntityFormBuilderServiceTest extends TestCase
|
||||
$formBuilder->method('create')->willReturn($expectedResult);
|
||||
$formClassNameService = $this->createMock(FormClassNameServiceInterface::class);
|
||||
$formClassNameService->method('getClass')->willReturn('dummyNamespace');
|
||||
$entityFormBuilderService = new RequestedEntityFormBuilderService($formBuilder, $formClassNameService);
|
||||
$entity = new PureSource();
|
||||
$entityRequested = $this->createMock(RequestedEntityInterface::class);
|
||||
$entityRequested->method('hasIdentity')->willReturn(true);
|
||||
$entityRequested->method('getEntity')->willReturn($entity);
|
||||
$result = $entityFormBuilderService->create($entityRequested);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
$requestedEntity->method('hasIdentity')->willReturn(true);
|
||||
$requestedEntity->method('getEntity')->willReturn($entity);
|
||||
$requestedAction = $this->createMock(RequestedActionServiceInterface::class);
|
||||
$requestedAction->method('getRequestedEntity')->willReturn($requestedEntity);
|
||||
$entityFormBuilderService = new RequestedActionFormBuilderService($formBuilder, $formClassNameService, $requestedAction);
|
||||
$result = $entityFormBuilderService->create($requestedAction);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
$this->assertEquals($entityFormBuilderService->create($requestedAction), $entityFormBuilderService->createByService());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user