Implemented validation of requestedAction for requestedActionFormBuilderTest

This commit is contained in:
Kevin Frantz 2019-02-12 19:24:34 +01:00
parent f60e1e1453
commit 1e1a1a892e
2 changed files with 41 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace App\Domain\FormManagement;
use Symfony\Component\Form\FormBuilderInterface;
use App\Domain\RequestManagement\Action\RequestedActionInterface;
use Symfony\Component\Form\FormFactoryInterface;
use App\Exception\NotSetException;
/**
* @author kevinfrantz
@ -21,6 +22,18 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
*/
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 FormClassNameServiceInterface $formClassNameService
@ -38,6 +51,7 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
*/
public function create(RequestedActionInterface $requestedAction): FormBuilderInterface
{
$this->validateRequestedAction($requestedAction);
$requestedEntity = $requestedAction->getRequestedEntity();
$actionType = $requestedAction->getActionType();
$origineClass = $requestedEntity->getClass();

View File

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