mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Optimized RequestManagement and pushed code coverage for it to 100%
This commit is contained in:
parent
4dd7ce8331
commit
c995778264
@ -5,6 +5,8 @@ namespace App\Domain\LayerManagement;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\Entity\Source\AbstractSource;
|
||||
use App\Exception\NotSetException;
|
||||
use App\Entity\Meta\Law;
|
||||
use App\Entity\Meta\Right;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -13,6 +15,8 @@ final class LayerClassMap implements LayerClassMapInterface
|
||||
{
|
||||
const LAYER_CLASS_MAP = [
|
||||
LayerType::SOURCE => AbstractSource::class,
|
||||
LayerType::LAW => Law::class,
|
||||
LayerType::RIGHT => Right::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -122,6 +122,6 @@ abstract class AbstractRequestedRightFacade implements RequestedRightInterface
|
||||
*/
|
||||
public function hasRequestedEntity(): bool
|
||||
{
|
||||
$this->requestedRight->hasRequestedEntity();
|
||||
return $this->requestedRight->hasRequestedEntity();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use App\Attribut\CrudAttribut;
|
||||
use App\Attribut\LayerAttribut;
|
||||
use App\Attribut\RecieverAttribut;
|
||||
use App\Exception\PreconditionFailedException;
|
||||
use App\Exception\NotSetException;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
|
||||
use App\Attribut\RequestedEntityAttribut;
|
||||
use App\Entity\Meta\MetaInterface;
|
||||
@ -68,19 +67,10 @@ class RequestedRight implements RequestedRightInterface
|
||||
{
|
||||
$this->validateRequestedEntity();
|
||||
$this->loadSource();
|
||||
$this->validateLoad();
|
||||
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
private function validateLoad(): void
|
||||
{
|
||||
if ($this->source) {
|
||||
return;
|
||||
}
|
||||
throw new NotSetException('The Requested Source couldn\'t be found!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriding is neccessary to declare the correct relation.
|
||||
*
|
||||
|
@ -5,6 +5,12 @@ namespace tests\Unit\Domain\RequestManagement\Entity;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Domain\RequestManagement\Entity\RequestedEntity;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use App\Exception\NotSetException;
|
||||
use App\Exception\NotCorrectInstanceException;
|
||||
use App\Domain\RequestManagement\Right\RequestedRightInterface;
|
||||
use App\DBAL\Types\Meta\Right\LayerType;
|
||||
use App\Repository\RepositoryInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -24,4 +30,41 @@ class RequestedEntityTest extends TestCase
|
||||
$this->assertEquals($id, $requestedEntity->getId());
|
||||
$this->assertFalse($requestedEntity->hasSlug());
|
||||
}
|
||||
|
||||
public function testNotSetExeptionIdSlug(): void
|
||||
{
|
||||
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
|
||||
$this->expectException(NotSetException::class);
|
||||
$requestedEntity->getEntity();
|
||||
}
|
||||
|
||||
public function testNotCorrectInstanceException(): void
|
||||
{
|
||||
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$layerRepositoryFactoryService->method('getRepository')->willReturn($this->createMock(RepositoryInterface::class));
|
||||
$requestedRight = $this->createMock(RequestedRightInterface::class);
|
||||
$requestedRight->method('getLayer')->willReturn(LayerType::LAW);
|
||||
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
|
||||
$requestedEntity->setSlug('abcd');
|
||||
$requestedEntity->setRequestedRight($requestedRight);
|
||||
$this->expectException(NotCorrectInstanceException::class);
|
||||
$requestedEntity->getEntity();
|
||||
}
|
||||
|
||||
public function testLoadById(): void
|
||||
{
|
||||
$entityMock = $this->createMock(EntityInterface::class);
|
||||
$repository = $this->createMock(RepositoryInterface::class);
|
||||
$repository->method('find')->willReturn($entityMock);
|
||||
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
||||
$layerRepositoryFactoryService->method('getRepository')->willReturn($repository);
|
||||
$requestedRight = $this->createMock(RequestedRightInterface::class);
|
||||
$requestedRight->method('getLayer')->willReturn(LayerType::LAW);
|
||||
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
|
||||
$requestedEntity->setId(123);
|
||||
$requestedEntity->setRequestedRight($requestedRight);
|
||||
$entityResult = $requestedEntity->getEntity();
|
||||
$this->assertEquals($entityMock, $entityResult);
|
||||
}
|
||||
}
|
||||
|
@ -48,12 +48,14 @@ class AbstractRequestedRightFacadeTest extends TestCase
|
||||
$requestedRight->method('getSource')->willReturn($source);
|
||||
$requestedRight->method('getReciever')->willReturn($reciever);
|
||||
$requestedRight->method('getRequestedEntity')->willReturn($requestedEntity);
|
||||
$requestedRight->method('hasRequestedEntity')->willReturn(true);
|
||||
$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());
|
||||
$this->assertTrue($requestedRightFacade->hasRequestedEntity());
|
||||
}
|
||||
|
||||
public function testSetters(): void
|
||||
|
@ -14,6 +14,8 @@ use App\Entity\Source\PureSource;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface;
|
||||
use App\Domain\RepositoryManagement\LayerRepositoryFactoryService;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use App\Entity\Meta\Law;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -48,7 +50,7 @@ class RequestedRightTest extends KernelTestCase
|
||||
public function testLayerException(): void
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
var_dump($this->requestedRight->getLayer());
|
||||
$this->requestedRight->getLayer();
|
||||
}
|
||||
|
||||
public function testRequestedEntityWithoutAttributes(): void
|
||||
@ -86,4 +88,21 @@ class RequestedRightTest extends KernelTestCase
|
||||
$responseSource2 = $this->requestedRight->getSource();
|
||||
$this->assertEquals($responseSource1, $responseSource2);
|
||||
}
|
||||
|
||||
public function testMetaEntity(): void
|
||||
{
|
||||
$slug = 123;
|
||||
$source = $this->createMock(SourceInterface::class);
|
||||
$entity = new Law();
|
||||
$entity->setSource($source);
|
||||
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
|
||||
$requestedEntity->method('getSlug')->willReturn($slug);
|
||||
$requestedEntity->method('hasSlug')->willReturn(true);
|
||||
$requestedEntity->method('getEntity')->willReturn($entity);
|
||||
$this->assertEquals($slug, $requestedEntity->getSlug());
|
||||
$this->requestedRight->setRequestedEntity($requestedEntity);
|
||||
$this->requestedRight->setLayer(LayerType::LAW);
|
||||
$responseSource1 = $this->requestedRight->getSource();
|
||||
$this->assertEquals($responseSource1, $source);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user