2019-01-26 17:17:20 +01:00
|
|
|
<?php
|
|
|
|
|
2019-05-30 16:52:02 +02:00
|
|
|
namespace tests\Unit\Domain\Request\Entity;
|
2019-01-26 17:17:20 +01:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-05-30 16:52:02 +02:00
|
|
|
use Infinito\Domain\Request\Entity\RequestedEntity;
|
2019-05-30 16:30:03 +02:00
|
|
|
use Infinito\Domain\Repository\LayerRepositoryFactoryServiceInterface;
|
2019-05-30 16:52:02 +02:00
|
|
|
use Infinito\Domain\Request\Right\RequestedRightInterface;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
|
|
|
use Infinito\Repository\RepositoryInterface;
|
|
|
|
use Infinito\Entity\EntityInterface;
|
|
|
|
use Infinito\Entity\Source\AbstractSource;
|
2019-04-14 23:37:30 +02:00
|
|
|
use Infinito\Exception\Attribut\UndefinedAttributException;
|
2019-04-15 01:37:17 +02:00
|
|
|
use Infinito\Exception\Core\NoIdentityCoreException;
|
2019-04-14 23:37:30 +02:00
|
|
|
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
|
2019-04-15 01:37:17 +02:00
|
|
|
use Infinito\Exception\Core\NotCorrectInstanceCoreException;
|
2019-01-26 17:17:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
class RequestedEntityTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testSetByIdentity(): void
|
|
|
|
{
|
2019-01-26 19:39:36 +01:00
|
|
|
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
|
|
|
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
|
2019-01-26 17:17:20 +01:00
|
|
|
$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());
|
|
|
|
}
|
2019-01-26 20:45:55 +01:00
|
|
|
|
|
|
|
public function testNotSetExeptionIdSlug(): void
|
|
|
|
{
|
|
|
|
$layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class);
|
|
|
|
$requestedEntity = new RequestedEntity($layerRepositoryFactoryService);
|
2019-04-15 01:37:17 +02:00
|
|
|
$this->expectException(NoIdentityCoreException::class);
|
2019-01-26 20:45:55 +01:00
|
|
|
$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);
|
2019-04-15 01:37:17 +02:00
|
|
|
$this->expectException(NotCorrectInstanceCoreException::class);
|
2019-01-26 20:45:55 +01:00
|
|
|
$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);
|
2019-02-03 13:40:13 +01:00
|
|
|
$this->assertEquals(get_class($entityMock), $requestedEntity->getClass());
|
2019-04-14 23:37:30 +02:00
|
|
|
$this->expectException(AllreadyDefinedAttributException::class);
|
2019-02-03 13:40:13 +01:00
|
|
|
$requestedEntity->setClass(AbstractSource::class);
|
|
|
|
}
|
2019-02-03 13:57:49 +01:00
|
|
|
|
|
|
|
public function testSetClass(): void
|
|
|
|
{
|
2019-02-03 13:40:13 +01:00
|
|
|
$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());
|
2019-04-14 23:37:30 +02:00
|
|
|
$this->expectException(AllreadyDefinedAttributException::class);
|
2019-02-03 13:40:13 +01:00
|
|
|
$requestedEntity->setIdentity('123343');
|
2019-01-26 20:45:55 +01:00
|
|
|
}
|
2019-02-13 15:01:23 +01:00
|
|
|
|
|
|
|
public function testValidateLayerRepositoryFactoryService(): void
|
|
|
|
{
|
|
|
|
$requestedEntity = new RequestedEntity();
|
|
|
|
$requestedEntity->setSlug('ABABEBA');
|
2019-04-14 23:37:30 +02:00
|
|
|
$this->expectException(UndefinedAttributException::class);
|
2019-02-13 15:01:23 +01:00
|
|
|
$requestedEntity->getEntity();
|
|
|
|
}
|
2019-01-26 17:17:20 +01:00
|
|
|
}
|