externalShareMapper = $this->createMock(ExternalShareMapper::class); $this->logger = $this->createMock(LoggerInterface::class); $userSession = $this->createMock(IUserSession::class); $userSession->method('getUser')->willReturn(null); $this->manager = new Manager( $this->createMock(IDBConnection::class), $this->createMock(\OC\Files\Mount\Manager::class), $this->createMock(IStorageFactory::class), $this->createMock(IClientService::class), $this->createMock(INotificationManager::class), $this->createMock(IDiscoveryService::class), $this->createMock(ICloudFederationProviderManager::class), $this->createMock(ICloudFederationFactory::class), $this->createMock(IGroupManager::class), $userSession, $this->createMock(IEventDispatcher::class), $this->logger, $this->createMock(IRootFolder::class), $this->createMock(ISetupManager::class), $this->createMock(ICertificateManager::class), $this->externalShareMapper, $this->createMock(IConfig::class), ); } public function testUpdateAccessTokenUpdatesShareInDb(): void { $share = new ExternalShare(); $share->setRefreshToken('refresh-token'); $this->externalShareMapper->expects($this->once()) ->method('getShareByToken') ->with('refresh-token') ->willReturn($share); $this->externalShareMapper->expects($this->once()) ->method('update') ->with($this->callback(function (ExternalShare $s) { return $s->getAccessToken() === 'new-access-token' && $s->getAccessTokenExpires() === 9999; })); $this->manager->updateAccessToken('refresh-token', 'new-access-token', 9999); } public function testUpdateAccessTokenLogsWarningWhenShareNotFound(): void { $this->externalShareMapper->method('getShareByToken') ->willThrowException(new DoesNotExistException('not found')); $this->externalShareMapper->expects($this->never())->method('update'); $this->logger->expects($this->once()) ->method('warning') ->with($this->stringContains('Could not find share')); $this->manager->updateAccessToken('missing-token', 'access', 0); } public function testUpdateAccessTokenLogsErrorOnDbException(): void { $this->externalShareMapper->method('getShareByToken') ->willThrowException(new Exception('db error')); $this->externalShareMapper->expects($this->never())->method('update'); $this->logger->expects($this->once()) ->method('error') ->with($this->stringContains('Failed to update access token')); $this->manager->updateAccessToken('some-token', 'access', 0); } }