infinito/application/symfony/tests/Unit/Domain/Action/Read/ReadSourceActionTest.php

73 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2019-01-27 15:28:25 +01:00
<?php
namespace tests\Unit\Domain\SecureCRUDManagement\CRUD\Read;
use Doctrine\ORM\EntityManagerInterface;
use Infinito\Domain\Action\ActionDependenciesDAOServiceInterface;
2020-04-02 21:13:35 +02:00
use Infinito\Domain\Action\Read\ReadAction;
use Infinito\Domain\Action\Read\ReadActionInterface;
use Infinito\Domain\Request\Action\RequestedActionInterface;
use Infinito\Domain\Request\Entity\RequestedEntityInterface;
use Infinito\Entity\Source\SourceInterface;
2019-04-15 01:37:17 +02:00
use Infinito\Exception\Permission\NoPermissionException;
2020-04-02 21:13:35 +02:00
use PHPUnit\Framework\TestCase;
2019-01-27 15:28:25 +01:00
/**
* @author kevinfrantz
*/
class ReadSourceActionTest extends TestCase
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var ActionDependenciesDAOServiceInterface
2019-01-27 15:28:25 +01:00
*/
private $actionService;
/**
* @var ReadActionInterface
*/
private $sourceReadAction;
/**
* @var RequestedEntityInterface
*/
private $requestedEntity;
/**
* @var SourceInterface
*/
private $entity;
public function setUp(): void
{
$this->entity = $this->createMock(SourceInterface::class);
$this->requestedEntity = $this->createMock(RequestedEntityInterface::class);
$this->requestedEntity->method('getEntity')->willReturn($this->entity);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->requestedAction = $this->createMock(RequestedActionInterface::class);
$this->requestedAction->method('getRequestedEntity')->willReturn($this->requestedEntity);
$this->actionService = $this->createMock(ActionDependenciesDAOServiceInterface::class);
2019-01-27 15:28:25 +01:00
$this->actionService->method('getEntityManager')->willReturn($this->entityManager);
$this->actionService->method('getRequestedAction')->willReturn($this->requestedAction);
$this->sourceReadAction = new ReadAction($this->actionService);
}
public function testNotSecureException(): void
{
$this->actionService->method('isRequestedActionSecure')->willReturn(false);
2019-04-15 01:37:17 +02:00
$this->expectException(NoPermissionException::class);
2019-01-27 15:28:25 +01:00
$this->sourceReadAction->execute();
}
public function testGranted(): void
{
$this->actionService->method('isRequestedActionSecure')->willReturn(true);
$result = $this->sourceReadAction->execute();
$this->assertEquals($this->entity, $result);
}
}