Implemented AbstractRequestedRightFacade

This commit is contained in:
Kevin Frantz 2019-01-20 12:54:39 +01:00
parent cc491f5707
commit b2d50e3cfd
6 changed files with 213 additions and 79 deletions

View File

@ -26,11 +26,6 @@ class RequestedAction extends RequestedUser implements RequestedActionInterface
ActionType::LIST => CRUDType::READ,
];
/**
* @var RequestedRightInterface
*/
private $requestedRight;
/**
* @param RequestedRightInterface $requestedRight
*/

View File

@ -0,0 +1,117 @@
<?php
namespace App\Domain\RequestManagement\Right;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Entity\Source\SourceInterface;
/**
* Offers a facade to wrapp a requested right.
*
* @author kevinfrantz
*/
abstract class AbstractRequestedRightFacade implements RequestedRightInterface
{
/**
* @var RequestedRightInterface
*/
protected $requestedRight;
/**
* @param RequestedRightInterface $requestedRight
*/
public function __construct(RequestedRightInterface $requestedRight)
{
$this->requestedRight = $requestedRight;
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\RecieverAttributInterface::getReciever()
*/
public function getReciever(): SourceInterface
{
return $this->requestedRight->getReciever();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\LayerAttributInterface::setLayer()
*/
public function setLayer(string $layer): void
{
$this->requestedRight->setLayer($layer);
}
/**
* @deprecated
* {@inheritdoc}
* @see \App\Domain\RequestManagement\Right\RequestedRightInterface::getSource()
*/
public function getSource(): SourceInterface
{
return $this->requestedRight->getSource();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\LayerAttributInterface::getLayer()
*/
public function getLayer(): string
{
return $this->requestedRight->getLayer();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\RequestedEntityAttributInterface::setRequestedEntity()
*/
public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void
{
$this->requestedRight->setRequestedEntity($requestedEntity);
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\CrudAttributInterface::setCrud()
*/
public function setCrud(string $crud): void
{
$this->requestedRight->setCrud($crud);
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\CrudAttributInterface::getCrud()
*/
public function getCrud(): string
{
return $this->requestedRight->getCrud();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\RequestedEntityAttributInterface::getRequestedEntity()
*/
public function getRequestedEntity(): RequestedEntityInterface
{
return $this->requestedRight->getRequestedEntity();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\RecieverAttributInterface::setReciever()
*/
public function setReciever(SourceInterface $reciever): void
{
$this->requestedRight->setReciever($reciever);
}
}

View File

@ -10,6 +10,7 @@ use App\Exception\PreconditionFailedException;
use App\Exception\NotSetException;
use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Attribut\RequestedEntityAttribut;
/**
* @author kevinfrantz
@ -18,7 +19,7 @@ use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
*/
class RequestedRight implements RequestedRightInterface
{
use CrudAttribut, LayerAttribut, RecieverAttribut;
use CrudAttribut, LayerAttribut, RecieverAttribut, RequestedEntityAttribut;
/**
* @var SourceRepositoryInterface

View File

@ -6,18 +6,13 @@ use App\Attribut\CrudAttributInterface;
use App\Attribut\RecieverAttributInterface;
use App\Attribut\LayerAttributInterface;
use App\Entity\Source\SourceInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Attribut\RequestedEntityAttributInterface;
/**
* @author kevinfrantz
*/
interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface
interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface, RequestedEntityAttributInterface
{
/**
* @param RequestedEntityInterface $requestedSource
*/
public function setRequestedEntity(RequestedEntityInterface $requestedSource): void;
/**
* {@inheritdoc}
*

View File

@ -6,30 +6,25 @@ use App\Entity\Source\SourceInterface;
use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Exception\SetNotPossibleException;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Domain\RequestManagement\Right\AbstractRequestedRightFacade;
/**
* @author kevinfrantz
*/
class RequestedUser implements RequestedUserInterface
class RequestedUser extends AbstractRequestedRightFacade implements RequestedUserInterface
{
/**
* @var UserSourceDirectorInterface
*/
private $userSourceDirector;
/**
* @var RequestedRightInterface
*/
private $requestedRight;
/**
* @param UserSourceDirectorInterface $userSourceDirector
*/
public function __construct(UserSourceDirectorInterface $userSourceDirector, RequestedRightInterface $requestedRight)
{
$this->userSourceDirector = $userSourceDirector;
$this->requestedRight = $requestedRight;
parent::__construct($requestedRight);
}
/**
@ -51,62 +46,4 @@ class RequestedUser implements RequestedUserInterface
{
return $this->userSourceDirector->getUser()->getSource();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\LayerAttributInterface::setLayer()
*/
public function setLayer(string $layer): void
{
$this->requestedRight->setLayer($layer);
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\CrudAttributInterface::getCrud()
*/
public function getCrud(): string
{
return $this->requestedRight->getCrud();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\LayerAttributInterface::getLayer()
*/
public function getLayer(): string
{
return $this->requestedRight->getLayer();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\SourceAttributInterface::getSource()
*/
public function getSource(): SourceInterface
{
return $this->requestedRight->getSource();
}
/**
* {@inheritdoc}
*
* @see \App\Attribut\CrudAttributInterface::setCrud()
*/
public function setCrud(string $type): void
{
$this->requestedRight->setCrud($type);
}
/**
* @param RequestedEntityInterface $requestedSource
*/
public function setRequestedEntity(RequestedEntityInterface $requestedSource): void
{
$this->requestedRight->setRequestedEntity($requestedSource);
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace tests\Unit\Domain\RightManagement\User;
use PHPUnit\Framework\TestCase;
use App\Entity\User;
use App\Domain\RequestManagement\User\RequestedUser;
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\AbstractSource;
use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Right\RequestedRight;
use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\DBAL\Types\SystemSlugType;
use App\Exception\SetNotPossibleException;
use App\Entity\Source\SourceInterface;
use App\Domain\RequestManagement\Right\AbstractRequestedRightFacade;
/**
* @author kevinfrantz
*/
class AbstractRequestedRightFacadeTest extends TestCase
{
private function getRequestedRightFacade(RequestedRightInterface $requestedRight): AbstractRequestedRightFacade
{
return new class($requestedRight) extends AbstractRequestedRightFacade {
// public function __construct(RequestedRightInterface $requestedRight){
// $this->requestedRight = $requestedRight;
// }
};
}
public function testGetters(): void
{
$reciever = $this->createMock(AbstractSource::class);
$user = $this->createMock(User::class);
$user->method('getSource')->willReturn($reciever);
$layer = LayerType::SOURCE;
$type = CRUDType::READ;
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$source = $this->createMock(AbstractSource::class);
$reciever = $this->createMock(AbstractSource::class);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedRight->method('getLayer')->willReturn($layer);
$requestedRight->method('getCrud')->willReturn($type);
$requestedRight->method('getSource')->willReturn($source);
$requestedRight->method('getReciever')->willReturn($reciever);
$requestedRight->method('getRequestedEntity')->willReturn($requestedEntity);
$requestedRightFacade = $this->getRequestedRightFacade($requestedRight);
$this->assertEquals($layer, $requestedRightFacade->getLayer());
$this->assertEquals($type, $requestedRightFacade->getCrud());
$this->assertEquals($source, $requestedRightFacade->getSource());
$this->assertEquals($reciever, $requestedRightFacade->getReciever());
$this->assertEquals($requestedEntity, $requestedRightFacade->getRequestedEntity());
}
public function testSetters(): void
{
$layer = LayerType::SOURCE;
$type = CRUDType::READ;
$reciever = $this->createMock(SourceInterface::class);
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$requestedEntity->method('hasSlug')->willReturn(true);
$sourceRepository = $this->createMock(SourceRepositoryInterface::class);
$requestedRight = new RequestedRight($sourceRepository);
$requestedRightFacade = $this->getRequestedRightFacade($requestedRight);
$this->assertNull($requestedRightFacade->setLayer($layer));
$this->assertNull($requestedRightFacade->setCrud($type));
$this->assertNull($requestedRightFacade->setRequestedEntity($requestedEntity));
$this->assertNull($requestedRightFacade->setReciever($reciever));
$this->assertEquals($layer, $requestedRight->getLayer());
$this->assertEquals($type, $requestedRight->getCrud());
$this->assertEquals($requestedEntity, $requestedRight->getRequestedEntity());
$this->assertEquals($reciever, $requestedRight->getReciever());
}
public function testSetReciever(): void
{
$reciever = $this->createMock(AbstractSource::class);
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->expectException(SetNotPossibleException::class);
$requestedUserRightFacade->setReciever($reciever);
}
}