Refactored draft for Request Management

This commit is contained in:
Kevin Frantz 2019-01-20 12:54:56 +01:00
parent 7e9916b27b
commit 86198ff2df
40 changed files with 490 additions and 176 deletions

View File

@ -0,0 +1,36 @@
<?php
namespace App\Domain\CRUDManagement;
use App\Entity\EntityInterface;
use App\Repository\RepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
/**
* @author kevinfrantz
*/
final class RepositoryFactoryService implements RepositoryFactoryServiceInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @param EntityManagerInterface $entityManager
*/
private function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* {@inheritdoc}
*
* @see \App\Domain\CRUDManagement\RepositoryFactoryInterface::getRepository()
*/
public function getRepository(EntityInterface $entity): RepositoryInterface
{
$this->entityManager->getRepository(get_class($entity));
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Domain\CRUDManagement;
use App\Repository\RepositoryInterface;
use App\Entity\EntityInterface;
/**
* Offers a fabric for entity repositories.
*
* @author kevinfrantz
*/
interface RepositoryFactoryServiceInterface
{
/**
* @param EntityInterface $entity
*
* @return RepositoryInterface The repositoy of the interface
*/
public function getRepository(EntityInterface $entity): RepositoryInterface;
}

View File

@ -9,6 +9,9 @@ A folder MUST end on the suffix ** *Management ** to show that it has the purpos
# Domain Overview # Domain Overview
## CRUD Management
### Repository Factory Service
Offers a fabric for entity repositories.
## Entity Management ## Entity Management
### Entity Meta Information ### ### Entity Meta Information ###
Offers some meta information about an entity Offers some meta information about an entity
@ -31,18 +34,7 @@ Maps a path to a namespace.
## Request Management ## Request Management
Offers classes to manage requests for rights, users and sources. Offers classes to manage requests for rights, users and sources. A [detailed description](./RequestManagement/README.md) is available.
### Logic
- Requested Right
- Requested Source
- Requested User
### Services
- Requested Right Service
- Requested Source Service
- Requested User Service
## Right Management ## Right Management
### Right Checker ### ### Right Checker ###
Checks if the crud, layer and source combination is granted by a right. Checks if the crud, layer and source combination is granted by a right.

View File

@ -0,0 +1,74 @@
<?php
namespace App\Domain\RequestManagement\Action;
use App\Entity\Attribut\ActionTypeAttribut;
use App\DBAL\Types\ActionType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Domain\RequestManagement\User\RequestedUser;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
/**
* @author kevinfrantz
* @todo Implement!
*/
class RequestedAction extends RequestedUser implements RequestedActionInterface
{
use ActionTypeAttribut{
setActionType as setActionTypeTrait;
}
/**
* @var array Containes the mapping of non standard actions to a crud
*/
const ACTION_CRUD_MAP = [
ActionType::LIST => CRUDType::READ,
];
/**
* @var RequestedRightInterface
*/
private $requestedRight;
/**
* @param RequestedRightInterface $requestedRight
*/
public function __construct(RequestedRightInterface $requestedRight)
{
$this->requestedRight = $requestedRight;
}
/**
* {@inheritdoc}
*
* @see \App\Entity\Attribut\ActionTypeAttributInterface::setActionType()
*/
public function setActionType(string $actionType): void
{
$this->setActionTypeTrait($actionType);
$this->setRequestedRightCrudType($actionType);
}
/**
* @param string $actionType
*/
private function setRequestedRightCrudType(string $actionType): void
{
$crudType = $this->getCrudType($actionType);
$this->requestedRight->setCrud($crudType);
}
/**
* @param string $actionType
*
* @return string
*/
private function getCrudType(string $actionType): string
{
if (key_exists($actionType, self::ACTION_CRUD_MAP)) {
return self::ACTION_CRUD_MAP[$actionType];
}
return $actionType;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Domain\RequestManagement\Action;
use App\Entity\Attribut\ActionTypeAttributInterface;
use App\Domain\RequestManagement\User\RequestedUserInterface;
/**
* An action containes multiple attributes which are neccessary to process a request.
*
* @see ActionType
* @author kevinfrantz
*/
interface RequestedActionInterface extends ActionTypeAttributInterface, RequestedUserInterface
{
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Domain\RequestManagement\Action;
use App\Domain\RequestManagement\Right\RequestedRightServiceInterface;
/**
* @author kevinfrantz
*/
final class RequestedActionService extends RequestedAction implements RequestedActionServiceInterface
{
/**
* @param RequestedRightServiceInterface $requestedRightService
*/
public function __construct(RequestedRightServiceInterface $requestedRightService)
{
parent::__construct($requestedRightService);
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Domain\RequestManagement\Action;
/**
* Allows to use a action as a service.
* @todo Implement!
* @author kevinfrantz
*/
interface RequestedActionServiceInterface
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Domain\RequestManagement\Entity;
use App\Entity\AbstractEntity;
/**
* @author kevinfrantz
*/
class RequestedEntity extends AbstractEntity implements RequestedEntityInterface
{
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Domain\RequestManagement\Entity;
use App\Entity\EntityInterface;
/**
* @author kevinfrantz
*/
interface RequestedEntityInterface extends EntityInterface
{
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Domain\RequestManagement\Entity;
/**
* @author kevinfrantz
*/
final class RequestedEntityService extends RequestedEntity implements RequestedEntityServiceInterface
{
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Domain\RequestManagement\Entity;
/**
* @author kevinfrantz
*/
interface RequestedEntityServiceInterface
{
}

View File

@ -0,0 +1,12 @@
# Request Management
The request management works with different layers.
### Layers
Each layer contains out of __2 classes__ and __2 interfaces__ for it.
One class contains the __logic__ and the other class contains the __service__. This makes the classes easier testable and mockable and follows the [SOLID Design Principles](https://en.wikipedia.org/wiki/SOLID). The layer order you can keep in mind with the acronym __RUAE__: __R__ight__U__ser__A__ction__E__ntity.
#### Right
This is the basic request layer from which the other layers inhiere.
#### User
#### Action
#### Entity

View File

@ -1,12 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
use App\Entity\Source\AbstractSource;
/**
* @author kevinfrantz
*/
class RequestedSource extends AbstractSource implements RequestedSourceInterface
{
}

View File

@ -1,12 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
use App\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
*/
interface RequestedSourceInterface extends SourceInterface
{
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
/**
* @author kevinfrantz
*/
final class RequestedSourceService extends RequestedSource implements RequestedSourceServiceInterface
{
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
/**
* @author kevinfrantz
*/
interface RequestedSourceServiceInterface
{
}

View File

@ -1,12 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
/**
* Offers a Service for managing the rights.
*
* @author kevinfrantz
*/
interface RequestedUserRightInterface extends RequestedRightInterface
{
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Domain\RequestManagement;
/**
* @author kevinfrantz
*/
interface RequestedUserRightServiceInterface extends RequestedUserRightInterface
{
}

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\Right;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Entity\Attribut\CrudAttribut; use App\Entity\Attribut\CrudAttribut;
@ -9,6 +9,7 @@ use App\Entity\Attribut\RecieverAttribut;
use App\Exception\PreconditionFailedException; use App\Exception\PreconditionFailedException;
use App\Exception\NotSetException; use App\Exception\NotSetException;
use App\Repository\Source\SourceRepositoryInterface; use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -30,7 +31,7 @@ class RequestedRight implements RequestedRightInterface
private $source; private $source;
/** /**
* @var RequestedSourceInterface * @var RequestedEntityInterface
*/ */
private $requestedSource; private $requestedSource;
@ -50,7 +51,7 @@ class RequestedRight implements RequestedRightInterface
/** /**
* @throws PreconditionFailedException If the source has no id or slug * @throws PreconditionFailedException If the source has no id or slug
*/ */
private function validateRequestedSource(): void private function validateRequestedEntity(): void
{ {
if ($this->requestedSource->hasSlug() || $this->requestedSource->hasId()) { if ($this->requestedSource->hasSlug() || $this->requestedSource->hasId()) {
return; return;
@ -63,11 +64,11 @@ class RequestedRight implements RequestedRightInterface
* *
* @see https://en.wikipedia.org/wiki/Lazy_loading * @see https://en.wikipedia.org/wiki/Lazy_loading
* {@inheritdoc} * {@inheritdoc}
* @see \App\Domain\RequestManagement\RequestedRightInterface::getSource() * @see \App\Domain\RequestManagement\Right\RequestedRightInterface::getSource()
*/ */
final public function getSource(): SourceInterface final public function getSource(): SourceInterface
{ {
$this->validateRequestedSource(); $this->validateRequestedEntity();
$this->loadSource(); $this->loadSource();
$this->validateLoad(); $this->validateLoad();
@ -85,9 +86,9 @@ class RequestedRight implements RequestedRightInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource() * @see \App\Domain\RequestManagement\Right\RequestedRightInterface::setRequestedEntity()
*/ */
final public function setRequestedSource(RequestedSourceInterface $requestedSource) final public function setRequestedEntity(RequestedEntityInterface $requestedSource)
{ {
$this->requestedSource = $requestedSource; $this->requestedSource = $requestedSource;
} }

View File

@ -1,11 +1,12 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\Right;
use App\Entity\Attribut\CrudAttributInterface; use App\Entity\Attribut\CrudAttributInterface;
use App\Entity\Attribut\RecieverAttributInterface; use App\Entity\Attribut\RecieverAttributInterface;
use App\Entity\Attribut\LayerAttributInterface; use App\Entity\Attribut\LayerAttributInterface;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -13,9 +14,9 @@ use App\Entity\Source\SourceInterface;
interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface interface RequestedRightInterface extends CrudAttributInterface, RecieverAttributInterface, LayerAttributInterface
{ {
/** /**
* @param RequestedSourceInterface $requestedSource * @param RequestedEntityInterface $requestedSource
*/ */
public function setRequestedSource(RequestedSourceInterface $requestedSource); public function setRequestedEntity(RequestedEntityInterface $requestedSource);
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\Right;
/** /**
* Allows to use a right as a Service. * Allows to use a right as a Service.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\Right;
/** /**
* Allows to use a right as a Service. * Allows to use a right as a Service.

View File

@ -1,15 +1,17 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\User;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\UserManagement\UserSourceDirectorInterface; use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Exception\SetNotPossibleException; use App\Exception\SetNotPossibleException;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class RequestedUserRight implements RequestedUserRightInterface class RequestedUser implements RequestedUserInterface
{ {
/** /**
* @var UserSourceDirectorInterface * @var UserSourceDirectorInterface
@ -101,12 +103,10 @@ class RequestedUserRight implements RequestedUserRightInterface
} }
/** /**
* {@inheritdoc} * @param RequestedEntityInterface $requestedSource
*
* @see \App\Domain\RequestManagement\RequestedRightInterface::setRequestedSource()
*/ */
public function setRequestedSource(RequestedSourceInterface $requestedSource) public function setRequestedEntity(RequestedEntityInterface $requestedSource)
{ {
$this->requestedRight->setRequestedSource($requestedSource); $this->requestedRight->setRequestedEntity($requestedSource);
} }
} }

View File

@ -0,0 +1,14 @@
<?php
namespace App\Domain\RequestManagement\User;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
/**
* Offers a Service for managing the rights.
*
* @author kevinfrantz
*/
interface RequestedUserInterface extends RequestedRightInterface
{
}

View File

@ -1,13 +1,14 @@
<?php <?php
namespace App\Domain\RequestManagement; namespace App\Domain\RequestManagement\User;
use App\Domain\UserManagement\UserSourceDirectorServiceInterface; use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
use App\Domain\RequestManagement\Right\RequestedRightServiceInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
final class RequestedUserRightService extends RequestedUserRight implements RequestedUserRightServiceInterface final class RequestedUserService extends RequestedUser implements RequestedUserServiceInterface
{ {
/** /**
* @param UserSourceDirectorServiceInterface $userSourceDirectorService * @param UserSourceDirectorServiceInterface $userSourceDirectorService

View File

@ -0,0 +1,10 @@
<?php
namespace App\Domain\RequestManagement\User;
/**
* @author kevinfrantz
*/
interface RequestedUserServiceInterface extends RequestedUserInterface
{
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Domain\ViewManagement;
use FOS\RestBundle\View\View;
use App\Domain\RequestManagement\RequestedUser;
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryService;
use App\Domain\SecureCRUDManagement\Factory\SecureCRUDFactoryServiceInterface;
/**
* @author kevinfrantz
*/
class AbstractViewBuilder implements ViewBuilderInterface
{
/**
* @var View
*/
protected $view;
/**
* @var SecureCRUDFactoryServiceInterface
*/
protected $secureCrudFactoryService;
/**
* @param RequestedUser $requestedUserRight
* @param SecureCRUDFactoryService $secureCrudFactoryService
*/
public function __construct(RequestedUser $requestedUserRight, SecureCRUDFactoryService $secureCrudFactoryService)
{
$this->view = new View();
$this->requestedUserRight = $requestedUserRight;
$this->secureCrudFactoryService = $secureCrudFactoryService;
}
/**
* @return View
*/
public function getView(): View
{
$this->secureCrudFactoryService->create($requestedRight);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Domain\ViewManagement;
use FOS\RestBundle\View\View;
/**
* @author kevinfrantz
*/
interface ViewBuilderInterface
{
/**
* @return View
*/
public function getView(): View;
}

View File

@ -5,13 +5,15 @@ namespace App\Entity;
use App\Entity\Attribut\IdAttribut; use App\Entity\Attribut\IdAttribut;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\VersionAttribut; use App\Entity\Attribut\VersionAttribut;
use App\Entity\Attribut\SlugAttribut;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
abstract class AbstractEntity implements EntityInterface abstract class AbstractEntity implements EntityInterface
{ {
use IdAttribut, VersionAttribut; use IdAttribut, VersionAttribut,SlugAttribut;
/** /**
* @ORM\Id() * @ORM\Id()
@ -29,6 +31,21 @@ abstract class AbstractEntity implements EntityInterface
*/ */
protected $version; protected $version;
/**
* System slugs should be writen in UPPER CASES
* Slugs which are defined by the user are checked via the assert.
*
* @ORM\Column(type="string",length=30,nullable=true,unique=true)
* @Assert\Regex(pattern="/^[a-z]+$/")
*
* @todo Check out if a plugin can solve this purpose;
*
* @see https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md
*
* @var string
*/
protected $slug;
public function __construct() public function __construct()
{ {
$this->version = 0; $this->version = 0;

View File

@ -4,10 +4,11 @@ namespace App\Entity;
use App\Entity\Attribut\VersionAttributInterface; use App\Entity\Attribut\VersionAttributInterface;
use App\Entity\Attribut\IdAttributInterface; use App\Entity\Attribut\IdAttributInterface;
use App\Entity\Attribut\SlugAttributInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
interface EntityInterface extends VersionAttributInterface, IdAttributInterface interface EntityInterface extends VersionAttributInterface, IdAttributInterface,SlugAttributInterface
{ {
} }

View File

@ -8,7 +8,6 @@ use App\Entity\AbstractEntity;
use App\Entity\Attribut\LawAttribut; use App\Entity\Attribut\LawAttribut;
use App\Entity\Meta\LawInterface; use App\Entity\Meta\LawInterface;
use App\Entity\Meta\Law; use App\Entity\Meta\Law;
use App\Entity\Attribut\SlugAttribut;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Attribut\CreatorRelationAttribut; use App\Entity\Attribut\CreatorRelationAttribut;
@ -49,22 +48,7 @@ use App\Entity\Meta\Relation\Member\MemberRelationInterface;
*/ */
abstract class AbstractSource extends AbstractEntity implements SourceInterface abstract class AbstractSource extends AbstractEntity implements SourceInterface
{ {
use LawAttribut,SlugAttribut,CreatorRelationAttribut, MemberRelationAttribut; use LawAttribut,CreatorRelationAttribut, MemberRelationAttribut;
/**
* System slugs should be writen in UPPER CASES
* Slugs which are defined by the user are checked via the assert.
*
* @ORM\Column(type="string",length=30,nullable=true,unique=true)
* @Assert\Regex(pattern="/^[a-z]+$/")
*
* @todo Check out if a plugin can solve this purpose;
*
* @see https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md
*
* @var string
*/
protected $slug;
/** /**
* @var CreatorRelationInterface * @var CreatorRelationInterface

View File

@ -5,13 +5,12 @@ namespace App\Entity\Source;
use App\Entity\Attribut\IdAttributInterface; use App\Entity\Attribut\IdAttributInterface;
use App\Entity\EntityInterface; use App\Entity\EntityInterface;
use App\Entity\Attribut\LawAttributInterface; use App\Entity\Attribut\LawAttributInterface;
use App\Entity\Attribut\SlugAttributInterface;
use App\Entity\Attribut\CreatorRelationAttributInterface; use App\Entity\Attribut\CreatorRelationAttributInterface;
use App\Entity\Attribut\MemberRelationAttributInterface; use App\Entity\Attribut\MemberRelationAttributInterface;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, SlugAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface
{ {
} }

View File

@ -3,7 +3,7 @@
namespace App\Repository\Source; namespace App\Repository\Source;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\RequestManagement\RequestedSourceInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Repository\AbstractRepository; use App\Repository\AbstractRepository;
/** /**
@ -11,6 +11,11 @@ use App\Repository\AbstractRepository;
*/ */
final class SourceRepository extends AbstractRepository implements SourceRepositoryInterface final class SourceRepository extends AbstractRepository implements SourceRepositoryInterface
{ {
/**
* {@inheritdoc}
*
* @see \App\Repository\Source\SourceRepositoryInterface::findOneBySlug()
*/
public function findOneBySlug(string $slug): ?SourceInterface public function findOneBySlug(string $slug): ?SourceInterface
{ {
return $this->findOneBy([ return $this->findOneBy([
@ -18,7 +23,12 @@ final class SourceRepository extends AbstractRepository implements SourceReposit
]); ]);
} }
public function findOneByIdOrSlug(RequestedSourceInterface $requestedSource): ?SourceInterface /**
* {@inheritdoc}
*
* @see \App\Repository\Source\SourceRepositoryInterface::findOneByIdOrSlug()
*/
public function findOneByIdOrSlug(RequestedEntityInterface $requestedSource): ?SourceInterface
{ {
if ($requestedSource->hasId()) { if ($requestedSource->hasId()) {
return $this->find($requestedSource->getId()); return $this->find($requestedSource->getId());

View File

@ -3,7 +3,7 @@
namespace App\Repository\Source; namespace App\Repository\Source;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
use App\Domain\RequestManagement\RequestedSourceInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Repository\RepositoryInterface; use App\Repository\RepositoryInterface;
/** /**
@ -23,9 +23,9 @@ interface SourceRepositoryInterface extends RepositoryInterface
/** /**
* Loads a source by id or if not defined, by slug. * Loads a source by id or if not defined, by slug.
* *
* @param RequestedSourceInterface $requestedSource * @param RequestedEntityInterface $requestedSource
* *
* @return SourceInterface|null * @return SourceInterface|null
*/ */
public function findOneByIdOrSlug(RequestedSourceInterface $requestedSource): ?SourceInterface; public function findOneByIdOrSlug(RequestedEntityInterface $requestedSource): ?SourceInterface;
} }

View File

@ -0,0 +1,57 @@
<?php
namespace tests\Unit\Domain\RequestManagement\Action;
use PHPUnit\Framework\TestCase;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Action\RequestedActionInterface;
use App\Domain\RequestManagement\Right\RequestedRight;
use App\Domain\RequestManagement\Action\RequestedAction;
use App\DBAL\Types\ActionType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Repository\Source\SourceRepositoryInterface;
/**
* @author kevinfrantz
*/
class RequestedActionTest extends TestCase
{
/**
* @var RequestedRightInterface
*/
private $requestedRight;
/**
* @var RequestedActionInterface
*/
private $action;
/**
* {@inheritdoc}
*
* @see \PHPUnit\Framework\TestCase::setUp()
*/
public function setUp(): void
{
$sourceRepository = $this->createMock(SourceRepositoryInterface::class);
$this->requestedRight = new RequestedRight($sourceRepository);
$this->action = new RequestedAction($this->requestedRight);
}
public function testList(): void
{
$list = ActionType::LIST;
$this->action->setActionType($list);
$this->assertEquals($list, $this->action->getActionType());
$this->assertEquals(CRUDType::READ, $this->requestedRight->getCrud());
}
public function testCrud(): void
{
foreach (CRUDType::getChoices() as $crud) {
$this->action->setActionType($crud);
$this->assertEquals($crud, $this->action->getActionType());
$this->assertEquals($crud, $this->requestedRight->getCrud());
}
}
}

View File

@ -1,23 +0,0 @@
<?php
namespace tests\Unit\Domain\RequestManagement;
use PHPUnit\Framework\TestCase;
use App\Domain\RequestManagement\RequestedUserRightService;
use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
use App\Domain\RequestManagement\RequestedUserRightServiceInterface;
use App\Domain\RequestManagement\RequestedRightServiceInterface;
/**
* @author kevinfrantz
*/
class RequestedUserRightServiceTest extends TestCase
{
public function testConstructorSet(): void
{
$requestedRightService = $this->createMock(RequestedRightServiceInterface::class);
$userSourceDirectorService = $this->createMock(UserSourceDirectorServiceInterface::class);
$service = new RequestedUserRightService($userSourceDirectorService, $requestedRightService);
$this->assertInstanceOf(RequestedUserRightServiceInterface::class, $service);
}
}

View File

@ -1,15 +1,15 @@
<?php <?php
namespace tests\Unit\Domain\RequestManagement; namespace tests\Unit\Domain\RequestManagement\Entity;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Domain\RequestManagement\RequestedRightInterface; use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\RequestedRight; use App\Domain\RequestManagement\Right\RequestedRight;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use App\DBAL\Types\Meta\Right\LayerType; use App\DBAL\Types\Meta\Right\LayerType;
use App\Domain\RequestManagement\RequestedSource; use App\Domain\RequestManagement\Entity\RequestedEntity;
use App\DBAL\Types\SystemSlugType; use App\DBAL\Types\SystemSlugType;
use App\Domain\RequestManagement\RequestedSourceInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\Exception\PreconditionFailedException; use App\Exception\PreconditionFailedException;
use App\Exception\NotSetException; use App\Exception\NotSetException;
@ -44,19 +44,19 @@ class RequestedRightTest extends KernelTestCase
var_dump($this->requestedRight->getLayer()); var_dump($this->requestedRight->getLayer());
} }
public function testRequestedSourceWithoutAttributes(): void public function testRequestedEntityWithoutAttributes(): void
{ {
$requestedSource = $this->createMock(RequestedSource::class); $requestedSource = $this->createMock(RequestedEntity::class);
$this->requestedRight->setRequestedSource($requestedSource); $this->requestedRight->setRequestedEntity($requestedSource);
$this->expectException(PreconditionFailedException::class); $this->expectException(PreconditionFailedException::class);
$this->requestedRight->getSource(); $this->requestedRight->getSource();
} }
public function testKnownSource(): void public function testKnownSource(): void
{ {
$requestedSource = new RequestedSource(); $requestedSource = new RequestedEntity();
$requestedSource->setSlug(SystemSlugType::IMPRINT); $requestedSource->setSlug(SystemSlugType::IMPRINT);
$this->requestedRight->setRequestedSource($requestedSource); $this->requestedRight->setRequestedEntity($requestedSource);
$sourceResponse1 = $this->requestedRight->getSource(); $sourceResponse1 = $this->requestedRight->getSource();
$this->assertGreaterThan(0, $sourceResponse1->getId()); $this->assertGreaterThan(0, $sourceResponse1->getId());
$requestedSource->setSlug(''); $requestedSource->setSlug('');
@ -67,11 +67,11 @@ class RequestedRightTest extends KernelTestCase
public function testEqualsSlug(): void public function testEqualsSlug(): void
{ {
$slug = SystemSlugType::IMPRINT; $slug = SystemSlugType::IMPRINT;
$requestedSource = $this->createMock(RequestedSourceInterface::class); $requestedSource = $this->createMock(RequestedEntityInterface::class);
$requestedSource->method('getSlug')->willReturn($slug); $requestedSource->method('getSlug')->willReturn($slug);
$requestedSource->method('hasSlug')->willReturn(true); $requestedSource->method('hasSlug')->willReturn(true);
$this->assertEquals($slug, $requestedSource->getSlug()); $this->assertEquals($slug, $requestedSource->getSlug());
$this->requestedRight->setRequestedSource($requestedSource); $this->requestedRight->setRequestedEntity($requestedSource);
$responseSource1 = $this->requestedRight->getSource(); $responseSource1 = $this->requestedRight->getSource();
$responseSource2 = $this->requestedRight->getSource(); $responseSource2 = $this->requestedRight->getSource();
$this->assertEquals($responseSource1, $responseSource2); $this->assertEquals($responseSource1, $responseSource2);

View File

@ -0,0 +1,23 @@
<?php
namespace tests\Unit\Domain\RequestManagement\User;
use PHPUnit\Framework\TestCase;
use App\Domain\RequestManagement\User\RequestedUserService;
use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
use App\Domain\RequestManagement\User\RequestedUserServiceInterface;
use App\Domain\RequestManagement\Right\RequestedRightServiceInterface;
/**
* @author kevinfrantz
*/
class RequestedUserServiceTest extends TestCase
{
public function testConstructorSet(): void
{
$requestedRightService = $this->createMock(RequestedRightServiceInterface::class);
$userSourceDirectorService = $this->createMock(UserSourceDirectorServiceInterface::class);
$service = new RequestedUserService($userSourceDirectorService, $requestedRightService);
$this->assertInstanceOf(RequestedUserServiceInterface::class, $service);
}
}

View File

@ -1,19 +1,19 @@
<?php <?php
namespace tests\Unit\Domain\RightManagement; namespace tests\Unit\Domain\RightManagement\User;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\User; use App\Entity\User;
use App\Domain\RequestManagement\RequestedUserRight; use App\Domain\RequestManagement\User\RequestedUser;
use App\DBAL\Types\Meta\Right\LayerType; use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType; use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use App\Domain\UserManagement\UserSourceDirectorInterface; use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Domain\RequestManagement\RequestedRightInterface; use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\RequestedRight; use App\Domain\RequestManagement\Right\RequestedRight;
use App\Domain\UserManagement\UserSourceDirector; use App\Domain\UserManagement\UserSourceDirector;
use App\Repository\Source\SourceRepositoryInterface; use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\RequestedSourceInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\DBAL\Types\SystemSlugType; use App\DBAL\Types\SystemSlugType;
use App\Exception\NotSetException; use App\Exception\NotSetException;
use App\Exception\SetNotPossibleException; use App\Exception\SetNotPossibleException;
@ -21,13 +21,13 @@ use App\Exception\SetNotPossibleException;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
class RequestedUserRightTest extends TestCase class RequestedUserTest extends TestCase
{ {
public function testInterface(): void public function testInterface(): void
{ {
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class); $requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight); $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade); $this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade);
} }
@ -46,7 +46,7 @@ class RequestedUserRightTest extends TestCase
$requestedRight->method('getLayer')->willReturn($layer); $requestedRight->method('getLayer')->willReturn($layer);
$requestedRight->method('getCrud')->willReturn($type); $requestedRight->method('getCrud')->willReturn($type);
$requestedRight->method('getSource')->willReturn($source); $requestedRight->method('getSource')->willReturn($source);
$requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight); $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->assertEquals($layer, $requestedUserRightFacade->getLayer()); $this->assertEquals($layer, $requestedUserRightFacade->getLayer());
$this->assertEquals($type, $requestedUserRightFacade->getCrud()); $this->assertEquals($type, $requestedUserRightFacade->getCrud());
$this->assertEquals($source, $requestedUserRightFacade->getSource()); $this->assertEquals($source, $requestedUserRightFacade->getSource());
@ -57,21 +57,21 @@ class RequestedUserRightTest extends TestCase
{ {
$layer = LayerType::SOURCE; $layer = LayerType::SOURCE;
$type = CRUDType::READ; $type = CRUDType::READ;
$requestedSource = $this->createMock(RequestedSourceInterface::class); $requestedSource = $this->createMock(RequestedEntityInterface::class);
$requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$requestedSource->method('hasSlug')->willReturn(true); $requestedSource->method('hasSlug')->willReturn(true);
$sourceRepository = $this->createMock(SourceRepositoryInterface::class); $sourceRepository = $this->createMock(SourceRepositoryInterface::class);
$requestedRight = new RequestedRight($sourceRepository); $requestedRight = new RequestedRight($sourceRepository);
$user = $this->createMock(User::class); $user = $this->createMock(User::class);
$userSourceDirector = new UserSourceDirector($sourceRepository, $user); $userSourceDirector = new UserSourceDirector($sourceRepository, $user);
$requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight); $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->assertNull($requestedUserRightFacade->setLayer($layer)); $this->assertNull($requestedUserRightFacade->setLayer($layer));
$this->assertNull($requestedUserRightFacade->setCrud($type)); $this->assertNull($requestedUserRightFacade->setCrud($type));
$this->assertNull($requestedUserRightFacade->setRequestedSource($requestedSource)); $this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedSource));
$this->assertEquals($layer, $requestedRight->getLayer()); $this->assertEquals($layer, $requestedRight->getLayer());
$this->assertEquals($type, $requestedRight->getCrud()); $this->assertEquals($type, $requestedRight->getCrud());
$this->expectException(NotSetException::class); $this->expectException(NotSetException::class);
$this->assertNotInstanceOf(RequestedSourceInterface::class, $requestedRight->getSource()); $this->assertNotInstanceOf(RequestedEntityInterface::class, $requestedRight->getSource());
} }
public function testSetReciever(): void public function testSetReciever(): void
@ -79,7 +79,7 @@ class RequestedUserRightTest extends TestCase
$reciever = $this->createMock(AbstractSource::class); $reciever = $this->createMock(AbstractSource::class);
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class); $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class); $requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight); $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->expectException(SetNotPossibleException::class); $this->expectException(SetNotPossibleException::class);
$requestedUserRightFacade->setReciever($reciever); $requestedUserRightFacade->setReciever($reciever);
} }

View File

@ -5,7 +5,7 @@ namespace tests\Unit\Repository\Source;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\Repository\Source\SourceRepositoryInterface; use App\Repository\Source\SourceRepositoryInterface;
use App\Entity\Source\AbstractSource; use App\Entity\Source\AbstractSource;
use App\Domain\RequestManagement\RequestedSourceInterface; use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
use App\DBAL\Types\SystemSlugType; use App\DBAL\Types\SystemSlugType;
use App\Entity\Source\SourceInterface; use App\Entity\Source\SourceInterface;
@ -30,12 +30,12 @@ class SourceRepositoryTest extends KernelTestCase
public function testLoadBySlugOrId(): void public function testLoadBySlugOrId(): void
{ {
$requestedSource = $this->createMock(RequestedSourceInterface::class); $requestedSource = $this->createMock(RequestedEntityInterface::class);
$requestedSource->method('hasSlug')->willReturn(true); $requestedSource->method('hasSlug')->willReturn(true);
$requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource); $imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource);
$this->assertInstanceOf(SourceInterface::class, $imprint); $this->assertInstanceOf(SourceInterface::class, $imprint);
$requestedSource2 = $this->createMock(RequestedSourceInterface::class); $requestedSource2 = $this->createMock(RequestedEntityInterface::class);
$requestedSource2->method('hasId')->willReturn(true); $requestedSource2->method('hasId')->willReturn(true);
$requestedSource2->method('getId')->willReturn($imprint->getId()); $requestedSource2->method('getId')->willReturn($imprint->getId());
$imprint2 = $this->sourceRepository->findOneByIdOrSlug($requestedSource2); $imprint2 = $this->sourceRepository->findOneByIdOrSlug($requestedSource2);