Optimized ActionFactoryServiceTest

This commit is contained in:
Kevin Frantz 2019-02-26 20:06:07 +01:00
parent 776a7fe282
commit e5b31d7727

View File

@ -1,13 +1,11 @@
<?php
namespace tests\Unit\Domain\SecureCRUDManagement\Factory;
namespace tests\Unit\Domain\ActionManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\ActionManagement\ActionFactoryServiceInterface;
use Infinito\Domain\ActionManagement\ActionFactoryService;
use Infinito\Domain\ActionManagement\ActionServiceInterface;
use Infinito\Domain\ActionManagement\ActionInterface;
use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
use Infinito\Domain\RequestManagement\Action\RequestedAction;
use Infinito\Domain\RequestManagement\Right\RequestedRight;
use Infinito\Domain\LayerManagement\LayerActionMap;
@ -19,39 +17,20 @@ use Infinito\Domain\UserManagement\UserSourceDirectorInterface;
*/
class ActionFactoryServiceTest extends TestCase
{
/**
* @var ActionFactoryServiceInterface
*/
private $actionFactoryService;
/**
* @var ActionServiceInterface
*/
private $actionService;
/**
* @var RequestedActionInterface
*/
private $requestedAction;
public function setUp(): void
{
$requestedRight = new RequestedRight();
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedUser = new RequestedUser($userSourceDirector, $requestedRight);
$this->requestedAction = new RequestedAction($requestedUser);
$this->actionService = $this->createMock(ActionServiceInterface::class);
$this->actionService->method('getRequestedAction')->willReturn($this->requestedAction);
$this->actionFactoryService = new ActionFactoryService($this->actionService);
}
public function testCreate(): void
{
foreach (LayerActionMap::LAYER_ACTION_MAP as $layer => $actions) {
foreach ($actions as $action) {
$this->requestedAction->setLayer($layer);
$this->requestedAction->setActionType($action);
$result = $this->actionFactoryService->create();
$requestedRight = new RequestedRight();
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedUser = new RequestedUser($userSourceDirector, $requestedRight);
$requestedAction = new RequestedAction($requestedUser);
$actionService = $this->createMock(ActionServiceInterface::class);
$actionService->method('getRequestedAction')->willReturn($requestedAction);
$actionFactoryService = new ActionFactoryService($actionService);
$requestedAction->setLayer($layer);
$requestedAction->setActionType($action);
$result = $actionFactoryService->create();
$this->assertInstanceOf(ActionInterface::class, $result);
}
}