infinito/application/symfony/tests/Unit/Domain/ActionManagement/ActionServiceTest.php

129 lines
4.4 KiB
PHP
Raw Normal View History

2019-01-27 09:35:43 +01:00
<?php
namespace tests\Unit\Domain\ActionManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\ActionManagement\ActionService;
use App\Domain\RequestManagement\Action\RequestedActionInterface;
use App\Domain\SecureManagement\SecureRequestedRightCheckerInterface;
2019-01-27 15:28:25 +01:00
use Doctrine\ORM\EntityManagerInterface;
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;
use App\Domain\FormManagement\RequestedActionFormBuilderServiceInterface;
2019-01-27 09:35:43 +01:00
/**
* @author kevinfrantz
*/
class ActionServiceTest extends TestCase
{
2019-01-27 15:28:25 +01:00
/**
* @var RequestedActionInterface|MockObject
2019-01-27 15:28:25 +01:00
*/
private $requestedAction;
/**
* @var SecureRequestedRightCheckerInterface|MockObject
2019-01-27 15:28:25 +01:00
*/
private $secureRequestedRightChecker;
/**
* @var RequestedActionFormBuilderServiceInterface|MockObject
2019-01-27 15:28:25 +01:00
*/
private $requestedActionFormBuilderService;
2019-01-27 15:28:25 +01:00
/**
* @var RequestStack|MockObject
2019-01-27 15:28:25 +01:00
*/
private $requestStack;
/**
* @var LayerRepositoryFactoryServiceInterface|MockObject
2019-01-27 15:28:25 +01:00
*/
private $layerRepositoryFactoryService;
/**
* @var ActionServiceInterface
*/
private $actionService;
/**
* @var EntityManagerInterface|MockObject
2019-01-27 15:28:25 +01:00
*/
private $entityManager;
/**
* @var RequestedEntityInterface|MockObject
*/
private $requestedEntity;
/**
* @var EntityInterface|MockObject
*/
private $entity;
2019-01-27 15:28:25 +01:00
public function setUp(): void
{
$this->entity = $this->createMock(EntityInterface::class);
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
2019-01-27 15:28:25 +01:00
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
$this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity);
2019-01-27 15:28:25 +01:00
$this->secureRequestedRightChecker = $this->createMock(SecureRequestedRightCheckerInterface::class);
$this->requestedActionFormBuilderService = $this->createMock(RequestedActionFormBuilderServiceInterface::class);
2019-01-27 15:28:25 +01:00
$this->requestStack = $this->createMock(RequestStack::class);
$this->layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->actionService = new ActionService($this->requestedAction, $this->secureRequestedRightChecker, $this->requestStack, $this->layerRepositoryFactoryService, $this->requestedActionFormBuilderService, $this->entityManager);
2019-01-27 15:28:25 +01:00
}
public function testIsRequestedActionSecure(): void
2019-01-27 09:35:43 +01:00
{
2019-01-27 15:28:25 +01:00
$this->secureRequestedRightChecker->method('check')->willReturn(true);
$this->assertTrue($this->actionService->isRequestedActionSecure());
2019-01-27 09:35:43 +01:00
}
public function testRequestedActionGetter(): void
2019-01-27 09:35:43 +01:00
{
2019-01-27 15:28:25 +01:00
$this->assertInstanceOf(RequestedActionInterface::class, $this->actionService->getRequestedAction());
2019-01-27 09:35:43 +01:00
}
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);
}
2019-02-06 18:38:20 +01:00
public function testGetCurrentFormBuilder(): void
{
$form = $this->createMock(FormBuilderInterface::class);
$this->requestedActionFormBuilderService->method('createByService')->willReturn($form);
2019-02-06 18:38:20 +01:00
$result = $this->actionService->getCurrentFormBuilder();
$this->assertEquals($form, $result);
}
2019-01-27 09:35:43 +01:00
}