From 5f37207609b278f4c52b27ae2c3023a97be774e9 Mon Sep 17 00:00:00 2001 From: mesilov Date: Sun, 30 Jun 2024 00:48:55 +0600 Subject: [PATCH] Add default arguments handling in User.get method 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 --- CHANGELOG.md | 1 + src/Services/User/Service/User.php | 4 ++++ tests/Integration/Services/User/Service/UserTest.php | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6115ddc..14fd95e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Services/User/Service/User.php b/src/Services/User/Service/User.php index 04456e9d..1590a7db 100644 --- a/src/Services/User/Service/User.php +++ b/src/Services/User/Service/User.php @@ -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], diff --git a/tests/Integration/Services/User/Service/UserTest.php b/tests/Integration/Services/User/Service/UserTest.php index d8120fb9..8e9931fe 100644 --- a/tests/Integration/Services/User/Service/UserTest.php +++ b/tests/Integration/Services/User/Service/UserTest.php @@ -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