Skip to content

Commit

Permalink
feat: Add multiple users deletion (#25)
Browse files Browse the repository at this point in the history
* Add multiple users deletion

* Update LoghyInterface.php

* Update phpstan-baseline.neon
  • Loading branch information
mkohei authored Sep 16, 2022
1 parent 614302f commit 21f4afb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Method Loghy\\\\SDK\\\\Contract\\\\LoghyInterface\\:\\:deleteUser\\(\\) has parameter \\$loghyId with no value type specified in iterable type array\\.$#"
count: 1
path: src/Contract/LoghyInterface.php

-
message: "#^Method Loghy\\\\SDK\\\\Exception\\\\InvalidResponseBodyStructureException\\:\\:__construct\\(\\) has parameter \\$response with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -10,6 +15,11 @@ parameters:
count: 1
path: src/Exception/InvalidResponseBodyStructureException.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:deleteUser\\(\\) has parameter \\$loghyId with no value type specified in iterable type array\\.$#"
count: 1
path: src/Loghy.php

-
message: "#^Method Loghy\\\\SDK\\\\Loghy\\:\\:getResponseJson\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/LoghyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function putUserId(string $userId, string $loghyId = null): bool;
/**
* Delete user (Loghy ID).
*
* @param string|null $loghyId
* @param string|array|null $loghyId
* @return bool
*/
public function deleteUser(string $loghyId = null): bool;
public function deleteUser(string|array $loghyId = null): bool;
}
6 changes: 2 additions & 4 deletions src/Loghy.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function putUserId(string $userId, ?string $loghyId = null): bool
* @throws \Loghy\SDK\Exception\LoghyException
* @throws \Loghy\SDK\Exception\UnsetLoghyIdException
*/
public function deleteUser(?string $loghyId = null): bool
public function deleteUser(string|array $loghyId = null): bool
{
$loghyId ??= $this->user?->getLoghyId() ?? throw new UnsetLoghyIdException(
'Loghy ID has not been set. ' .
Expand All @@ -358,9 +358,7 @@ public function deleteUser(?string $loghyId = null): bool
'Authorization' => 'Bearer ' . $this->getSiteAccessToken()
],
json: [
'loghy_ids' => [
$loghyId,
],
'loghy_ids' => (array)$loghyId,
],
);
return $response['message'] === 'ok';
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Loghy/DeleteUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
->toBe(true);
})->with('response.manage.user.bulk.delete.ok');

test('deleteUser() can delete multiple users', function (array $json) {
$loghy = new \Loghy\SDK\Loghy('__site_code__');

$httpClient = makeMockHttpClient(
makeJsonResponse($json, 200)
);
$loghy->setHttpClient($httpClient)
->setSiteAccessToken('__site_access_token__');

expect($loghy->deleteUser(['__loghy_id_1__', '__loghy_id_2__']))
->toBe(true);
})->with('response.manage.user.bulk.delete.ok');

test('deleteUser() throws exception when some error occurs', function (int $status, array $json) {
$loghy = new \Loghy\SDK\Loghy('__site_code__');

Expand Down

0 comments on commit 21f4afb

Please sign in to comment.