mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 10:16:22 +02:00
Implemented validation of requestedAction for requestedActionFormBuilderTest
This commit is contained in:
parent
f60e1e1453
commit
1e1a1a892e
@ -5,6 +5,7 @@ namespace App\Domain\FormManagement;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||||
use Symfony\Component\Form\FormFactoryInterface;
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
|
use App\Exception\NotSetException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
@ -21,6 +22,18 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
|
|||||||
*/
|
*/
|
||||||
private $formClassNameService;
|
private $formClassNameService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RequestedActionInterface $requestedAction
|
||||||
|
*
|
||||||
|
* @throws NotSetException If the requested action can't be processed
|
||||||
|
*/
|
||||||
|
private function validateRequestedAction(RequestedActionInterface $requestedAction): void
|
||||||
|
{
|
||||||
|
if (!$requestedAction->hasRequestedEntity()) {
|
||||||
|
throw new NotSetException('The <<requested entity>> attribut of a <<requested action>> must be set, to be processed by '.__CLASS__.'!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FormFactoryInterface $formFactory
|
* @param FormFactoryInterface $formFactory
|
||||||
* @param FormClassNameServiceInterface $formClassNameService
|
* @param FormClassNameServiceInterface $formClassNameService
|
||||||
@ -38,6 +51,7 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
|
|||||||
*/
|
*/
|
||||||
public function create(RequestedActionInterface $requestedAction): FormBuilderInterface
|
public function create(RequestedActionInterface $requestedAction): FormBuilderInterface
|
||||||
{
|
{
|
||||||
|
$this->validateRequestedAction($requestedAction);
|
||||||
$requestedEntity = $requestedAction->getRequestedEntity();
|
$requestedEntity = $requestedAction->getRequestedEntity();
|
||||||
$actionType = $requestedAction->getActionType();
|
$actionType = $requestedAction->getActionType();
|
||||||
$origineClass = $requestedEntity->getClass();
|
$origineClass = $requestedEntity->getClass();
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace tests\Unit\Domain\FormManagement;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use App\Exception\NotSetException;
|
||||||
|
use App\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||||
|
use App\Domain\FormManagement\RequestedActionFormBuilder;
|
||||||
|
use App\Domain\FormManagement\FormClassNameServiceInterface;
|
||||||
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class RequestedActionFormBuilderTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRequestedActionNotValid(): void
|
||||||
|
{
|
||||||
|
$requestedAction = $this->createMock(RequestedActionInterface::class);
|
||||||
|
$requestedAction->method('hasRequestedEntity')->willReturn(false);
|
||||||
|
$formFactory = $this->createMock(FormFactoryInterface::class);
|
||||||
|
$formClassNameService = $this->createMock(FormClassNameServiceInterface::class);
|
||||||
|
$requestedActionFormBuilder = new RequestedActionFormBuilder($formFactory, $formClassNameService);
|
||||||
|
$this->expectException(NotSetException::class);
|
||||||
|
$requestedActionFormBuilder->create($requestedAction);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user