mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented validation of requestedAction for requestedActionFormBuilderTest
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user