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(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); $this->assertEquals(get_class($entityMock), $requestedEntity->getClass()); $this->expectException(AllreadyDefinedException::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(AllreadyDefinedException::class); $requestedEntity->setIdentity('123343'); } }