diff --git a/application/symfony/src/Domain/ActionManagement/ActionService.php b/application/symfony/src/Domain/ActionManagement/ActionService.php index 8655f33..1e7e62b 100644 --- a/application/symfony/src/Domain/ActionManagement/ActionService.php +++ b/application/symfony/src/Domain/ActionManagement/ActionService.php @@ -10,7 +10,6 @@ use App\Domain\FormManagement\EntityFormBuilderServiceInterface; use Symfony\Component\HttpFoundation\RequestStack; use App\Repository\RepositoryInterface; use Symfony\Component\Form\FormBuilderInterface; -use App\Entity\EntityInterface; use Doctrine\ORM\EntityManagerInterface; /** @@ -84,9 +83,11 @@ final class ActionService implements ActionServiceInterface /** * @return FormBuilderInterface */ - public function getForm(EntityInterface $entity): FormBuilderInterface + public function getForm(): FormBuilderInterface { - $this->entityFormBuilderService->create($entity); + $entity = $this->requestedAction->getRequestedEntity()->getEntity(); + + return $this->entityFormBuilderService->create($entity); } /** diff --git a/application/symfony/src/Domain/ActionManagement/ActionServiceInterface.php b/application/symfony/src/Domain/ActionManagement/ActionServiceInterface.php index 2171e7e..7923aba 100644 --- a/application/symfony/src/Domain/ActionManagement/ActionServiceInterface.php +++ b/application/symfony/src/Domain/ActionManagement/ActionServiceInterface.php @@ -6,7 +6,6 @@ use App\Domain\RequestManagement\Action\RequestedActionInterface; use Symfony\Component\HttpFoundation\Request; use App\Repository\RepositoryInterface; use Symfony\Component\Form\FormBuilderInterface; -use App\Entity\EntityInterface; use Doctrine\ORM\EntityManagerInterface; /** @@ -37,11 +36,9 @@ interface ActionServiceInterface public function getRepository(): RepositoryInterface; /** - * @param EntityInterface $entity - * * @return FormBuilderInterface */ - public function getForm(EntityInterface $entity): FormBuilderInterface; + public function getForm(): FormBuilderInterface; /** * @return EntityManagerInterface diff --git a/application/symfony/tests/Unit/Domain/ActionManagement/ActionServiceTest.php b/application/symfony/tests/Unit/Domain/ActionManagement/ActionServiceTest.php index e1506ef..6e92530 100644 --- a/application/symfony/tests/Unit/Domain/ActionManagement/ActionServiceTest.php +++ b/application/symfony/tests/Unit/Domain/ActionManagement/ActionServiceTest.php @@ -11,6 +11,12 @@ use App\Domain\FormManagement\EntityFormBuilderServiceInterface; use Symfony\Component\HttpFoundation\RequestStack; use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; use App\Domain\ActionManagement\ActionServiceInterface; +use App\Repository\RepositoryInterface; +use Symfony\Component\HttpFoundation\Request; +use App\Domain\RequestManagement\Entity\RequestedEntityInterface; +use PHPUnit\Framework\MockObject\MockObject; +use App\Entity\EntityInterface; +use Symfony\Component\Form\FormBuilderInterface; /** * @author kevinfrantz @@ -18,27 +24,27 @@ use App\Domain\ActionManagement\ActionServiceInterface; class ActionServiceTest extends TestCase { /** - * @var RequestedActionInterface + * @var RequestedActionInterface|MockObject */ private $requestedAction; /** - * @var SecureRequestedRightCheckerInterface + * @var SecureRequestedRightCheckerInterface|MockObject */ private $secureRequestedRightChecker; /** - * @var EntityFormBuilderServiceInterface + * @var EntityFormBuilderServiceInterface|MockObject */ private $entityFormBuilderService; /** - * @var RequestStack + * @var RequestStack|MockObject */ private $requestStack; /** - * @var LayerRepositoryFactoryServiceInterface + * @var LayerRepositoryFactoryServiceInterface|MockObject */ private $layerRepositoryFactoryService; @@ -48,13 +54,29 @@ class ActionServiceTest extends TestCase private $actionService; /** - * @var EntityManagerInterface + * @var EntityManagerInterface|MockObject */ private $entityManager; + /** + * @var RequestedEntityInterface|MockObject + */ + private $requestedEntity; + + /** + * @var EntityInterface|MockObject + */ + private $entity; + public function setUp(): void { + $this->entity = $this->createMock(EntityInterface::class); + + $this->requestedEntity = $this->createMock(RequestedEntityInterface::class); + $this->requestedEntity->method('getEntity')->willReturn($this->entity); + $this->requestedAction = $this->createMock(RequestedActionInterface::class); + $this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity); $this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class); $this->entityFormBuilderService = $this->createMock(EntityFormBuilderServiceInterface::class); $this->requestStack = $this->createMock(RequestStack::class); @@ -63,14 +85,43 @@ class ActionServiceTest extends TestCase $this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->entityFormBuilderService, $this->entityManager); } - public function testIsRequestedActionSecure() + public function testIsRequestedActionSecure(): void { $this->secureRequestedRightChecker->method('check')->willReturn(true); $this->assertTrue($this->actionService->isRequestedActionSecure()); } - public function testRequestedActionGetter() + public function testRequestedActionGetter(): void { $this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction()); } + + public function testGetEntityManager(): void + { + $this->assertEquals($this->entityManager, $this->actionService->getEntityManager()); + } + + public function testGetRepository(): void + { + $repository = $this->createMock(RepositoryInterface::class); + $this->layerRepositoryFactoryService->method('getRepository')->willReturn($repository); + $result = $this->actionService->getRepository(); + $this->assertEquals($repository, $result); + } + + public function testGetRequest(): void + { + $request = $this->createMock(Request::class); + $this->requestStack->method('getCurrentRequest')->willReturn($request); + $result = $this->actionService->getRequest(); + $this->assertEquals($request, $result); + } + + public function testGetForm(): void + { + $form = $this->createMock(FormBuilderInterface::class); + $this->entityFormBuilderService->method('create')->willReturn($form); + $result = $this->actionService->getForm(); + $this->assertEquals($form, $result); + } }