Skip to content

Commit

Permalink
Add default arguments handling in User.get method
Browse files Browse the repository at this point in the history
A check has been added in User.get method, to set a default argument as ascending order of IDs when no explicit order is provided. A corresponding test case 'test get users list with default arguments' has also been included to validate the functionality. The CHAGELOG.md is updated to reflect this fix.

Signed-off-by: mesilov <mesilov.maxim@gmail.com>
  • Loading branch information
mesilov committed Jun 29, 2024
1 parent ca7afda commit 5f37207
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
### Bugfix

* fix [typehint for Bitrix24 User entity with field ID](https://github.com/mesilov/bitrix24-php-sdk/issues/382)
* fix [default arguments for Bitrix24 User get method](https://github.com/mesilov/bitrix24-php-sdk/issues/381)

## 2.0-beta.2 — 1.04.2024

Expand Down
4 changes: 4 additions & 0 deletions src/Services/User/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function add(array $fields, string $messageText = ''): AddedItemResult
*/
public function get(array $order, array $filter, bool $isAdminMode = false): UsersResult
{
if ($order === []) {
$order = ['ID' => 'ASC'];
}

return new UsersResult($this->core->call('user.get', [
'sort' => array_keys($order)[0],
'order' => array_values($order)[0],
Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/Services/User/Service/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function testGetWithInternalPhone(): void
);
}

#[TestDox('test get users list with default arguments')]
public function testGetWithDefaultArguments(): void
{
$this->assertGreaterThanOrEqual(1, $this->userService->get([], [], true)->getCoreResponse()->getResponseData()->getPagination()->getTotal());
}

/**
* @throws BaseException
* @throws TransportException
Expand Down

0 comments on commit 5f37207

Please sign in to comment.