Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typecast error for User ID #391

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
vendor/bin/phpunit --testsuite integration_tests_scope_workflows
test-integration-scope-user:
vendor/bin/phpunit --testsuite integration_tests_scope_user
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
paths:
- src/
- tests/Integration/Services/Telephony
- tests/Integration/Services/User
bootstrapFiles:
- tests/bootstrap.php
parallel:
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<testsuite name="integration_tests_scope_telephony">
<directory>./tests/Integration/Services/Telephony/</directory>
</testsuite>
<testsuite name="integration_tests_scope_user">
<directory>./tests/Integration/Services/User/</directory>
</testsuite>
<testsuite name="integration_tests_scope_workflows">
<directory>./tests/Integration/Services/Workflows/</directory>
</testsuite>
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions src/Services/User/Result/UserItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,21 +16,21 @@
* @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
* @property-read array $TIMESTAMP_X
* @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
Expand All @@ -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';
Expand Down
14 changes: 1 addition & 13 deletions src/Services/User/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -44,16 +42,14 @@ 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
*/
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(
Expand All @@ -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
*/
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/Services/User/UserServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

class UserServiceBuilder extends AbstractServiceBuilder
{
/**
* get user service
*
* @return User
*/
public function user(): User
{
if (!isset($this->serviceCache[__METHOD__])) {
Expand Down
40 changes: 19 additions & 21 deletions tests/Integration/Services/User/Service/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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 = [
Expand All @@ -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 = [
Expand All @@ -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();
}
Expand Down
Loading