mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Optimized RequestManagement and tests
This commit is contained in:
		| @@ -7,6 +7,9 @@ use App\Attribut\RightAttributInterface; | ||||
| use App\Attribut\RightAttribut; | ||||
| use App\Entity\Meta\RightInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class RightAttributTest extends TestCase | ||||
| { | ||||
|     /*** | ||||
|   | ||||
| @@ -7,6 +7,7 @@ use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryService; | ||||
| use App\Repository\RepositoryInterface; | ||||
| use App\Exception\NotSetException; | ||||
| use App\Domain\LayerManagement\LayerClassMap; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -27,7 +28,7 @@ class LayerRepositoryFactoryServiceTest extends KernelTestCase | ||||
|  | ||||
|     public function testGetRepository(): void | ||||
|     { | ||||
|         foreach (array_keys(LayerRepositoryFactoryService::LAYER_CLASS_MAP) as $layer) { | ||||
|         foreach (array_keys(LayerClassMap::LAYER_CLASS_MAP) as $layer) { | ||||
|             $repositoy = $this->layerRepositoryFactoryService->getRepository($layer); | ||||
|             $this->assertInstanceOf(RepositoryInterface::class, $repositoy); | ||||
|         } | ||||
|   | ||||
| @@ -4,6 +4,7 @@ namespace tests\Unit\Domain\RequestManagement\Entity; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntity; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -12,7 +13,8 @@ class RequestedEntityTest extends TestCase | ||||
| { | ||||
|     public function testSetByIdentity(): void | ||||
|     { | ||||
|         $requestedEntity = new RequestedEntity(); | ||||
|         $layerRepositoryFactoryService = $this->createMock(LayerRepositoryFactoryServiceInterface::class); | ||||
|         $requestedEntity = new RequestedEntity($layerRepositoryFactoryService); | ||||
|         $slug = 'test'; | ||||
|         $requestedEntity->setIdentity($slug); | ||||
|         $this->assertEquals($slug, $requestedEntity->getSlug()); | ||||
|   | ||||
| @@ -5,13 +5,15 @@ namespace tests\Unit\Domain\RequestManagement\Entity; | ||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||||
| use App\Domain\RequestManagement\Right\RequestedRightInterface; | ||||
| use App\Domain\RequestManagement\Right\RequestedRight; | ||||
| use App\Entity\Source\AbstractSource; | ||||
| use App\DBAL\Types\Meta\Right\LayerType; | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntity; | ||||
| use App\DBAL\Types\SystemSlugType; | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntityInterface; | ||||
| use App\Exception\PreconditionFailedException; | ||||
| use App\Exception\NotSetException; | ||||
| use App\Entity\Source\PureSource; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryServiceInterface; | ||||
| use App\Domain\RepositoryManagement\LayerRepositoryFactoryService; | ||||
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -23,12 +25,17 @@ class RequestedRightTest extends KernelTestCase | ||||
|      */ | ||||
|     private $requestedRight; | ||||
|  | ||||
|     /** | ||||
|      * @var LayerRepositoryFactoryServiceInterface | ||||
|      */ | ||||
|     private $layerRepositoryFactoryService; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         self::bootKernel(); | ||||
|         $entityManager = self::$container->get('doctrine.orm.default_entity_manager'); | ||||
|         $sourceRepository = $entityManager->getRepository(AbstractSource::class); | ||||
|         $this->requestedRight = new RequestedRight($sourceRepository); | ||||
|         $this->layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager); | ||||
|         $this->requestedRight = new RequestedRight(); | ||||
|     } | ||||
|  | ||||
|     public function testLayer(): void | ||||
| @@ -54,24 +61,27 @@ class RequestedRightTest extends KernelTestCase | ||||
|  | ||||
|     public function testKnownSource(): void | ||||
|     { | ||||
|         $requestedSource = new RequestedEntity(); | ||||
|         $requestedSource->setSlug(SystemSlugType::IMPRINT); | ||||
|         $this->requestedRight->setRequestedEntity($requestedSource); | ||||
|         $requestedEntity = new RequestedEntity($this->layerRepositoryFactoryService); | ||||
|         $requestedEntity->setSlug(SystemSlugType::IMPRINT); | ||||
|         $this->requestedRight->setRequestedEntity($requestedEntity); | ||||
|         $this->requestedRight->setLayer(LayerType::SOURCE); | ||||
|         $sourceResponse1 = $this->requestedRight->getSource(); | ||||
|         $this->assertGreaterThan(0, $sourceResponse1->getId()); | ||||
|         $requestedSource->setSlug(''); | ||||
|         $this->expectException(NotSetException::class); | ||||
|         $requestedEntity->setSlug(''); | ||||
|         $this->expectException(NotFoundHttpException::class); | ||||
|         $this->requestedRight->getSource(); | ||||
|     } | ||||
|  | ||||
|     public function testEqualsSlug(): void | ||||
|     { | ||||
|         $slug = SystemSlugType::IMPRINT; | ||||
|         $requestedSource = $this->createMock(RequestedEntityInterface::class); | ||||
|         $requestedSource->method('getSlug')->willReturn($slug); | ||||
|         $requestedSource->method('hasSlug')->willReturn(true); | ||||
|         $this->assertEquals($slug, $requestedSource->getSlug()); | ||||
|         $this->requestedRight->setRequestedEntity($requestedSource); | ||||
|         $requestedEntityEntity = new PureSource(); | ||||
|         $requestedEntity = $this->createMock(RequestedEntityInterface::class); | ||||
|         $requestedEntity->method('getSlug')->willReturn($slug); | ||||
|         $requestedEntity->method('hasSlug')->willReturn(true); | ||||
|         $requestedEntity->method('getEntity')->willReturn($requestedEntityEntity); | ||||
|         $this->assertEquals($slug, $requestedEntity->getSlug()); | ||||
|         $this->requestedRight->setRequestedEntity($requestedEntity); | ||||
|         $responseSource1 = $this->requestedRight->getSource(); | ||||
|         $responseSource2 = $this->requestedRight->getSource(); | ||||
|         $this->assertEquals($responseSource1, $responseSource2); | ||||
|   | ||||
| @@ -15,8 +15,8 @@ use App\Domain\UserManagement\UserSourceDirector; | ||||
| use App\Repository\Source\SourceRepositoryInterface; | ||||
| use App\Domain\RequestManagement\Entity\RequestedEntityInterface; | ||||
| use App\DBAL\Types\SystemSlugType; | ||||
| use App\Exception\NotSetException; | ||||
| use App\Exception\SetNotPossibleException; | ||||
| use App\Exception\NotCorrectInstanceException; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -61,7 +61,7 @@ class RequestedUserTest extends TestCase | ||||
|         $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); | ||||
|         $requestedSource->method('hasSlug')->willReturn(true); | ||||
|         $sourceRepository = $this->createMock(SourceRepositoryInterface::class); | ||||
|         $requestedRight = new RequestedRight($sourceRepository); | ||||
|         $requestedRight = new RequestedRight(); | ||||
|         $user = $this->createMock(User::class); | ||||
|         $userSourceDirector = new UserSourceDirector($sourceRepository, $user); | ||||
|         $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight); | ||||
| @@ -70,7 +70,7 @@ class RequestedUserTest extends TestCase | ||||
|         $this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedSource)); | ||||
|         $this->assertEquals($layer, $requestedRight->getLayer()); | ||||
|         $this->assertEquals($type, $requestedRight->getCrud()); | ||||
|         $this->expectException(NotSetException::class); | ||||
|         $this->expectException(NotCorrectInstanceException::class); | ||||
|         $this->assertNotInstanceOf(RequestedEntityInterface::class, $requestedRight->getSource()); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user