mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Transformed Unit test to Integration test for RequestedActionFormBuilderService
This commit is contained in:
parent
d6a29af72a
commit
357319fd6c
@ -42,9 +42,7 @@ class RequestedActionFormBuilder implements RequestedActionFormBuilderInterface
|
||||
$actionType = $requestedAction->getActionType();
|
||||
$origineClass = $requestedEntity->getClass();
|
||||
$class = $this->formClassNameService->getClass($origineClass, $actionType);
|
||||
if ($requestedEntity->hasIdentity()) {
|
||||
$entity = $requestedEntity->getEntity();
|
||||
}
|
||||
$entity = ($requestedEntity->hasIdentity()) ? $requestedEntity->getEntity() : null;
|
||||
$form = $this->formFactory->createBuilder($class, $entity);
|
||||
|
||||
return $form;
|
||||
|
@ -7,7 +7,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class PureSourceType extends SourceType
|
||||
final class PureSourceCreateType extends SourceType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
@ -6,6 +6,8 @@ use App\Form\TypeInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @todo Rename!
|
||||
*/
|
||||
interface PureSourceTypeInterface extends TypeInterface
|
||||
{
|
||||
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Integration\Domain\FormManagement;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use App\Entity\Source\PureSource;
|
||||
use App\Domain\FormManagement\RequestedActionFormBuilderService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use App\Domain\FormManagement\FormClassNameService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionService;
|
||||
use App\Domain\RequestManagement\User\RequestedUserService;
|
||||
use App\Domain\RequestManagement\Right\RequestedRightService;
|
||||
use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
|
||||
use App\DBAL\Types\ActionType;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityService;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RequestedActionFormBuilderServiceIntegrationTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var RequestedActionServiceInterface
|
||||
*/
|
||||
private $requestedActionService;
|
||||
|
||||
/**
|
||||
* @var RequestedActionFormBuilderService
|
||||
*/
|
||||
private $requestedActionFormBuilderService;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityInterface
|
||||
*/
|
||||
private $requestedEntity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \PHPUnit\Framework\TestCase::setUp()
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$formFactory = self::$container->get('form.factory');
|
||||
//$entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$userSourceDirectorService = $this->createMock(UserSourceDirectorServiceInterface::class);
|
||||
$formClassNameService = new FormClassNameService();
|
||||
$layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager);
|
||||
$this->requestedEntity = new RequestedEntityService($layerRepositoryFactoryService);
|
||||
$requestedRightService = new RequestedRightService();
|
||||
$requestedRightService->setRequestedEntity($this->requestedEntity);
|
||||
$requestedUserService = new RequestedUserService($userSourceDirectorService, $requestedRightService);
|
||||
$this->requestedActionService = new RequestedActionService($userSourceDirectorService, $requestedUserService);
|
||||
$this->requestedActionService->setActionType(ActionType::CREATE);
|
||||
$this->requestedActionFormBuilderService = new RequestedActionFormBuilderService($formFactory, $formClassNameService, $this->requestedActionService);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$class = PureSource::class;
|
||||
$this->requestedEntity->setClass($class);
|
||||
$result = $this->requestedActionFormBuilderService->create($this->requestedActionService);
|
||||
//$this->assertTrue(method_exists($result, 'isValid'));
|
||||
$this->assertInstanceOf(FormBuilderInterface::class, $result);
|
||||
//Tests if the origine builder and the service function return the same value by the requestedActionService
|
||||
$this->assertEquals($this->requestedActionFormBuilderService->create($this->requestedActionService), $this->requestedActionFormBuilderService->createByService());
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\FormManagement;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
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\RequestedActionFormBuilderService;
|
||||
use App\Domain\RequestManagement\Action\RequestedActionServiceInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class RequestedActionFormBuilderServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Could be that this test includes a bit to much mocking -.-.
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$formBuilder = $this->createMock(FormBuilderInterface::class);
|
||||
$formFactory = $this->createMock(FormFactoryInterface::class);
|
||||
$formFactory->method('create')->willReturn($formBuilder);
|
||||
$formClassNameService = $this->createMock(FormClassNameServiceInterface::class);
|
||||
$formClassNameService->method('getClass')->willReturn('dummyNamespace');
|
||||
$entity = new PureSource();
|
||||
$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($formFactory, $formClassNameService, $requestedAction);
|
||||
$result = $entityFormBuilderService->create($requestedAction);
|
||||
//$this->assertTrue(method_exists($result, 'isValid'));
|
||||
$this->assertEquals($formBuilder, $result);
|
||||
$this->assertEquals($entityFormBuilderService->create($requestedAction), $entityFormBuilderService->createByService());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user