discoveryService = $this->createMock(DiscoveryService::class); $this->discoveryService->expects($this->any())->method('discover')->willReturn([]); $this->logger = $this->createMock(LoggerInterface::class); } public function testSync(): void { /** @var DbHandler&MockObject $dbHandler */ $dbHandler = $this->createMock(DbHandler::class); $dbHandler->method('getAllServer') ->willReturn([ [ 'url' => 'https://cloud.example.org', 'url_hash' => 'sha1', 'shared_secret' => 'ilovenextcloud', 'sync_token' => '0' ] ]); $dbHandler->expects($this->once())->method('setServerStatus') ->with('https://cloud.example.org', 1, '1'); $syncService = $this->createMock(SyncService::class); $syncService->expects($this->once())->method('syncRemoteAddressBook') ->willReturn('1'); /** @var SyncService $syncService */ $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); $s->syncThemAll(function ($url, $ex): void { $this->callBacks[] = [$url, $ex]; }); $this->assertCount(1, $this->callBacks); } public function testException(): void { /** @var DbHandler&MockObject $dbHandler */ $dbHandler = $this->createMock(DbHandler::class); $dbHandler->method('getAllServer') ->willReturn([ [ 'url' => 'https://cloud.example.org', 'url_hash' => 'sha1', 'shared_secret' => 'ilovenextcloud', 'sync_token' => '0' ] ]); $syncService = $this->createMock(SyncService::class); $syncService->expects($this->once())->method('syncRemoteAddressBook') ->willThrowException(new \Exception('something did not work out')); /** @var SyncService $syncService */ $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); $s->syncThemAll(function ($url, $ex): void { $this->callBacks[] = [$url, $ex]; }); $this->assertCount(2, $this->callBacks); } public function testSuccessfulSyncWithoutChangesAfterFailure(): void { /** @var DbHandler&MockObject $dbHandler */ $dbHandler = $this->createMock(DbHandler::class); $dbHandler->method('getAllServer') ->willReturn([ [ 'url' => 'https://cloud.example.org', 'url_hash' => 'sha1', 'shared_secret' => 'ilovenextcloud', 'sync_token' => '0' ] ]); $dbHandler->method('getServerStatus')->willReturn(TrustedServers::STATUS_FAILURE); $dbHandler->expects($this->once())->method('setServerStatus') ->with('https://cloud.example.org', 1); $syncService = $this->createMock(SyncService::class); $syncService->expects($this->once())->method('syncRemoteAddressBook') ->willReturn('0'); /** @var SyncService $syncService */ $s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger); $s->syncThemAll(function ($url, $ex): void { $this->callBacks[] = [$url, $ex]; }); $this->assertCount(1, $this->callBacks); } }