Skip to content

Commit

Permalink
test: validate construct parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Saw-jan <[email protected]>
  • Loading branch information
saw-jan committed Jan 30, 2025
1 parent 85ebeab commit 56275c5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,13 @@ private function getStorageMock($nodeClassName = null) {
}

/**
* @param array<string, object> $constructParams
* generates a list mocks that can be given as arguments to the constructor of OpenProjectAPIService
* by default only empty mocks are generated, but specific mocks can be passed in using the
* $constructParams parameter.
*
* Format has to be [<string> => <object>] with the first being the constructor parameter name and the second one the mock.
* Example: ['avatarManager' => $createMockObject]
* @param array<string, object> $constructParams specific mocks for the constructor of OpenProjectAPIService
*
* @return array
*/
Expand Down Expand Up @@ -658,8 +664,12 @@ private function getOpenProjectAPIServiceConstructArgs(array $constructParams =
'exchangedTokenRequestedEventHelper' => $this->createMock(ExchangedTokenRequestedEventHelper::class),
];

// replace the mock
// replace default mocks with manually passed in mocks
foreach ($constructParams as $key => $value) {
if (!array_key_exists($key, $constructArgs)) {
throw new \InvalidArgumentException("Invalid construct parameter: $key");
}

$constructArgs[$key] = $value;
}

Expand Down

0 comments on commit 56275c5

Please sign in to comment.