Added RequestedEntityAttribut

This commit is contained in:
Kevin Frantz 2019-01-20 11:33:05 +01:00
parent c5375d4e0d
commit cc491f5707
6 changed files with 100 additions and 8 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace App\Attribut;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
trait RequestedEntityAttribut
{
/**
* @var RequestedEntityInterface
*/
private $requestedEntity;
/**
* @return RequestedEntityInterface
*/
public function getRequestedEntity(): RequestedEntityInterface
{
return $this->requestedEntity;
}
/**
* @param RequestedEntityInterface $requestedEntity
*/
public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void
{
$this->requestedEntity = $requestedEntity;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Attribut;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
interface RequestedEntityAttributInterface
{
/**
* @return RequestedEntityInterface
*/
public function getRequestedEntity(): RequestedEntityInterface;
/**
* @param RequestedEntityInterface $requestedEntity
*/
public function setRequestedEntity(RequestedEntityInterface $requestedEntity): void;
}

View File

@ -33,7 +33,7 @@ class RequestedRight implements RequestedRightInterface
/**
* @var RequestedEntityInterface
*/
private $requestedSource;
private $requestedEntity;
/**
* @param SourceRepositoryInterface $sourceRepository
@ -45,7 +45,7 @@ class RequestedRight implements RequestedRightInterface
private function loadSource(): void
{
$this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedSource);
$this->source = $this->sourceRepository->findOneByIdOrSlug($this->requestedEntity);
}
/**
@ -53,10 +53,10 @@ class RequestedRight implements RequestedRightInterface
*/
private function validateRequestedEntity(): void
{
if ($this->requestedSource->hasSlug() || $this->requestedSource->hasId()) {
if ($this->requestedEntity->hasSlug() || $this->requestedEntity->hasId()) {
return;
}
throw new PreconditionFailedException(get_class($this->requestedSource).' needs to have a defined attribut id or slug!');
throw new PreconditionFailedException(get_class($this->requestedEntity).' needs to have a defined attribut id or slug!');
}
/**
@ -88,8 +88,8 @@ class RequestedRight implements RequestedRightInterface
*
* @see \App\Domain\RequestManagement\Right\RequestedRightInterface::setRequestedEntity()
*/
final public function setRequestedEntity(RequestedEntityInterface $requestedSource)
final public function setRequestedEntity(RequestedEntityInterface $requestedSource): void
{
$this->requestedSource = $requestedSource;
$this->requestedEntity = $requestedSource;
}
}

View File

@ -16,7 +16,7 @@ interface RequestedRightInterface extends CrudAttributInterface, RecieverAttribu
/**
* @param RequestedEntityInterface $requestedSource
*/
public function setRequestedEntity(RequestedEntityInterface $requestedSource);
public function setRequestedEntity(RequestedEntityInterface $requestedSource): void;
/**
* {@inheritdoc}

View File

@ -105,7 +105,7 @@ class RequestedUser implements RequestedUserInterface
/**
* @param RequestedEntityInterface $requestedSource
*/
public function setRequestedEntity(RequestedEntityInterface $requestedSource)
public function setRequestedEntity(RequestedEntityInterface $requestedSource): void
{
$this->requestedRight->setRequestedEntity($requestedSource);
}

View File

@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Attribut;
use PHPUnit\Framework\TestCase;
use App\Attribut\RequestedEntityAttribut;
use App\Attribut\RequestedEntityAttributInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/**
* @author kevinfrantz
*/
class RequestedEntityAttributTest extends TestCase
{
/**
* @var RequestedEntityAttributInterface
*/
protected $requestedEntityAttribut;
public function setUp(): void
{
$this->requestedEntityAttribut = new class() implements RequestedEntityAttributInterface {
use RequestedEntityAttribut;
};
}
public function testConstructor(): void
{
$this->expectException(\TypeError::class);
$this->requestedEntityAttribut->getRequestedEntity();
}
public function testAccessors(): void
{
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$this->assertNull($this->requestedEntityAttribut->setRequestedEntity($requestedEntity));
$this->assertEquals($requestedEntity, $this->requestedEntityAttribut->getRequestedEntity());
}
}