From f3338ddf843af7d4585daa105ff48bbb0eae3c9f Mon Sep 17 00:00:00 2001 From: nabim777 Date: Mon, 1 Jun 2026 09:32:36 +0545 Subject: [PATCH 1/5] test: replace method withConsecutive Signed-off-by: nabim777 --- tests/lib/Controller/ConfigControllerTest.php | 58 +++---- tests/lib/Controller/FilesControllerTest.php | 141 +++++++++--------- .../OpenProjectAPIControllerTest.php | 18 ++- .../lib/Service/OpenProjectAPIServiceTest.php | 85 +++++------ 4 files changed, 137 insertions(+), 165 deletions(-) diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index f062e16a2..c69aaca14 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -1264,20 +1264,13 @@ public function testOPOAuthTokenRevokeDoesNotOccurIfNoOPOAuthClientHasChanged() $configMock ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'openproject_client_id', ''], - ['integration_openproject', 'openproject_client_secret', ''], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''] - ) - ->willReturnOnConsecutiveCalls( - $oldAdminConfig['openproject_instance_url'], - $oldAdminConfig['authorization_method'], - $oldAdminConfig['openproject_client_id'], - $oldAdminConfig['openproject_client_secret'], - '' - ); + ->willReturnMap([ + [Application::APP_ID, 'openproject_instance_url', '', $oldAdminConfig['openproject_instance_url']], + [Application::APP_ID, 'authorization_method', '', $oldAdminConfig['authorization_method']], + [Application::APP_ID, 'openproject_client_id', '', $oldAdminConfig['openproject_client_id']], + [Application::APP_ID, 'openproject_client_secret', '', $oldAdminConfig['openproject_client_secret']], + [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], + ]); $configMock ->expects($this->exactly(2)) ->method('deleteAppValue') @@ -1521,30 +1514,19 @@ public function testSetAdminConfigOIDCAuthSetting( ->getMock(); $configMock ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'oidc_provider'], - ['integration_openproject', 'targeted_audience_client_id'], - ['integration_openproject', 'nc_oauth_client_id', ''], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'oidc_provider'], - ['integration_openproject', 'targeted_audience_client_id'], - ['integration_openproject', 'openproject_instance_url'], - ) - ->willReturnOnConsecutiveCalls( - $oldCreds['openproject_instance_url'], - $oldCreds['authorization_method'], - $oldCreds['oidc_provider'], - $oldCreds['targeted_audience_client_id'], - '123', - '', - Application::AUTH_METHOD_OAUTH, - $credsToUpdate['oidc_provider'], - $credsToUpdate['targeted_audience_client_id'], - $credsToUpdate['openproject_instance_url'] - ); + ->willReturnMap([ + ['integration_openproject', 'openproject_instance_url', '', $oldCreds['openproject_instance_url']], + ['integration_openproject', 'authorization_method', '', $oldCreds['authorization_method']], + ['integration_openproject', 'oidc_provider', '', $oldCreds['oidc_provider']], + ['integration_openproject', 'targeted_audience_client_id', '', $oldCreds['targeted_audience_client_id']], + ['integration_openproject', 'nc_oauth_client_id', '', '123'], + ['integration_openproject', 'oPOAuthTokenRevokeStatus', '', ''], + ['integration_openproject', 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OIDC], + ['integration_openproject', 'oidc_provider', '', $credsToUpdate['oidc_provider']], + ['integration_openproject', 'targeted_audience_client_id', '', $credsToUpdate['targeted_audience_client_id']], + ['integration_openproject', 'openproject_instance_url', '', $credsToUpdate['openproject_instance_url']], + + ]); $apiService = $this->getMockBuilder(OpenProjectAPIService::class) ->disableOriginalConstructor() diff --git a/tests/lib/Controller/FilesControllerTest.php b/tests/lib/Controller/FilesControllerTest.php index ba01f6eca..0d0b06e5f 100644 --- a/tests/lib/Controller/FilesControllerTest.php +++ b/tests/lib/Controller/FilesControllerTest.php @@ -187,20 +187,20 @@ public function testGetFileInfoFileExistingButCannotGetNameInContextOfOwner(): v public function testGetFilesInfoFourIdsRequestedOneExistsOneInTrashOneNotExisitingOneForbidden(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([123], [759], [365], [956]) - ->willReturnOnConsecutiveCalls( + ->willReturnMap( [ - $this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png') - ], - [], - [] + [123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]], + [759, []], + [365, []], + [956, []] + ] ); $cachedMountFileInfoMock = $this->getMockBuilder( ICachedMountFileInfo::class )->getMock(); $cachedMountFileInfoMock->method('getInternalPath') - ->willReturnOnConsecutiveCalls( + ->willReturn( 'files/logo.png', 'files_trashbin/files/welcome.txt.d1648724302', '/anotherUser/files/logo.png' @@ -213,19 +213,20 @@ public function testGetFilesInfoFourIdsRequestedOneExistsOneInTrashOneNotExisiti $mountCacheMock = $this->getMockBuilder(IUserMountCache::class)->getMock(); $mountCacheMock->method('getMountsForFileId') - ->withConsecutive([123], [759], [365], [956]) - ->willReturnOnConsecutiveCalls( - [$cachedMountFileInfoMock], - [$cachedMountFileInfoMock], - [], // not found - [$cachedMountFileInfoMock], + ->willReturnMap( + [ + [123, null, [$cachedMountFileInfoMock]], + [759, null, [$cachedMountFileInfoMock]], + [365, null, []], + [956, null, [$cachedMountFileInfoMock]] + ] ); $filesController = $this->getFilesControllerMock( ['getDavPermissions'], $folderMock, $mountCacheMock ); $filesController->method('getDavPermissions') - ->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW'); + ->willReturn('RGDNVW', 'RGDNVW'); $result = $filesController->getFilesInfo([123, 759, 365, 956]); assertSame( @@ -268,13 +269,12 @@ public function testGetFilesInfoOneIdRequestedFileExistsReturnsOneResult(): void public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([123], [256], [365]) - ->willReturnOnConsecutiveCalls( + ->willReturnMap( [ - $this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png') - ], - [], - [] + [123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]], + [256, []], + [365, []] + ] ); $cachedMountFileInfoMock = $this->getMockBuilder( @@ -289,7 +289,7 @@ public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult() $mountCacheMock = $this->getMockBuilder(IUserMountCache::class) ->getMock(); $mountCacheMock->method('getMountsForFileId') - ->willReturnOnConsecutiveCalls( + ->willReturn( [$cachedMountFileInfoMock], [], [] ); @@ -313,20 +313,18 @@ public function testGetFilesInfoThreeIdsRequestedOneFileExistsReturnsOneResult() public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResult(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([123], [365]) - ->willReturnOnConsecutiveCalls( + ->willReturnMap( [ - $this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png') - ], - [ - $this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png'), + [123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]], + [365, [$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png')]] ] ); + $cachedMountFileInfoMock = $this->getMockBuilder( ICachedMountFileInfo::class )->getMock(); $cachedMountFileInfoMock->method('getInternalPath') - ->willReturnOnConsecutiveCalls( + ->willReturn( 'files/logo.png', 'files/inFolder/image.png', ); @@ -344,7 +342,7 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResul ['getDavPermissions'], $folderMock, $mountCacheMock ); $filesController->method('getDavPermissions') - ->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW'); + ->willReturn('RGDNVW'); $result = $filesController->getFilesInfo([123,365]); assertSame( [ @@ -359,13 +357,10 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsOneResul public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultipleResults(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([123], [365]) - ->willReturnOnConsecutiveCalls( - [ - $this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png'), - ], + ->willReturnMap( [ - $this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png'), + [123, [$this->getNodeMock('image/png', 123, 'file', '/testUser/files/logo.png')]], + [365, [$this->getNodeMock('image/png', 365, 'file', '/testUser/files/inFolder/image.png')]] ] ); @@ -373,7 +368,7 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultiple ICachedMountFileInfo::class )->getMock(); $cachedMountFileInfoMock->method('getInternalPath') - ->willReturnOnConsecutiveCalls( + ->willReturn( 'files/logo.png', 'files/inFolder/image.png', ); @@ -391,7 +386,7 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultiple ['getDavPermissions'], $folderMock, $mountCacheMock ); $filesController->method('getDavPermissions') - ->willReturnOnConsecutiveCalls('RGDNVW', 'RGDNVW'); + ->willReturn('RGDNVW'); $result = $filesController->getFilesInfo([123,365]); assertSame( @@ -407,31 +402,36 @@ public function testGetFilesInfoTwoIdsRequestedAllFilesExistsEachReturnsMultiple public function testGetFilesInfoTwoIdsRequestedEachReturnsOneFolder(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([2], [3]) - ->willReturnOnConsecutiveCalls( + ->willReturnMap([ [ - $this->getNodeMock( - 'httpd/unix-directory', - 2, - 'dir', - '/testUser/files/myFolder/a-sub-folder' - ) + 2, + [ + $this->getNodeMock( + 'httpd/unix-directory', + 2, + 'dir', + '/testUser/files/myFolder/a-sub-folder' + ) + ] ], [ - $this->getNodeMock( - 'httpd/unix-directory', - 3, - 'dir', - '/testUser/files' - ) - ] - ); + 3, + [ + $this->getNodeMock( + 'httpd/unix-directory', + 3, + 'dir', + '/testUser/files' + ) + ] + ], + ]); $cachedMountFileInfoMock = $this->getMockBuilder( ICachedMountFileInfo::class )->getMock(); $cachedMountFileInfoMock->method('getInternalPath') - ->willReturnOnConsecutiveCalls( + ->willReturn( 'files/myFolder/a-sub-folder', 'files' ); @@ -449,7 +449,7 @@ public function testGetFilesInfoTwoIdsRequestedEachReturnsOneFolder(): void { ['getDavPermissions'], $folderMock, $mountCacheMock ); $filesController->method('getDavPermissions') - ->willReturnOnConsecutiveCalls('RGDNVCK', 'RGDNVCK'); + ->willReturn('RGDNVCK', 'RGDNVCK'); $result = $filesController->getFilesInfo([2,3]); assertSame( @@ -507,31 +507,32 @@ public function testGetFilesInfoInvalidRequest(): void { public function testGetFilesInfoSendStringIds(): void { $folderMock = $this->getMockBuilder(Folder::class)->getMock(); $folderMock->method('getById') - ->withConsecutive([2], [3]) - ->willReturnOnConsecutiveCalls( - [ - $this->getNodeMock( + ->willReturnMap([ + [ 2, + [$this->getNodeMock( 'httpd/unix-directory', 2, 'dir', '/testUser/files/myFolder/a-sub-folder' - ) + )] ], - [ - $this->getNodeMock( - 'httpd/unix-directory', - 3, - 'dir', - '/testUser/files/testFolder' - ) + [ 3, + [ + $this->getNodeMock( + 'httpd/unix-directory', + 3, + 'dir', + '/testUser/files/testFolder' + ) + ] ] - ); + ]); $cachedMountFileInfoMock = $this->getMockBuilder( ICachedMountFileInfo::class )->getMock(); $cachedMountFileInfoMock->method('getInternalPath') - ->willReturnOnConsecutiveCalls( + ->willReturn( 'files/myFolder/a-sub-folder', '' ); @@ -549,7 +550,7 @@ public function testGetFilesInfoSendStringIds(): void { ['getDavPermissions'], $folderMock, $mountCacheMock ); $filesController->method('getDavPermissions') - ->willReturnOnConsecutiveCalls('RGDNVCK', 'RGDNVCK'); + ->willReturn('RGDNVCK', 'RGDNVCK'); $result = $filesController->getFilesInfo(["2","3"]); assertSame( diff --git a/tests/lib/Controller/OpenProjectAPIControllerTest.php b/tests/lib/Controller/OpenProjectAPIControllerTest.php index 40a7bbde7..416a6409b 100644 --- a/tests/lib/Controller/OpenProjectAPIControllerTest.php +++ b/tests/lib/Controller/OpenProjectAPIControllerTest.php @@ -61,18 +61,20 @@ public function getConfigMock(string $authorizationMethod = '', $authToken = nul $configMock = $this->getMockBuilder(IConfig::class)->getMock(); $configMock ->method('getUserValue') - ->withConsecutive( - ['test','integration_openproject', 'token'], - ['test','integration_openproject', 'refresh_token'], - )->willReturnOnConsecutiveCalls($token, 'refreshToken'); + ->willReturnMap( + [ + ['test', 'integration_openproject', 'token', '', $token], + ['test', 'integration_openproject', 'refresh_token', '', 'refreshToken'] + ] + ); $opUrl = $opUrl ?? 'https://openproject.org'; $configMock ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url'], - ['integration_openproject', 'authorization_method'], - )->willReturnOnConsecutiveCalls($opUrl, $authorizationMethod); + ->willReturnMap([ + ['integration_openproject', 'openproject_instance_url', '', $opUrl], + ['integration_openproject', 'authorization_method', '', $authorizationMethod], + ]); return $configMock; } diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index 58805bc5b..595e9f236 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -726,29 +726,18 @@ private function getOpenProjectAPIService( $clientConfigMock = $this->getMockBuilder(IConfig::class)->getMock(); $clientConfigMock ->method('getSystemValueBool') - ->withConsecutive( - ['allow_local_remote_servers', false], - ['installed', false], - ['allow_local_remote_servers', false], - ['allow_local_remote_servers', false], - ['installed', false], - ['allow_local_remote_servers', false], - ['allow_local_remote_servers', false], - ['installed', false], - ['allow_local_remote_servers', false] - ) - ->willReturnOnConsecutiveCalls( - true, - true, - true, - true, - true, - true, - true, - true, - true + ->willReturnMap([ + ['allow_local_remote_servers', false, true], + ['installed', false, true], + ['allow_local_remote_servers', false, true], + ['allow_local_remote_servers', false, true], + ['installed', false, true], + ['allow_local_remote_servers', false, true], + ['allow_local_remote_servers', false, true], + ['installed', false, true], + ['allow_local_remote_servers', false, true] + ] ); - $clientService = $this->getMockBuilder(IClientService::class)->getMock(); $clientService->method('newClient')->willReturn($this->createMock(Client::class)); @@ -963,9 +952,10 @@ public function testSearchWorkPackageNotLinkedToAStorage(array $response, array public function testSearchWorkPackageByFileIdOnlyFileId() { $service = $this->getOpenProjectAPIServiceMock(); $service->method('request') - ->withConsecutive( + ->willReturnMap([ [ - 'user', 'work_packages', + 'user', + 'work_packages', [ 'filters' => '[' . '{"file_link_origin_id":{"operator":"=","values":["123"]}},'. @@ -973,12 +963,12 @@ public function testSearchWorkPackageByFileIdOnlyFileId() { '{"operator":"=","values":["https%3A%2F%2Fnc.my-server.org"]}}'. ']', 'sortBy' => '[["updatedAt","desc"]]', - ] - ], - ) - ->willReturnOnConsecutiveCalls( - ["_embedded" => ["elements" => [['id' => 1], ['id' => 2], ['id' => 3]]]] + ], + 'GET', + ["_embedded" => ["elements" => [['id' => 1], ['id' => 2], ['id' => 3]]]] + ]] ); + $result = $service->searchWorkPackage('user', null, 123); $this->assertSame([['id' => 1], ['id' => 2], ['id' => 3]], $result); } @@ -2218,14 +2208,12 @@ public function testRequestConnectException( ])); $configMock ->method('getUserValue') - ->withConsecutive( - ['','integration_openproject', 'token'], - ['','integration_openproject', 'token_expires_at'], - ['','integration_openproject', 'refresh_token'], - ) - ->willReturnOnConsecutiveCalls( - '', - '', + ->willReturnMap( + [ + ['','integration_openproject', 'token', '', ''], + ['','integration_openproject', 'token_expires_at', '', ''], + ['','integration_openproject', 'refresh_token', '', ''], + ] ); $constructArgs = $this->getOpenProjectAPIServiceConstructArgs([ @@ -2268,13 +2256,11 @@ public function testRequestClientServerException( ])); $configMock ->method('getUserValue') - ->withConsecutive( - ['','integration_openproject', 'token'], - ['','integration_openproject', 'refresh_token'], - ) - ->willReturnOnConsecutiveCalls( - '', - '', + ->willReturnMap( + [ + ['','integration_openproject', 'token', '', ''], + ['','integration_openproject', 'refresh_token', '', ''], + ] ); $constructArgs = $this->getOpenProjectAPIServiceConstructArgs([ @@ -4450,11 +4436,12 @@ public function testIsAdminAuditConfigSetCorrectly( $iAppManagerMock = $this->getMockBuilder(IAppManager::class)->getMock(); $configMock ->method('getSystemValue') - ->withConsecutive( - ['loglevel'], - ['logfile_audit'], - ['log.condition'] - )->willReturnOnConsecutiveCalls($logLevel, $pathToAuditLog, $logCondition); + ->willReturnMap([ + ['loglevel', '', $logLevel], + ['logfile_audit', '', $pathToAuditLog], + ['log.condition', '', $logCondition] + ] + ); $userManagerMock = $this->getMockBuilder(IUserManager::class) ->getMock(); $iAppManagerMock->method('isInstalled')->with('admin_audit') From d40318645b32fa02bcd2cb9a1b2d5e5f4c313551 Mon Sep 17 00:00:00 2001 From: nabim777 Date: Tue, 2 Jun 2026 17:05:20 +0545 Subject: [PATCH 2/5] tes: use callback Signed-off-by: nabim777 --- tests/lib/Controller/ConfigControllerTest.php | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index c69aaca14..7b36acf43 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -272,16 +272,49 @@ public function testOauthRedirectWrongState() { $configMock = $this->getConfigMock( str_repeat("A", 128), str_repeat("S", 50) ); + + $calls = [ + ['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], + ['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error during OAuth exchanges', null], + ]; + $configMock - ->expects($this->exactly(2)) + ->expects($this->exactly(count($calls))) ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - [ - 'testUser', 'integration_openproject', 'oauth_connection_error_message', - 'Error during OAuth exchanges' - ], - ); + ->willReturnCallback(function (...$args) use (&$calls) { + $expected = array_shift($calls); + $this->assertSame($expected, $args); + }); + + + // $matcher = $this->exactly(count($this->parts)); + // $calls = [ + // [ + // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[0]->getContentType(), $this->parts[0]->getPath(), $this->parts[0]->getName(), $this->boundary], + // 'return' => new Result(true, ''), + // ], + // [ + // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[1]->getContentType(), $this->parts[1]->getPath(), $this->parts[1]->getName(), $this->boundary], + // 'return' => new Result(true, ''), + // ], + // [ + // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[2]->getContentType(), $this->parts[2]->getPath(), $this->parts[2]->getName(), $this->boundary], + // 'return' => new Result($success, $success ? '' : $this->message), + // ] + // ]; + // $this->client + // ->expects($matcher) + // ->method('withMultipartFileV2') + // ->willReturnCallback( + // function (...$args) use ($calls, $matcher) { + // $index = $matcher->numberOfInvocations() - 1; + // $call = $calls[$index]; + // $this->assertSame($call['args'], $args); + + // return $call['return']; + // } + // ); + $constructArgs = $this->getConfigControllerConstructArgs([ 'config' => $configMock, From 83699019f836220ab6fd0930320b34c65d2f13a3 Mon Sep 17 00:00:00 2001 From: nabim777 Date: Mon, 6 Jul 2026 08:31:06 +0545 Subject: [PATCH 3/5] ci: fix some test Signed-off-by: nabim777 --- lib/Controller/ConfigController.php | 2 +- tests/lib/Controller/ConfigControllerTest.php | 658 +++++++++--------- .../Controller/OpenProjectControllerTest.php | 18 +- .../lib/Service/OpenProjectAPIServiceTest.php | 29 +- 4 files changed, 344 insertions(+), 363 deletions(-) diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index de3b9667f..2e2d3a700 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -109,7 +109,7 @@ public function __construct( * @param string|null $userId * @return void */ - public function clearUserInfo(string $userId = null) { + public function clearUserInfo(?string $userId = null) { if ($userId === null) { $userId = $this->userId; } diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index 7b36acf43..2b13da308 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -44,6 +44,33 @@ protected function tearDown(): void { } } + /** + * @param MockObject $mock The mock object on which the method is expected to be called + * @param string $method The method name for which the expectations are set + * @param array $calls An array of expected argument arrays for each call + */ + private function expectMethodCalls( + $mock, + string $method, + array $calls, + ?bool $exactly = false + ): void { + if ($exactly) { + $expectedCallsCount = $this->exactly(count($calls)); + } else { + $expectedCallsCount = $this->any(); + } + $mock + ->expects($expectedCallsCount) + ->method($method) + ->willReturnCallback(function (...$args) use (&$calls) { + // if not $returnValue = array_pop($calls); + [$expectedArgs, $returnValue] = array_shift($calls); + $this->assertSame($expectedArgs, $args); + return $returnValue; + }); + } + /** * @param string $codeVerifier The string that should be used as code_verifier * @param string $clientSecret The string that should be used as openproject_client_secret @@ -54,31 +81,29 @@ private function getConfigMock( $codeVerifier, $clientSecret, $startingPage = '{ page: "files" }' ) { $configMock = $this->getMockBuilder(IConfig::class)->getMock(); - $configMock - ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_client_id'], - ['integration_openproject', 'openproject_client_secret'], - ['integration_openproject', 'openproject_instance_url'], - ['integration_openproject', 'openproject_client_id'], - ['integration_openproject', 'openproject_client_secret'], - )->willReturnOnConsecutiveCalls( - 'clientID', $clientSecret, 'http://openproject.org', 'clientID', 'clientSecret', - ); + + $this->expectMethodCalls($configMock, 'getAppValue', [ + [['integration_openproject', 'openproject_client_id', ''], 'clientID'], + [['integration_openproject', 'openproject_client_secret', ''], $clientSecret], + [['integration_openproject', 'openproject_instance_url', ''], 'http://openproject.org'], + [['integration_openproject', 'openproject_client_id', ''], 'clientID'], + [['integration_openproject', 'openproject_client_secret', ''], 'clientSecret'], + ]); + + // $this->expectMethodCalls($configMock, 'getUserValue', [ + // [['testUser', 'integration_openproject', 'oauth_state', ''], 'randomString'], + // [['testUser', 'integration_openproject', 'code_verifier', false], $codeVerifier], + // [['testUser', 'integration_openproject', 'oauth_journey_starting_page', ''], $startingPage], + // [['testUser', 'integration_openproject', 'refresh_token', false], 'oAuthRefreshToken'], + // ]); $configMock ->method('getUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_state'], - ['testUser', 'integration_openproject', 'code_verifier'], - ['testUser', 'integration_openproject', 'oauth_journey_starting_page'], - ['testUser', 'integration_openproject', 'refresh_token'], - ) - ->willReturnOnConsecutiveCalls( - 'randomString', - $codeVerifier, - $startingPage, - 'oAuthRefreshToken', - ); + ->willReturnMap([ + ['testUser', 'integration_openproject', 'oauth_state', '', 'randomString'], + ['testUser', 'integration_openproject', 'code_verifier', false, $codeVerifier], + ['testUser', 'integration_openproject', 'oauth_journey_starting_page', '', $startingPage], + ['testUser', 'integration_openproject', 'refresh_token', false, 'oAuthRefreshToken'], + ]); return $configMock; } @@ -165,13 +190,10 @@ public function testOauthRedirectSuccess():void { str_repeat("A", 128), str_repeat("S", 50)); $configMock ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'token', 'oAuthAccessToken'], - ['testUser', 'integration_openproject', 'refresh_token', 'oAuthRefreshToken'], - ['testUser', 'integration_openproject', 'user_id', 1], - ['testUser', 'integration_openproject', 'user_name', 'Tripathi Himal'], - ['testUser', 'integration_openproject', 'oauth_connection_result', 'success'], + ->with( + 'testUser', 'integration_openproject', 'oauth_connection_result', 'success' ); + $urlGeneratorMock = $this->getMockBuilder(IURLGenerator::class) ->disableOriginalConstructor() ->getMock(); @@ -184,12 +206,12 @@ public function testOauthRedirectSuccess():void { ->getMock(); $apiServiceMock - ->method('request') + ->method('initUserInfo') ->with( 'testUser', - 'users/me' + 'oAuthAccessToken' ) - ->willReturn(['lastName' => 'Himal', 'firstName' => 'Tripathi', 'id' => 1]); + ->willReturn(['user_name' => 'Tripathi Himal']); $apiServiceMock ->method('requestOAuthAccessToken') @@ -273,48 +295,10 @@ public function testOauthRedirectWrongState() { str_repeat("A", 128), str_repeat("S", 50) ); - $calls = [ - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], - ['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error during OAuth exchanges', null], - ]; - - $configMock - ->expects($this->exactly(count($calls))) - ->method('setUserValue') - ->willReturnCallback(function (...$args) use (&$calls) { - $expected = array_shift($calls); - $this->assertSame($expected, $args); - }); - - - // $matcher = $this->exactly(count($this->parts)); - // $calls = [ - // [ - // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[0]->getContentType(), $this->parts[0]->getPath(), $this->parts[0]->getName(), $this->boundary], - // 'return' => new Result(true, ''), - // ], - // [ - // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[1]->getContentType(), $this->parts[1]->getPath(), $this->parts[1]->getName(), $this->boundary], - // 'return' => new Result(true, ''), - // ], - // [ - // 'args' => [$this->interactionHandle, $this->requestPartId, $this->parts[2]->getContentType(), $this->parts[2]->getPath(), $this->parts[2]->getName(), $this->boundary], - // 'return' => new Result($success, $success ? '' : $this->message), - // ] - // ]; - // $this->client - // ->expects($matcher) - // ->method('withMultipartFileV2') - // ->willReturnCallback( - // function (...$args) use ($calls, $matcher) { - // $index = $matcher->numberOfInvocations() - 1; - // $call = $calls[$index]; - // $this->assertSame($call['args'], $args); - - // return $call['return']; - // } - // ); - + $this->expectMethodCalls($configMock, 'setUserValue', [ + [['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], null], + [['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error during OAuth exchanges', null], null], + ]); $constructArgs = $this->getConfigControllerConstructArgs([ 'config' => $configMock, @@ -353,27 +337,17 @@ public function testOauthRedirectCodeVerifier($codeVerifier, $valid) { $loggerMock->expects($this->never()) ->method('error'); // even the secret is valid, we get an error because the token request is not mocked - $configMock->expects($this->exactly(2)) - ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - [ - 'testUser', 'integration_openproject', 'oauth_connection_error_message', - 'Error getting OAuth access token' - ], - ); + $this->expectMethodCalls($configMock, 'setUserValue', [ + [['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], null], + [['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error getting OAuth access token', null], null], + ], true); } else { $loggerMock->expects($this->once()) ->method('error'); - $configMock->expects($this->exactly(2)) - ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - [ - 'testUser', 'integration_openproject', 'oauth_connection_error_message', - 'Error during OAuth exchanges' - ], - ); + $this->expectMethodCalls($configMock, 'setUserValue', [ + [['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], null], + [['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error during OAuth exchanges', null], null], + ], true); } $constructArgs = $this->getConfigControllerConstructArgs([ @@ -416,25 +390,19 @@ public function testOauthRedirectSecret($clientSecret, $valid) { // even the secret is valid, we get an error because the token request is not mocked $configMock->expects($this->exactly(2)) ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - [ - 'testUser', 'integration_openproject', 'oauth_connection_error_message', - 'Error getting OAuth access token' - ], - ); + ->willReturnMap([ + ['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null, null], + ['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error getting OAuth access token', null, null], + ]); } else { $loggerMock->expects($this->once()) ->method('error'); $configMock->expects($this->exactly(2)) ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - [ - 'testUser', 'integration_openproject', 'oauth_connection_error_message', - 'Error during OAuth exchanges' - ], - ); + ->willReturnMap([ + ['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null, null], + ['testUser', 'integration_openproject', 'oauth_connection_error_message', 'Error during OAuth exchanges', null, null], + ]); } $constructArgs = $this->getConfigControllerConstructArgs([ @@ -495,12 +463,10 @@ public function testOauthNoAccessTokenInResponse($oauthResponse, $expectedErrorM $configMock = $this->getConfigMock( str_repeat("A", 128), str_repeat("S", 50) ); - $configMock->expects($this->exactly(2)) - ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'oauth_connection_result', 'error'], - ['testUser', 'integration_openproject', 'oauth_connection_error_message', $expectedErrorMessage], - ); + $this->expectMethodCalls($configMock, 'setUserValue', [ + [['testUser', 'integration_openproject', 'oauth_connection_result', 'error', null], null], + [['testUser', 'integration_openproject', 'oauth_connection_error_message', $expectedErrorMessage, null], null], + ], true); $constructArgs = $this->getConfigControllerConstructArgs([ 'config' => $configMock, @@ -549,14 +515,13 @@ public function testSetAdminConfigForDifferentAdminConfigStatusForOauth2($credsT $configMock = $this->getMockBuilder(IConfig::class)->getMock(); $configMock - ->expects($this->exactly(4)) ->method('setAppValue') - ->withConsecutive( + ->willReturnMap([ ['integration_openproject', 'authorization_method', $credsToUpdate['authorization_method']], ['integration_openproject', 'openproject_client_id', $credsToUpdate['openproject_client_id']], ['integration_openproject', 'openproject_client_secret', $credsToUpdate['openproject_client_secret']], ['integration_openproject', 'openproject_instance_url', $credsToUpdate['openproject_instance_url']] - ); + ]); $configMock ->method('getAppValue') ->willReturnMap([ @@ -645,15 +610,14 @@ public function testSetAdminConfigForDifferentAdminConfigStatusForOIDC($credsToU $userManager = \OC::$server->getUserManager(); $configMock = $this->getMockBuilder(IConfig::class)->getMock(); - $configMock - ->expects($this->exactly(4)) - ->method('setAppValue') - ->withConsecutive( - ['integration_openproject', 'authorization_method', $credsToUpdate['authorization_method']], - ['integration_openproject', 'oidc_provider', $credsToUpdate['oidc_provider']], - ['integration_openproject', 'targeted_audience_client_id', $credsToUpdate['targeted_audience_client_id']], - ['integration_openproject', 'openproject_instance_url', $credsToUpdate['openproject_instance_url']] - ); + + $this->expectMethodCalls($configMock, 'setAppValue', [ + [['integration_openproject', 'authorization_method', $credsToUpdate['authorization_method']], null], + [['integration_openproject', 'oidc_provider', $credsToUpdate['oidc_provider']], null], + [['integration_openproject', 'targeted_audience_client_id', $credsToUpdate['targeted_audience_client_id']], null], + [['integration_openproject', 'openproject_instance_url', $credsToUpdate['openproject_instance_url']], null], + ], true); + $configMock ->method('getAppValue') ->willReturnMap([ @@ -664,6 +628,8 @@ public function testSetAdminConfigForDifferentAdminConfigStatusForOIDC($credsToU [Application::APP_ID, 'targeted_audience_client_id', '', $credsToUpdate['targeted_audience_client_id']], [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], ]); + + $apiService = $this->getMockBuilder(OpenProjectAPIService::class) ->disableOriginalConstructor() ->getMock(); @@ -855,26 +821,22 @@ public function testSetAdminConfigClearUserDataChangeNCOauthClient( $deleteCalls = []; if ($deleteUserValues === true) { $configMock - ->expects($this->exactly(12)) // 5 times for each user + ->expects($this->exactly(12)) ->method('deleteUserValue') - ->willReturnCallback(function ($uid, $app, $key) use (&$deleteCalls) { - $deleteCalls[] = [$uid, $app, $key]; - }); - - $expectedCalls = [ - ['admin', Application::APP_ID, 'token'], - ['admin', Application::APP_ID, 'login'], - ['admin', Application::APP_ID, 'user_id'], - ['admin', Application::APP_ID, 'user_name'], - ['admin', Application::APP_ID, 'refresh_token'], - ['admin', Application::APP_ID, 'token_expires_at'], - [$testUser, Application::APP_ID, 'token'], - [$testUser, Application::APP_ID, 'login'], - [$testUser, Application::APP_ID, 'user_id'], - [$testUser, Application::APP_ID, 'user_name'], - [$testUser, Application::APP_ID, 'refresh_token'], - [$testUser, Application::APP_ID, 'token_expires_at'], - ]; + ->willReturnMap([ + ['admin', Application::APP_ID, 'token', null], + ['admin', Application::APP_ID, 'login', null], + ['admin', Application::APP_ID, 'user_id', null], + ['admin', Application::APP_ID, 'user_name', null], + ['admin', Application::APP_ID, 'refresh_token', null], + ['admin', Application::APP_ID, 'token_expires_at', null], + [$testUser, Application::APP_ID, 'token', null], + [$testUser, Application::APP_ID, 'login', null], + [$testUser, Application::APP_ID, 'user_id', null], + [$testUser, Application::APP_ID, 'user_name', null], + [$testUser, Application::APP_ID, 'refresh_token', null], + [$testUser, Application::APP_ID, 'token_expires_at', null], + ]); } else { $configMock ->expects($this->never()) @@ -939,6 +901,14 @@ public function testSetAdminConfigNotAllowedConfigValues() { public function checkForUsersCountBeforeTest($expectedCount = 1): IUserManager { $userManager = \OC::$server->getUserManager(); + // Keep tests isolated by removing users created by previous runs. + $userManager->callForAllUsers(function (IUser $user) { + if ($user->getUID() !== 'admin') { + $user->delete(); + } + return null; + }); + $actualCount = 0; $function = function () use (&$actualCount) { $actualCount++; @@ -1032,22 +1002,16 @@ public function testSetAdminConfigForOPOAuthTokenRevoke(array $oldConfig, array $oauthSettingsControllerMock = $this->createMock('OCA\OAuth2\Controller\SettingsController'); if ($mode === "reset") { - $configMock - ->expects($this->exactly(3)) - ->method('deleteAppValue') - ->withConsecutive( - ['integration_openproject', 'nc_oauth_client_id'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ); + $this->expectMethodCalls($configMock, 'deleteAppValue', [ + [[Application::APP_ID, 'nc_oauth_client_id'], null], + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + ], true); } else { - $configMock - ->expects($this->exactly(2)) - ->method('deleteAppValue') - ->withConsecutive( - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ); + $this->expectMethodCalls($configMock, 'deleteAppValue', [ + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + ], true); } $configMock @@ -1060,17 +1024,19 @@ public function testSetAdminConfigForOPOAuthTokenRevoke(array $oldConfig, array [Application::APP_ID, 'nc_oauth_client_id', '', $oldAdminConfig['nc_oauth_client_id']], [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], ]); + $configMock ->method('setAppValue') - ->withConsecutive( - ['integration_openproject', 'authorization_method', $newConfig['authorization_method']], - ['integration_openproject', 'openproject_client_id', $newConfig['openproject_client_id']], - ['integration_openproject', 'openproject_client_secret', $newConfig['openproject_client_secret']], - ['integration_openproject', 'openproject_instance_url', $newConfig['openproject_instance_url']], - ['integration_openproject', 'default_enable_navigation', $newConfig['default_enable_navigation']], - ['integration_openproject', 'default_enable_unified_search', $newConfig['default_enable_unified_search']], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', 'success'] - ); + ->willReturnMap([ + [Application::APP_ID, 'authorization_method', $newConfig['authorization_method'], null], + [Application::APP_ID, 'openproject_client_id', $newConfig['openproject_client_id'], null], + [Application::APP_ID, 'openproject_client_secret', $newConfig['openproject_client_secret'], null], + [Application::APP_ID, 'openproject_instance_url', $newConfig['openproject_instance_url'], null], + [Application::APP_ID, 'default_enable_navigation', $newConfig['default_enable_navigation'], null], + [Application::APP_ID, 'default_enable_unified_search', $newConfig['default_enable_unified_search'], null], + [Application::APP_ID, 'oPOAuthTokenRevokeStatus', 'success', null] + ]); + $configMock ->method('getUserValue') ->willReturnMap([ @@ -1081,28 +1047,29 @@ public function testSetAdminConfigForOPOAuthTokenRevoke(array $oldConfig, array $apiService ->expects($this->exactly(2)) ->method('revokeUserOAuthToken') - ->withConsecutive( - ['admin', $oldAdminConfig['openproject_instance_url'], $userTokens['admin'], $oldAdminConfig['openproject_client_id'], $oldAdminConfig['openproject_client_secret']], - [$testUser, $oldAdminConfig['openproject_instance_url'], $userTokens[$testUser], $oldAdminConfig['openproject_client_id'], $oldAdminConfig['openproject_client_secret']], - ); + ->willReturnMap([ + [$oldAdminConfig['openproject_instance_url'], $userTokens['admin'], $oldAdminConfig['openproject_client_id'], $oldAdminConfig['openproject_client_secret'], true], + [$oldAdminConfig['openproject_instance_url'], $userTokens[$testUser], $oldAdminConfig['openproject_client_id'], $oldAdminConfig['openproject_client_secret'], true], + ]); $configMock ->expects($this->exactly(12)) ->method("deleteUserValue") - ->withConsecutive( - ['admin', 'integration_openproject', 'token'], - ['admin', 'integration_openproject', 'login'], - ['admin', 'integration_openproject', 'user_id'], - ['admin', 'integration_openproject', 'user_name'], - ['admin', 'integration_openproject', 'refresh_token'], - ['admin', 'integration_openproject', 'token_expires_at'], - [$this->user1->getUID(), 'integration_openproject', 'token'], - [$this->user1->getUID(), 'integration_openproject', 'login'], - [$this->user1->getUID(), 'integration_openproject', 'user_id'], - [$this->user1->getUID(), 'integration_openproject', 'user_name'], - [$this->user1->getUID(), 'integration_openproject', 'refresh_token'], - [$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], - ); + ->willReturnMap([ + ['admin', Application::APP_ID, 'token', null], + ['admin', Application::APP_ID, 'login', null], + ['admin', Application::APP_ID, 'user_id', null], + ['admin', Application::APP_ID, 'user_name', null], + ['admin', Application::APP_ID, 'refresh_token', null], + ['admin', Application::APP_ID, 'token_expires_at', null], + [$testUser, Application::APP_ID, 'token', null], + [$testUser, Application::APP_ID, 'login', null], + [$testUser, Application::APP_ID, 'user_id', null], + [$testUser, Application::APP_ID, 'user_name', null], + [$testUser, Application::APP_ID, 'refresh_token', null], + [$testUser, Application::APP_ID, 'token_expires_at', null], + ]); + $constructArgs = $this->getConfigControllerConstructArgs([ 'config' => $configMock, 'userManager' => $userManager, @@ -1169,45 +1136,32 @@ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage $oauthSettingsControllerMock = $this->createMock('OCA\OAuth2\Controller\SettingsController'); $loggerInterfaceMock = $this->createMock(LoggerInterface::class); + $this->expectMethodCalls($configMock, 'getAppValue', [ + [[Application::APP_ID, 'openproject_instance_url', ''], $oldAdminConfig['openproject_instance_url']], + [[Application::APP_ID, 'authorization_method', ''], $oldAdminConfig['authorization_method']], + [[Application::APP_ID, 'openproject_client_id', ''], $oldAdminConfig['openproject_client_id']], + [[Application::APP_ID, 'openproject_client_secret', ''], $oldAdminConfig['openproject_client_secret']], + [[Application::APP_ID, 'nc_oauth_client_id', ''], ''], + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus', ''], $errorCode], + [[Application::APP_ID, 'authorization_method', ''], Application::AUTH_METHOD_OAUTH], + [[Application::APP_ID, 'openproject_instance_url', ''], $newAdminConfig['openproject_instance_url']], + [[Application::APP_ID, 'fresh_project_folder_setup', ''], false], + [[Application::APP_ID, 'openproject_client_id', ''], $newAdminConfig['openproject_client_id']], + [[Application::APP_ID, 'openproject_client_secret', ''], $newAdminConfig['openproject_client_secret']], + [[Application::APP_ID, 'openproject_instance_url', ''], $newAdminConfig['openproject_instance_url']], + ]); + $configMock - ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'openproject_client_id', ''], - ['integration_openproject', 'openproject_client_secret', ''], - ['integration_openproject', 'nc_oauth_client_id', ''], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], // for the last check - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'openproject_instance_url'], - ['integration_openproject', 'fresh_project_folder_setup'], - ['integration_openproject', 'openproject_client_id'], - ['integration_openproject', 'openproject_client_secret'], - ['integration_openproject', 'openproject_instance_url'], - ) - ->willReturnOnConsecutiveCalls( - $oldAdminConfig['openproject_instance_url'], - $oldAdminConfig['authorization_method'], - $oldAdminConfig['openproject_client_id'], - $oldAdminConfig['openproject_client_secret'], - '', - $errorCode, - Application::AUTH_METHOD_OAUTH, - $newAdminConfig['openproject_instance_url'], - false, - $newAdminConfig['openproject_client_id'], - $newAdminConfig['openproject_client_secret'], - $newAdminConfig['openproject_instance_url'], - ); - $configMock + ->expects($this->exactly(6)) ->method('setAppValue') - ->withConsecutive( - ['integration_openproject', 'authorization_method', $newAdminConfig['authorization_method']], - ['integration_openproject', 'openproject_client_id', $newAdminConfig['openproject_client_id']], - ['integration_openproject', 'openproject_client_secret', $newAdminConfig['openproject_client_secret']], - ['integration_openproject', 'openproject_instance_url', $newAdminConfig['openproject_instance_url']], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', $errorCode], - ); + ->willReturnMap([ + [Application::APP_ID, 'authorization_method', $newAdminConfig['authorization_method'], null], + [Application::APP_ID, 'openproject_client_id', $newAdminConfig['openproject_client_id'], null], + [Application::APP_ID, 'openproject_client_secret', $newAdminConfig['openproject_client_secret'], null], + [Application::APP_ID, 'openproject_instance_url', $newAdminConfig['openproject_instance_url'], null], + [Application::APP_ID, 'oPOAuthTokenRevokeStatus', $errorCode, null], + [Application::APP_ID, 'fresh_project_folder_setup', false, null], + ]); $configMock ->method('getUserValue') @@ -1217,42 +1171,36 @@ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage $loggerInterfaceMock ->method("error") - ->withConsecutive( - $errMessage, - ); + ->willReturn($errMessage); $apiService ->expects($this->exactly(1)) ->method('revokeUserOAuthToken') - ->withConsecutive( - [ - 'admin', - $oldAdminConfig['openproject_instance_url'], - $userTokens['admin'], - $oldAdminConfig['openproject_client_id'], - $oldAdminConfig['openproject_client_secret'] - ], + ->with( + 'admin', + $oldAdminConfig['openproject_instance_url'], + $userTokens['admin'], + $oldAdminConfig['openproject_client_id'], + $oldAdminConfig['openproject_client_secret'] ) ->willThrowException($exception); $configMock ->expects($this->exactly(6)) ->method("deleteUserValue") - ->withConsecutive( - ['admin', 'integration_openproject', 'token'], - ['admin', 'integration_openproject', 'login'], - ['admin', 'integration_openproject', 'user_id'], - ['admin', 'integration_openproject', 'user_name'], - ['admin', 'integration_openproject', 'refresh_token'], - ['admin', 'integration_openproject', 'token_expires_at'], - ); - $configMock - ->expects($this->exactly(2)) - ->method('deleteAppValue') - ->withConsecutive( - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ); + ->willReturnMap([ + ['admin', Application::APP_ID, 'token', null], + ['admin', Application::APP_ID, 'login', null], + ['admin', Application::APP_ID, 'user_id', null], + ['admin', Application::APP_ID, 'user_name', null], + ['admin', Application::APP_ID, 'refresh_token', null], + ['admin', Application::APP_ID, 'token_expires_at', null], + ]); + + $this->expectMethodCalls($configMock, 'deleteAppValue', [ + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + ], true); $constructArgs = $this->getConfigControllerConstructArgs([ 'config' => $configMock, @@ -1304,13 +1252,22 @@ public function testOPOAuthTokenRevokeDoesNotOccurIfNoOPOAuthClientHasChanged() [Application::APP_ID, 'openproject_client_secret', '', $oldAdminConfig['openproject_client_secret']], [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], ]); + // $configMock + // ->expects($this->exactly(2)) + // ->method('deleteAppValue') + // ->withConsecutive( + // ['integration_openproject', 'oPOAuthTokenRevokeStatus'], + // ['integration_openproject', 'oPOAuthTokenRevokeStatus'] + // ); + // $this->expectMethodCalls($configMock, 'deleteAppValue', [ + // [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + // [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], + // ], true); + $configMock ->expects($this->exactly(2)) ->method('deleteAppValue') - ->withConsecutive( - ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus'] - ); + ->with(Application::APP_ID, 'oPOAuthTokenRevokeStatus'); $apiService ->expects($this->exactly(0)) @@ -1632,33 +1589,22 @@ public function testSetAdminConfigForOAuth2AlreadyConfigured( $oauthSettingsControllerMock = $this->getMockBuilder(SettingsController::class) ->disableOriginalConstructor() ->getMock(); - $configMock - ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'openproject_client_id'], - ['integration_openproject', 'openproject_client_secret'], - ['integration_openproject', 'nc_oauth_client_id', ''], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'openproject_client_id'], - ['integration_openproject', 'openproject_client_secret'], - ['integration_openproject', 'openproject_instance_url'], - ) - ->willReturnOnConsecutiveCalls( - $oldCreds['openproject_instance_url'], - $oldCreds['authorization_method'], - $oldCreds['openproject_client_id'], - $oldCreds['openproject_client_secret'], - '123', - '123', - '', - Application::AUTH_METHOD_OAUTH, - $credsToUpdate['openproject_client_id'], - $credsToUpdate['openproject_client_secret'], - $credsToUpdate['openproject_instance_url'] - ); + $this->expectMethodCalls($configMock, 'getAppValue', [ + [['integration_openproject', 'openproject_instance_url', ''], $oldCreds['openproject_instance_url']], + [['integration_openproject', 'authorization_method', ''], $oldCreds['authorization_method']], + [['integration_openproject', 'openproject_client_id', ''], $oldCreds['openproject_client_id']], + [['integration_openproject', 'openproject_client_secret', ''], $oldCreds['openproject_client_secret']], + [['integration_openproject', 'nc_oauth_client_id', ''], '123'], + [['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], '123'], + [['integration_openproject', 'authorization_method', ''], Application::AUTH_METHOD_OAUTH], + [['integration_openproject', 'openproject_client_id', ''], $credsToUpdate['openproject_client_id']], + [['integration_openproject', 'openproject_client_secret', ''], $credsToUpdate['openproject_client_secret']], + [['integration_openproject', 'openproject_instance_url', ''], $credsToUpdate['openproject_instance_url']], + ]); + $oauthSettingsControllerMock + ->expects($this->once()) + ->method('deleteClient') + ->with(123); $oauthSettingsControllerMock ->expects($this->once()) ->method('deleteClient') @@ -1666,20 +1612,20 @@ public function testSetAdminConfigForOAuth2AlreadyConfigured( $configMock ->expects($this->exactly(12)) ->method('deleteUserValue') - ->withConsecutive( - ['admin', 'integration_openproject', 'token'], - ['admin', 'integration_openproject', 'login'], - ['admin', 'integration_openproject', 'user_id'], - ['admin', 'integration_openproject', 'user_name'], - ['admin', 'integration_openproject', 'refresh_token'], - ['admin', 'integration_openproject', 'token_expires_at'], - [$this->user1->getUID(), 'integration_openproject', 'token'], - [$this->user1->getUID(), 'integration_openproject', 'login'], - [$this->user1->getUID(), 'integration_openproject', 'user_id'], - [$this->user1->getUID(), 'integration_openproject', 'user_name'], - [$this->user1->getUID(), 'integration_openproject', 'refresh_token'], - [$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], - ); + ->willReturnMap([ + ['admin', 'integration_openproject', 'token', null], + ['admin', 'integration_openproject', 'login', null], + ['admin', 'integration_openproject', 'user_id', null], + ['admin', 'integration_openproject', 'user_name', null], + ['admin', 'integration_openproject', 'refresh_token', null], + ['admin', 'integration_openproject', 'token_expires_at', null], + [$this->user1->getUID(), 'integration_openproject', 'token', null], + [$this->user1->getUID(), 'integration_openproject', 'login', null], + [$this->user1->getUID(), 'integration_openproject', 'user_id', null], + [$this->user1->getUID(), 'integration_openproject', 'user_name', null], + [$this->user1->getUID(), 'integration_openproject', 'refresh_token', null], + [$this->user1->getUID(), 'integration_openproject', 'token_expires_at', null], + ]); $apiService = $this->getMockBuilder(OpenProjectAPIService::class) ->disableOriginalConstructor() @@ -1754,47 +1700,91 @@ public function testSetAdminConfigForOIDCAlreadyConfigured( $oauthSettingsControllerMock = $this->getMockBuilder(SettingsController::class) ->disableOriginalConstructor() ->getMock(); - $configMock - ->method('getAppValue') - ->withConsecutive( - ['integration_openproject', 'openproject_instance_url', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'oidc_provider'], - ['integration_openproject', 'targeted_audience_client_id'], - ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], - ['integration_openproject', 'authorization_method', ''], - ['integration_openproject', 'oidc_provider'], - ['integration_openproject', 'targeted_audience_client_id'], - ['integration_openproject', 'openproject_instance_url'], - ) - ->willReturnOnConsecutiveCalls( - $oldConfig['openproject_instance_url'], - $oldConfig['authorization_method'], - $oldConfig['oidc_provider'], - $oldConfig['targeted_audience_client_id'], - '', - $newConfig['authorization_method'], - $newConfig['oidc_provider'], - $newConfig['targeted_audience_client_id'], - $newConfig['openproject_instance_url'] - ); - $configMock - ->expects($this->exactly(12)) - ->method('deleteUserValue') - ->withConsecutive( - ['admin', 'integration_openproject', 'token'], - ['admin', 'integration_openproject', 'login'], - ['admin', 'integration_openproject', 'user_id'], - ['admin', 'integration_openproject', 'user_name'], - ['admin', 'integration_openproject', 'refresh_token'], - ['admin', 'integration_openproject', 'token_expires_at'], - [$this->user1->getUID(), 'integration_openproject', 'token'], - [$this->user1->getUID(), 'integration_openproject', 'login'], - [$this->user1->getUID(), 'integration_openproject', 'user_id'], - [$this->user1->getUID(), 'integration_openproject', 'user_name'], - [$this->user1->getUID(), 'integration_openproject', 'refresh_token'], - [$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], - ); + // $configMock + // ->method('getAppValue') + // ->withConsecutive( + // ['integration_openproject', 'openproject_instance_url', ''], + // ['integration_openproject', 'authorization_method', ''], + // ['integration_openproject', 'oidc_provider'], + // ['integration_openproject', 'targeted_audience_client_id'], + // ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], + // ['integration_openproject', 'authorization_method', ''], + // ['integration_openproject', 'oidc_provider'], + // ['integration_openproject', 'targeted_audience_client_id'], + // ['integration_openproject', 'openproject_instance_url'], + // ) + // ->willReturnOnConsecutiveCalls( + // $oldConfig['openproject_instance_url'], + // $oldConfig['authorization_method'], + // $oldConfig['oidc_provider'], + // $oldConfig['targeted_audience_client_id'], + // '', + // $newConfig['authorization_method'], + // $newConfig['oidc_provider'], + // $newConfig['targeted_audience_client_id'], + // $newConfig['openproject_instance_url'] + // ); + $this->expectMethodCalls($configMock, 'getAppValue', [ + [['integration_openproject', 'openproject_instance_url', ''], $oldConfig['openproject_instance_url']], + [['integration_openproject', 'authorization_method', ''], $oldConfig['authorization_method']], + [['integration_openproject', 'oidc_provider', ''], $oldConfig['oidc_provider']], + [['integration_openproject', 'targeted_audience_client_id', ''], $oldConfig['targeted_audience_client_id']], + [['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], ''], + [['integration_openproject', 'authorization_method', ''], $newConfig['authorization_method']], + [['integration_openproject', 'oidc_provider', ''], $newConfig['oidc_provider']], + [['integration_openproject', 'targeted_audience_client_id', ''], $newConfig['targeted_audience_client_id']], + [['integration_openproject', 'openproject_instance_url', ''], $newConfig['openproject_instance_url']], + ]); + // $configMock + // ->expects($this->exactly(12)) + // ->method('deleteUserValue') + // ->withConsecutive( + // ['admin', 'integration_openproject', 'token'], + // ['admin', 'integration_openproject', 'login'], + // ['admin', 'integration_openproject', 'user_id'], + // ['admin', 'integration_openproject', 'user_name'], + // ['admin', 'integration_openproject', 'refresh_token'], + // ['admin', 'integration_openproject', 'token_expires_at'], + // [$this->user1->getUID(), 'integration_openproject', 'token'], + // [$this->user1->getUID(), 'integration_openproject', 'login'], + // [$this->user1->getUID(), 'integration_openproject', 'user_id'], + // [$this->user1->getUID(), 'integration_openproject', 'user_name'], + // [$this->user1->getUID(), 'integration_openproject', 'refresh_token'], + // [$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], + // ); + + // $configMock + // ->expects($this->exactly(12)) + // ->method('deleteUserValue') + // ->willReturnMap([ + // ['admin', 'integration_openproject', 'token', null], + // ['admin', 'integration_openproject', 'login', null], + // ['admin', 'integration_openproject', 'user_id', null], + // ['admin', 'integration_openproject', 'user_name', null], + // ['admin', 'integration_openproject', 'refresh_token', null], + // ['admin', 'integration_openproject', 'token_expires_at', null], + // [$this->user1->getUID(), 'integration_openproject', 'token', null], + // [$this->user1->getUID(), 'integration_openproject', 'login', null], + // [$this->user1->getUID(), 'integration_openproject', 'user_id', null], + // [$this->user1->getUID(), 'integration_openproject', 'user_name', null], + // [$this->user1->getUID(), 'integration_openproject', 'refresh_token', null], + // [$this->user1->getUID(), 'integration_openproject', 'token_expires_at', null], + // ]); + + $this->expectMethodCalls($configMock, 'deleteUserValue', [ + [['admin', 'integration_openproject', 'token'], null], + [['admin', 'integration_openproject', 'login'], null], + [['admin', 'integration_openproject', 'user_id'], null], + [['admin', 'integration_openproject', 'user_name'], null], + [['admin', 'integration_openproject', 'refresh_token'], null], + [['admin', 'integration_openproject', 'token_expires_at'], null], + [[$this->user1->getUID(), 'integration_openproject', 'token'], null], + [[$this->user1->getUID(), 'integration_openproject', 'login'], null], + [[$this->user1->getUID(), 'integration_openproject', 'user_id'], null], + [[$this->user1->getUID(), 'integration_openproject', 'user_name'], null], + [[$this->user1->getUID(), 'integration_openproject', 'refresh_token'], null], + [[$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], null], + ], true); $apiService = $this->getMockBuilder(OpenProjectAPIService::class) ->disableOriginalConstructor() diff --git a/tests/lib/Controller/OpenProjectControllerTest.php b/tests/lib/Controller/OpenProjectControllerTest.php index d77e2f582..89708baa5 100644 --- a/tests/lib/Controller/OpenProjectControllerTest.php +++ b/tests/lib/Controller/OpenProjectControllerTest.php @@ -295,20 +295,10 @@ public function testGetOpenProjectOauthURLWithStateAndPKCE(): void { $configMock ->expects($this->exactly(2)) ->method('setUserValue') - ->withConsecutive( - [ - 'test', - 'integration_openproject', - 'oauth_state', - $this->matchesRegularExpression('/[a-z0-9]{10}/') - ], - [ - 'test', - 'integration_openproject', - 'code_verifier', - $this->matchesRegularExpression('/[A-Za-z0-9\-._~]{128}/') - ], - ); + ->willReturnMap([ + ['test', 'integration_openproject', 'oauth_state', $this->matchesRegularExpression('/[a-z0-9]{10}/'), null, null], + ['test', 'integration_openproject', 'code_verifier', $this->matchesRegularExpression('/[A-Za-z0-9\-._~]{128}/'), null, null], + ]); $controller = $this->getOpenProjectControllerMock([ 'openProjectAPIService' => $service, diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index 595e9f236..00f2a8dbd 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -2543,9 +2543,10 @@ public function testIsSystemReadyForProjectFolderSetUp(): void { $userManagerMock = $this->getMockBuilder(IUserManager::class) ->getMock(); $userManagerMock + ->expects($this->exactly(2)) ->method('userExists') - ->withConsecutive([Application::OPEN_PROJECT_ENTITIES_NAME], [Application::OPEN_PROJECT_ENTITIES_NAME]) - ->willReturnOnConsecutiveCalls(false, false); + ->with(Application::OPEN_PROJECT_ENTITIES_NAME) + ->willReturn(false); $userManagerMock ->method('get') ->with(Application::OPEN_PROJECT_ENTITIES_NAME) @@ -2554,9 +2555,10 @@ public function testIsSystemReadyForProjectFolderSetUp(): void { $groupManagerMock = $this->getMockBuilder(IGroupManager::class) ->getMock(); $groupManagerMock + ->expects($this->exactly(1)) ->method('groupExists') - ->withConsecutive([Application::OPEN_PROJECT_ENTITIES_NAME], [Application::OPEN_PROJECT_ENTITIES_NAME]) - ->willReturnOnConsecutiveCalls(false, false); + ->with(Application::OPEN_PROJECT_ENTITIES_NAME) + ->willReturn(false); $appManagerMock = $this->getMockBuilder(IAppManager::class) ->getMock(); $appManagerMock @@ -2564,21 +2566,15 @@ public function testIsSystemReadyForProjectFolderSetUp(): void { ->with('groupfolders', $userMock) ->willReturn(true); $service = $this->getOpenProjectAPIServiceMock( - ['getGroupFolderManager'], + ['isOpenProjectGroupfolderCreated'], [ 'userManager' => $userManagerMock, 'groupManager' => $groupManagerMock, 'appManager' => $appManagerMock, ], ); - $folderManagerMock = $this->getFolderManagerMock('', false, [ 0 => [ - 'folder_id' => 123, - 'mount_point' => '', - 'permissions' => 31, - 'acl' => true - ]]); - $service->method('getGroupFolderManager') - ->willReturn($folderManagerMock); + $service->method('isOpenProjectGroupfolderCreated') + ->willReturn(false); $result = $service->isSystemReadyForProjectFolderSetUp(); $this->assertTrue($result); } @@ -2823,7 +2819,12 @@ public function testProjectFolderDeleteAppPassword(): void { $service->method('hasAppPassword')->willReturn(true); $tokenProviderMock->expects($this->exactly(2)) ->method('invalidateTokenById') - ->withConsecutive([Application::OPEN_PROJECT_ENTITIES_NAME, 4], [Application::OPEN_PROJECT_ENTITIES_NAME, 5]); + ->willReturnMap( + [ + [Application::OPEN_PROJECT_ENTITIES_NAME, 4, null], + [Application::OPEN_PROJECT_ENTITIES_NAME, 5, null], + ] + ); $service->deleteAppPassword(); } From 9b9801010d1cb584b91c823d077e7bf9b41f67fa Mon Sep 17 00:00:00 2001 From: nabim777 Date: Mon, 6 Jul 2026 09:50:41 +0545 Subject: [PATCH 4/5] fix the psalm error Signed-off-by: nabim777 --- tests/lib/Controller/ConfigControllerTest.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index 2b13da308..9de293e47 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -47,7 +47,7 @@ protected function tearDown(): void { /** * @param MockObject $mock The mock object on which the method is expected to be called * @param string $method The method name for which the expectations are set - * @param array $calls An array of expected argument arrays for each call + * @param list{list, mixed}[] $calls An array of expected argument arrays for each call */ private function expectMethodCalls( $mock, @@ -901,14 +901,6 @@ public function testSetAdminConfigNotAllowedConfigValues() { public function checkForUsersCountBeforeTest($expectedCount = 1): IUserManager { $userManager = \OC::$server->getUserManager(); - // Keep tests isolated by removing users created by previous runs. - $userManager->callForAllUsers(function (IUser $user) { - if ($user->getUID() !== 'admin') { - $user->delete(); - } - return null; - }); - $actualCount = 0; $function = function () use (&$actualCount) { $actualCount++; @@ -1171,7 +1163,10 @@ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage $loggerInterfaceMock ->method("error") - ->willReturn($errMessage); + ->with( + $errMessage[0], + $errMessage[1] + ); $apiService ->expects($this->exactly(1)) @@ -1511,7 +1506,7 @@ public function testSetAdminConfigOIDCAuthSetting( ['integration_openproject', 'targeted_audience_client_id', '', $oldCreds['targeted_audience_client_id']], ['integration_openproject', 'nc_oauth_client_id', '', '123'], ['integration_openproject', 'oPOAuthTokenRevokeStatus', '', ''], - ['integration_openproject', 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OIDC], + ['integration_openproject', 'authorization_method', '', Application::AUTH_METHOD_OIDC], ['integration_openproject', 'oidc_provider', '', $credsToUpdate['oidc_provider']], ['integration_openproject', 'targeted_audience_client_id', '', $credsToUpdate['targeted_audience_client_id']], ['integration_openproject', 'openproject_instance_url', '', $credsToUpdate['openproject_instance_url']], From dffb48712637ac79785520359f310f038cceb320 Mon Sep 17 00:00:00 2001 From: nabim777 Date: Mon, 6 Jul 2026 14:49:02 +0545 Subject: [PATCH 5/5] cleanup comments Signed-off-by: nabim777 --- tests/lib/Controller/ConfigControllerTest.php | 80 +------------------ 1 file changed, 2 insertions(+), 78 deletions(-) diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index 9de293e47..339dcf02d 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -47,7 +47,7 @@ protected function tearDown(): void { /** * @param MockObject $mock The mock object on which the method is expected to be called * @param string $method The method name for which the expectations are set - * @param list{list, mixed}[] $calls An array of expected argument arrays for each call + * @param list, mixed}> $calls An array of [expected args, return value] tuples for each call */ private function expectMethodCalls( $mock, @@ -64,7 +64,6 @@ private function expectMethodCalls( ->expects($expectedCallsCount) ->method($method) ->willReturnCallback(function (...$args) use (&$calls) { - // if not $returnValue = array_pop($calls); [$expectedArgs, $returnValue] = array_shift($calls); $this->assertSame($expectedArgs, $args); return $returnValue; @@ -90,12 +89,6 @@ private function getConfigMock( [['integration_openproject', 'openproject_client_secret', ''], 'clientSecret'], ]); - // $this->expectMethodCalls($configMock, 'getUserValue', [ - // [['testUser', 'integration_openproject', 'oauth_state', ''], 'randomString'], - // [['testUser', 'integration_openproject', 'code_verifier', false], $codeVerifier], - // [['testUser', 'integration_openproject', 'oauth_journey_starting_page', ''], $startingPage], - // [['testUser', 'integration_openproject', 'refresh_token', false], 'oAuthRefreshToken'], - // ]); $configMock ->method('getUserValue') ->willReturnMap([ @@ -1247,17 +1240,6 @@ public function testOPOAuthTokenRevokeDoesNotOccurIfNoOPOAuthClientHasChanged() [Application::APP_ID, 'openproject_client_secret', '', $oldAdminConfig['openproject_client_secret']], [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], ]); - // $configMock - // ->expects($this->exactly(2)) - // ->method('deleteAppValue') - // ->withConsecutive( - // ['integration_openproject', 'oPOAuthTokenRevokeStatus'], - // ['integration_openproject', 'oPOAuthTokenRevokeStatus'] - // ); - // $this->expectMethodCalls($configMock, 'deleteAppValue', [ - // [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], - // [[Application::APP_ID, 'oPOAuthTokenRevokeStatus'], null], - // ], true); $configMock ->expects($this->exactly(2)) @@ -1695,30 +1677,7 @@ public function testSetAdminConfigForOIDCAlreadyConfigured( $oauthSettingsControllerMock = $this->getMockBuilder(SettingsController::class) ->disableOriginalConstructor() ->getMock(); - // $configMock - // ->method('getAppValue') - // ->withConsecutive( - // ['integration_openproject', 'openproject_instance_url', ''], - // ['integration_openproject', 'authorization_method', ''], - // ['integration_openproject', 'oidc_provider'], - // ['integration_openproject', 'targeted_audience_client_id'], - // ['integration_openproject', 'oPOAuthTokenRevokeStatus', ''], - // ['integration_openproject', 'authorization_method', ''], - // ['integration_openproject', 'oidc_provider'], - // ['integration_openproject', 'targeted_audience_client_id'], - // ['integration_openproject', 'openproject_instance_url'], - // ) - // ->willReturnOnConsecutiveCalls( - // $oldConfig['openproject_instance_url'], - // $oldConfig['authorization_method'], - // $oldConfig['oidc_provider'], - // $oldConfig['targeted_audience_client_id'], - // '', - // $newConfig['authorization_method'], - // $newConfig['oidc_provider'], - // $newConfig['targeted_audience_client_id'], - // $newConfig['openproject_instance_url'] - // ); + $this->expectMethodCalls($configMock, 'getAppValue', [ [['integration_openproject', 'openproject_instance_url', ''], $oldConfig['openproject_instance_url']], [['integration_openproject', 'authorization_method', ''], $oldConfig['authorization_method']], @@ -1730,41 +1689,6 @@ public function testSetAdminConfigForOIDCAlreadyConfigured( [['integration_openproject', 'targeted_audience_client_id', ''], $newConfig['targeted_audience_client_id']], [['integration_openproject', 'openproject_instance_url', ''], $newConfig['openproject_instance_url']], ]); - // $configMock - // ->expects($this->exactly(12)) - // ->method('deleteUserValue') - // ->withConsecutive( - // ['admin', 'integration_openproject', 'token'], - // ['admin', 'integration_openproject', 'login'], - // ['admin', 'integration_openproject', 'user_id'], - // ['admin', 'integration_openproject', 'user_name'], - // ['admin', 'integration_openproject', 'refresh_token'], - // ['admin', 'integration_openproject', 'token_expires_at'], - // [$this->user1->getUID(), 'integration_openproject', 'token'], - // [$this->user1->getUID(), 'integration_openproject', 'login'], - // [$this->user1->getUID(), 'integration_openproject', 'user_id'], - // [$this->user1->getUID(), 'integration_openproject', 'user_name'], - // [$this->user1->getUID(), 'integration_openproject', 'refresh_token'], - // [$this->user1->getUID(), 'integration_openproject', 'token_expires_at'], - // ); - - // $configMock - // ->expects($this->exactly(12)) - // ->method('deleteUserValue') - // ->willReturnMap([ - // ['admin', 'integration_openproject', 'token', null], - // ['admin', 'integration_openproject', 'login', null], - // ['admin', 'integration_openproject', 'user_id', null], - // ['admin', 'integration_openproject', 'user_name', null], - // ['admin', 'integration_openproject', 'refresh_token', null], - // ['admin', 'integration_openproject', 'token_expires_at', null], - // [$this->user1->getUID(), 'integration_openproject', 'token', null], - // [$this->user1->getUID(), 'integration_openproject', 'login', null], - // [$this->user1->getUID(), 'integration_openproject', 'user_id', null], - // [$this->user1->getUID(), 'integration_openproject', 'user_name', null], - // [$this->user1->getUID(), 'integration_openproject', 'refresh_token', null], - // [$this->user1->getUID(), 'integration_openproject', 'token_expires_at', null], - // ]); $this->expectMethodCalls($configMock, 'deleteUserValue', [ [['admin', 'integration_openproject', 'token'], null],