diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d764824..b6115ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -124,7 +124,10 @@ * remove interface `Bitrix24\SDK\Services\Telephony\Common\StatusSipCodeInterface` * remove class `Bitrix24\SDK\Services\Telephony\Common\StatusSipRegistrations` * remove class `Bitrix24\SDK\Services\Telephony\Common\TypeAtc` - + +### Bugfix + +* fix [typehint for Bitrix24 User entity with field ID](https://github.com/mesilov/bitrix24-php-sdk/issues/382) ## 2.0-beta.2 — 1.04.2024 diff --git a/Makefile b/Makefile index 480db6f4..5c55b787 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,6 @@ test-unit: test-integration-scope-telephony: vendor/bin/phpunit --testsuite integration_tests_scope_telephony test-integration-scope-workflows: - vendor/bin/phpunit --testsuite integration_tests_scope_workflows \ No newline at end of file + vendor/bin/phpunit --testsuite integration_tests_scope_workflows +test-integration-scope-user: + vendor/bin/phpunit --testsuite integration_tests_scope_user \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 06170dda..6a8ea16d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,6 +3,7 @@ parameters: paths: - src/ - tests/Integration/Services/Telephony + - tests/Integration/Services/User bootstrapFiles: - tests/bootstrap.php parallel: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3555dd5e..d16b93db 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,6 +13,9 @@ ./tests/Integration/Services/Telephony/ + + ./tests/Integration/Services/User/ + ./tests/Integration/Services/Workflows/ diff --git a/rector.php b/rector.php index 85ed9bf9..d4d262d1 100644 --- a/rector.php +++ b/rector.php @@ -11,6 +11,8 @@ ->withPaths([ __DIR__ . '/src/Services/Telephony', __DIR__ . '/tests/Integration/Services/Telephony', + __DIR__ . '/src/Services/User', + __DIR__ . '/tests/Integration/Services/User', ]) ->withCache(cacheDirectory: __DIR__ . '.cache/rector') ->withSets( diff --git a/src/Services/User/Result/UserItemResult.php b/src/Services/User/Result/UserItemResult.php index e8ad00e0..de8b597e 100644 --- a/src/Services/User/Result/UserItemResult.php +++ b/src/Services/User/Result/UserItemResult.php @@ -5,8 +5,7 @@ namespace Bitrix24\SDK\Services\User\Result; use Bitrix24\SDK\Core\Result\AbstractItem; -use DateTime; -use DateTimeImmutable; +use Carbon\CarbonImmutable; /** * @property-read int $ID @@ -17,8 +16,8 @@ * @property-read string $SECOND_NAME * @property-read string $TITLE * @property-read string $EMAIL - * @property-read DateTime $LAST_LOGIN - * @property-read DateTime $DATE_REGISTER + * @property-read CarbonImmutable $LAST_LOGIN + * @property-read CarbonImmutable $DATE_REGISTER * @property-read string $TIME_ZONE * @property-read bool $IS_ONLINE * @property-read int $TIME_ZONE_OFFSET @@ -26,12 +25,12 @@ * @property-read array $LAST_ACTIVITY_DATE * @property-read string $PERSONAL_GENDER * @property-read string $PERSONAL_WWW - * @property-read DateTimeImmutable $PERSONAL_BIRTHDAY + * @property-read CarbonImmutable $PERSONAL_BIRTHDAY * @property-read string $PERSONAL_PHOTO * @property-read string $PERSONAL_MOBILE * @property-read string $PERSONAL_CITY * @property-read string $WORK_PHONE - * @property-read DateTimeImmutable $UF_EMPLOYMENT_DATE + * @property-read CarbonImmutable $UF_EMPLOYMENT_DATE * @property-read string $UF_TIMEMAN * @property-read array $UF_DEPARTMENT * @property-read string $UF_PHONE_INNER @@ -42,14 +41,17 @@ class UserItemResult extends AbstractItem public function __get($offset) { switch ($offset) { + case 'ID': case 'TIME_ZONE_OFFSET': return (int)$this->data[$offset]; case 'LAST_LOGIN': case 'DATE_REGISTER': case 'UF_EMPLOYMENT_DATE': + case 'PERSONAL_BIRTHDAY': if ($this->data[$offset] !== '') { - return DateTimeImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]); + return CarbonImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]); } + break; case 'IS_ONLINE': return $this->data[$offset] === 'Y'; diff --git a/src/Services/User/Service/User.php b/src/Services/User/Service/User.php index 80228317..04456e9d 100644 --- a/src/Services/User/Service/User.php +++ b/src/Services/User/Service/User.php @@ -18,7 +18,6 @@ class User extends AbstractService { /** * Get user entity fields - * @return FieldsResult * @throws BaseException * @throws TransportException * @link https://training.bitrix24.com/rest_help/users/user_fields.php @@ -30,7 +29,6 @@ public function fields(): FieldsResult /** * Get current user - * @return UserResult * @throws BaseException * @throws TransportException * @link https://training.bitrix24.com/rest_help/users/user_current.php @@ -44,8 +42,6 @@ public function current(): UserResult * Invites a user. Available only for users with invitation permissions, usually an administrator. Sends a standard account invitation to the user on success. * * @param array $fields = ['ID','XML_ID','ACTIVE','NAME','LAST_NAME','SECOND_NAME','TITLE','EMAIL','PERSONAL_PHONE','WORK_PHONE','WORK_POSITION','WORK_COMPANY','IS_ONLINE','TIME_ZONE','TIMESTAMP_X','TIME_ZONE_OFFSET','DATE_REGISTER','LAST_ACTIVITY_DATE','PERSONAL_PROFESSION','PERSONAL_GENDER','PERSONAL_BIRTHDAY','PERSONAL_PHOTO','PERSONAL_FAX','PERSONAL_MOBILE','PERSONAL_PAGER','PERSONAL_STREET','PERSONAL_MAILBOX','PERSONAL_CITY','PERSONAL_STATE','PERSONAL_ZIP','PERSONAL_COUNTRY','PERSONAL_NOTES','WORK_DEPARTMENT','WORK_WWW','WORK_FAX','WORK_PAGER','WORK_STREET','WORK_MAILBOX','WORK_CITY','WORK_STATE','WORK_ZIP','WORK_COUNTRY','WORK_PROFILE','WORK_LOGO','WORK_NOTES','UF_DEPARTMENT','UF_DISTRICT','UF_SKYPE','UF_SKYPE_LINK','UF_ZOOM','UF_TWITTER','UF_FACEBOOK','UF_LINKEDIN','UF_XING','UF_WEB_SITES','UF_PHONE_INNER','UF_EMPLOYMENT_DATE','UF_TIMEMAN','UF_SKILLS','UF_INTERESTS','USER_TYPE'] - * @param string $messageText - * @return AddedItemResult * @throws BaseException * @throws TransportException * @link https://training.bitrix24.com/rest_help/users/user_add.php @@ -53,7 +49,7 @@ public function current(): UserResult public function add(array $fields, string $messageText = ''): AddedItemResult { if (!array_key_exists('EXTRANET', $fields)) { - throw new InvalidArgumentException(sprintf('field EXTRANET is required')); + throw new InvalidArgumentException('field EXTRANET is required'); } return new AddedItemResult($this->core->call( @@ -68,10 +64,7 @@ public function add(array $fields, string $messageText = ''): AddedItemResult } /** - * @param array $order * @param array $filter = ['ID','XML_ID','ACTIVE','NAME','LAST_NAME','SECOND_NAME','TITLE','EMAIL','PERSONAL_PHONE','WORK_PHONE','WORK_POSITION','WORK_COMPANY','IS_ONLINE','TIME_ZONE','TIMESTAMP_X','TIME_ZONE_OFFSET','DATE_REGISTER','LAST_ACTIVITY_DATE','PERSONAL_PROFESSION','PERSONAL_GENDER','PERSONAL_BIRTHDAY','PERSONAL_PHOTO','PERSONAL_FAX','PERSONAL_MOBILE','PERSONAL_PAGER','PERSONAL_STREET','PERSONAL_MAILBOX','PERSONAL_CITY','PERSONAL_STATE','PERSONAL_ZIP','PERSONAL_COUNTRY','PERSONAL_NOTES','WORK_DEPARTMENT','WORK_WWW','WORK_FAX','WORK_PAGER','WORK_STREET','WORK_MAILBOX','WORK_CITY','WORK_STATE','WORK_ZIP','WORK_COUNTRY','WORK_PROFILE','WORK_LOGO','WORK_NOTES','UF_DEPARTMENT','UF_DISTRICT','UF_SKYPE','UF_SKYPE_LINK','UF_ZOOM','UF_TWITTER','UF_FACEBOOK','UF_LINKEDIN','UF_XING','UF_WEB_SITES','UF_PHONE_INNER','UF_EMPLOYMENT_DATE','UF_TIMEMAN','UF_SKILLS','UF_INTERESTS','USER_TYPE'] - * @param bool $isAdminMode - * @return UsersResult * @throws BaseException * @throws TransportException */ @@ -87,9 +80,6 @@ public function get(array $order, array $filter, bool $isAdminMode = false): Use /** * Updates user information. Available only for users with invitation permissions. - * @param int $userId - * @param array $fields - * @return UpdatedItemResult * @throws BaseException * @throws TransportException * @link https://training.bitrix24.com/rest_help/users/user_update.php @@ -107,8 +97,6 @@ public function update(int $userId, array $fields): UpdatedItemResult /** * This method is used to retrieve list of users with expedited personal data search (name, last name, middle name, name of department, position). Works in two modes: Quick mode, via Fulltext Index and slower mode via right LIKE (support is determined automatically). * - * @param array $filterFields - * @return UsersResult * @throws BaseException * @throws TransportException * @link https://training.bitrix24.com/rest_help/users/user_search.php diff --git a/src/Services/User/UserServiceBuilder.php b/src/Services/User/UserServiceBuilder.php index d6977687..7b69235d 100644 --- a/src/Services/User/UserServiceBuilder.php +++ b/src/Services/User/UserServiceBuilder.php @@ -9,11 +9,6 @@ class UserServiceBuilder extends AbstractServiceBuilder { - /** - * get user service - * - * @return User - */ public function user(): User { if (!isset($this->serviceCache[__METHOD__])) { diff --git a/tests/Integration/Services/User/Service/UserTest.php b/tests/Integration/Services/User/Service/UserTest.php index e8f0ab26..d8120fb9 100644 --- a/tests/Integration/Services/User/Service/UserTest.php +++ b/tests/Integration/Services/User/Service/UserTest.php @@ -11,34 +11,33 @@ use Bitrix24\SDK\Services\UserConsent\Service\UserConsent; use Bitrix24\SDK\Services\UserConsent\Service\UserConsentAgreement; use Bitrix24\SDK\Tests\Integration\Fabric; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; +#[CoversClass(User::class)] class UserTest extends TestCase { private User $userService; /** - * @return void * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\User\Service\User::get - * @testdox test get users with filter */ + #[TestDox('test get users with filter')] public function testUserSearch(): void { - $users = $this->userService->search([ + $usersResult = $this->userService->search([ 'NAME' => 'test', ]); - $this->assertGreaterThanOrEqual(1, $users->getCoreResponse()->getResponseData()->getPagination()->getTotal()); + $this->assertGreaterThanOrEqual(1, $usersResult->getCoreResponse()->getResponseData()->getPagination()->getTotal()); } /** - * @return void * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\User\Service\User::get - * @testdox test get users list with internal phone */ + #[TestDox('test get users list with internal phone')] public function testGetWithInternalPhone(): void { $this->assertGreaterThanOrEqual( @@ -50,12 +49,10 @@ public function testGetWithInternalPhone(): void } /** - * @covers \Bitrix24\SDK\Services\User\Service\User::get - * @testdox test get users list - * @return void * @throws BaseException * @throws TransportException */ + #[TestDox('test get users list')] public function testGet(): void { $this->assertGreaterThanOrEqual( @@ -64,6 +61,13 @@ public function testGet(): void ); } + #[TestDox('test user typehints')] + public function testGetByIdTypehints(): void + { + $user = $this->userService->get(['ID' => 'ASC'], [], true)->getUsers()[0]; + $this->assertIsInt($user->ID); + } + public function testUpdate(): void { $newUser = [ @@ -83,12 +87,10 @@ public function testUpdate(): void } /** - * @covers \Bitrix24\SDK\Services\User\Service\User::add - * @testdox test add user - * @return void * @throws BaseException * @throws TransportException */ + #[TestDox('test add user')] public function testAdd(): void { $newUser = [ @@ -102,30 +104,26 @@ public function testAdd(): void } /** - * @covers \Bitrix24\SDK\Services\User\Service\User::current - * @testdox test get current user - * @return void * @throws BaseException * @throws TransportException */ + #[TestDox('test get current user')] public function testUserCurrent(): void { $this->assertInstanceOf(UserItemResult::class, $this->userService->current()->user()); } /** - * @covers \Bitrix24\SDK\Services\User\Service\User::fields - * @testdox test get user fields - * @return void * @throws BaseException * @throws TransportException */ + #[TestDox('test get user fields')] public function testGetUserFields(): void { $this->assertIsArray($this->userService->fields()->getFieldsDescription()); } - public function setUp(): void + protected function setUp(): void { $this->userService = Fabric::getServiceBuilder()->getUserScope()->user(); }