secureRequestedRightCheckerService = self::$container->get(SecureRequestedRightCheckerServiceInterface::class); } public function testGranted(): void { $reciever = new class() extends AbstractSource { }; $layer = LayerType::SOURCE; $crud = CRUDType::READ; $source = new class() extends AbstractSource { }; $right = new Right(); $right->setSource($source); $right->setLayer($layer); $right->setActionType($crud); $right->setReciever($reciever); $source->getLaw()->getRights()->add($right); $requestedRight = new RequestedRight(); $requestedRight->setActionType($crud); $requestedRight->setLayer($layer); $requestedRight->setReciever($reciever); $requestedEntity = $this->createMock(RequestedEntityInterface::class); $requestedEntity->method('hasId')->willReturn(true); $requestedEntity->method('getEntity')->willReturn($source); $requestedRight->setRequestedEntity($requestedEntity); $result = $this->secureRequestedRightCheckerService->check($requestedRight); $this->assertTrue($result); } public function testNotGranted(): void { $reciever = new class() extends AbstractSource { }; $layer = LayerType::SOURCE; $crud = CRUDType::READ; $source = new class() extends AbstractSource { }; $right = new Right(); $right->setSource($source); $right->setLayer($layer); $right->setActionType(CRUDType::CREATE); $right->setReciever($reciever); $source->getLaw()->getRights()->add($right); $requestedRight = new RequestedRight(); $requestedRight->setActionType($crud); $requestedRight->setLayer($layer); $requestedRight->setReciever($reciever); $requestedEntity = $this->createMock(RequestedEntityInterface::class); $requestedEntity->method('hasId')->willReturn(true); $requestedEntity->method('getEntity')->willReturn($source); $requestedRight->setRequestedEntity($requestedEntity); $result = $this->secureRequestedRightCheckerService->check($requestedRight); $this->assertFalse($result); } }