Renamed domain RequestManagement to Request

This commit is contained in:
Kevin Frantz
2019-05-30 16:52:02 +02:00
parent 9af7f47b85
commit b8029bb7cc
75 changed files with 149 additions and 149 deletions

View File

@@ -0,0 +1,103 @@
<?php
namespace tests\Unit\Domain\Request\Entity;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\Request\Entity\RequestedEntityInterface;
use Infinito\Domain\Request\Entity\LazyRequestedEntity;
use Infinito\Domain\Repository\LayerRepositoryFactoryServiceInterface;
use Infinito\Repository\RepositoryInterface;
use Infinito\Entity\Source\PureSource;
use Infinito\Repository\Source\SourceRepositoryInterface;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Domain\Request\Right\RequestedRightInterface;
class LazyRequestedEntityTest extends TestCase
{
/**
* @var RequestedEntityInterface
*/
private $lazyRequestedEntity;
/**
* @var LayerRepositoryFactoryServiceInterface
*/
private $layerRepositoryFactoryService;
/**
* @var SourceRepositoryInterface
*/
private $repository;
/**
* {@inheritdoc}
*
* @see \PHPUnit\Framework\TestCase::setUp()
*/
public function setUp(): void
{
$this->repository = $this->createMock(SourceRepositoryInterface::class);
$this->layerRepositoryFactoryService = new class($this->repository) implements LayerRepositoryFactoryServiceInterface {
private $count = 0;
private $repository;
public function __construct($repository)
{
$this->repository = $repository;
}
public function getRepository(string $layer): RepositoryInterface
{
if ($this->count > 0) {
//Just for information and testing thrown
throw new \Exception('The function '.__FUNCTION__.' was called multiple times!');
}
++$this->count;
return $this->repository;
}
};
$this->lazyRequestedEntity = new LazyRequestedEntity($this->layerRepositoryFactoryService);
}
public function testSlug(): void
{
$slug = 'hello';
$requestedSource = new PureSource();
$requestedSource->setSlug($slug);
$requestedSource->setId('123');
$this->repository->method('findOneBySlug')->willReturn($requestedSource);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedRight->method('getLayer')->willReturn(LayerType::SOURCE);
$this->assertNull($this->lazyRequestedEntity->setRequestedRight($requestedRight));
$this->assertNull($this->lazyRequestedEntity->setSlug($slug));
//Call 1
$this->assertEquals($requestedSource, $this->lazyRequestedEntity->getEntity());
//Call 2
$this->assertEquals($requestedSource, $this->lazyRequestedEntity->getEntity());
//Call with other slug
$this->assertNull($this->lazyRequestedEntity->setSlug('abcde'));
$this->expectException(\Exception::class);
$this->lazyRequestedEntity->getEntity();
}
public function testId(): void
{
$id = 12345;
$requestedSource = new PureSource();
$requestedSource->setId($id);
$this->repository->method('find')->willReturn($requestedSource);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedRight->method('getLayer')->willReturn(LayerType::SOURCE);
$this->assertNull($this->lazyRequestedEntity->setRequestedRight($requestedRight));
$this->assertNull($this->lazyRequestedEntity->setId($id));
//Call 1
$this->assertEquals($requestedSource, $this->lazyRequestedEntity->getEntity());
//Call 2
$this->assertEquals($requestedSource, $this->lazyRequestedEntity->getEntity());
//Call with other slug
$this->assertNull($this->lazyRequestedEntity->setId(65432));
$this->expectException(\Exception::class);
$this->lazyRequestedEntity->getEntity();
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace tests\Unit\Domain\Request\Entity;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\Request\Entity\RequestedEntity;
use Infinito\Domain\Repository\LayerRepositoryFactoryServiceInterface;
use Infinito\Domain\Request\Right\RequestedRightInterface;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Repository\RepositoryInterface;
use Infinito\Entity\EntityInterface;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Exception\Attribut\UndefinedAttributException;
use Infinito\Exception\Core\NoIdentityCoreException;
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
use Infinito\Exception\Core\NotCorrectInstanceCoreException;
/**
* @author kevinfrantz
*/
class RequestedEntityTest extends TestCase
{
public function testSetByIdentity(): void
{
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
$slug = 'test';
$requestedEntity->setIdentity($slug);
$this->assertEquals($slug, $requestedEntity->getSlug());
$this->assertFalse($requestedEntity->hasId());
$id = 123;
$requestedEntity->setIdentity($id);
$this->assertEquals($id, $requestedEntity->getId());
$this->assertFalse($requestedEntity->hasSlug());
}
public function testNotSetExeptionIdSlug(): void
{
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
$this->expectException(NoIdentityCoreException::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(NotCorrectInstanceCoreException::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);
$this->assertEquals(get_class($entityMock), $requestedEntity->getClass());
$this->expectException(AllreadyDefinedAttributException::class);
$requestedEntity->setClass(AbstractSource::class);
}
public function testSetClass(): void
{
$class = AbstractSource::class;
$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);
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
$this->assertFalse($requestedEntity->hasClass());
$this->assertNull($requestedEntity->setClass($class));
$this->assertTrue($requestedEntity->hasClass());
$this->assertEquals($class, $requestedEntity->getClass());
$this->expectException(AllreadyDefinedAttributException::class);
$requestedEntity->setIdentity('123343');
}
public function testValidateLayerRepositoryFactoryService(): void
{
$requestedEntity = new RequestedEntity();
$requestedEntity->setSlug('ABABEBA');
$this->expectException(UndefinedAttributException::class);
$requestedEntity->getEntity();
}
}