From 539a8360c8daab021563923304d39d82ba2c13ba Mon Sep 17 00:00:00 2001 From: mesilov Date: Fri, 22 Nov 2024 01:39:23 +0600 Subject: [PATCH 1/2] Fix errors in typehints and add tests with new assertion Signed-off-by: mesilov --- .../Activity/Result/ActivityItemResult.php | 68 +++-- .../CRM/Common/Result/AbstractCrmItem.php | 6 + .../CRM/Contact/Result/ContactItemResult.php | 6 +- .../CustomBitrix24Assertions.php | 241 +++++++++++++++++- .../CRM/Activity/Service/ActivityTest.php | 110 +++++--- .../CRM/Contact/Service/ContactTest.php | 41 ++- 6 files changed, 378 insertions(+), 94 deletions(-) diff --git a/src/Services/CRM/Activity/Result/ActivityItemResult.php b/src/Services/CRM/Activity/Result/ActivityItemResult.php index 8e819f40..d45507ff 100644 --- a/src/Services/CRM/Activity/Result/ActivityItemResult.php +++ b/src/Services/CRM/Activity/Result/ActivityItemResult.php @@ -27,49 +27,47 @@ /** * @see https://training.bitrix24.com/rest_help/crm/rest_activity/crm_activity_fields.php * - * @property-read int $ID // Activity ID - * @property-read int $OWNER_ID - * @property-read string $OWNER_TYPE_ID - * @property-read ActivityType $TYPE_ID - * @property-read string $PROVIDER_ID - * @property-read string $PROVIDER_TYPE_ID - * @property-read string $PROVIDER_GROUP_ID * @property-read int $ASSOCIATED_ENTITY_ID // ID of an entity associated with the activity - * @property-read string $SUBJECT - * @property-read string $START_TIME - * @property-read string $END_TIME // Completion time - * @property-read CarbonImmutable $DEADLINE // Deadline - * @property-read boolean $COMPLETED // Completed - * @property-read ActivityStatus $STATUS - * @property-read int $RESPONSIBLE_ID - * @property-read ActivityPriority $PRIORITY - * @property-read ActivityNotifyType $NOTIFY_TYPE // Notification type with crm_enum_activitynotifytype type - * @property-read int $NOTIFY_VALUE - * @property-read string $DESCRIPTION // Description - * @property-read ActivityContentType $DESCRIPTION_TYPE // Description type with crm_enum_contenttype type - * @property-read ActivityDirectionType $DIRECTION // with crm_enum_activity direction type - * @property-read string|null $LOCATION // Location + * @property-read array $BINDINGS // Bindings + * @property-read boolean $COMPLETED // Completed + * @property-read array $COMMUNICATIONS // type crm_activity_communication * @property-read CarbonImmutable $CREATED - * @property-read int $AUTHOR_ID // Activity author ID - * @property-read CarbonImmutable $LAST_UPDATED // Date of the last update date + * @property-read CarbonImmutable $DEADLINE // Deadline + * @property-read string $DESCRIPTION // Description + * @property-read ActivityContentType $DESCRIPTION_TYPE // Description type with crm_enum_contenttype type + * @property-read ActivityDirectionType $DIRECTION // with crm_enum_activity direction type * @property-read int $EDITOR_ID // Editor - * @property-read array $SETTINGS + * @property-read CarbonImmutable $END_TIME // Completion time + * @property-read array $FILES // Added files with diskfile type + * @property-read int $ID // Activity ID + * @property-read boolean $IS_INCOMING_CHANNEL + * @property-read CarbonImmutable $LAST_UPDATED // Date of the last update date + * @property-read string|null $LOCATION // Location + * @property-read ActivityNotifyType $NOTIFY_TYPE + * @property-read int $NOTIFY_VALUE * @property-read string|null $ORIGIN_ID * @property-read string|null $ORIGINATOR_ID - * @property-read int $RESULT_STATUS - * @property-read int $RESULT_STREAM - * @property-read string|null $RESULT_SOURCE_ID - * @property-read array $PROVIDER_PARAMS + * @property-read int $OWNER_ID + * @property-read int $OWNER_TYPE_ID + * @property-read int $RESPONSIBLE_ID + * @property-read string $PROVIDER_ID * @property-read string|null $PROVIDER_DATA + * @property-read string|null $PROVIDER_GROUP_ID + * @property-read array $PROVIDER_PARAMS + * @property-read string $PROVIDER_TYPE_ID * @property-read int $RESULT_MARK - * @property-read string|null $RESULT_VALUE - * @property-read Money|null $RESULT_SUM * @property-read Currency|null $RESULT_CURRENCY_ID - * @property-read int $AUTOCOMPLETE_RULE // Autocompletion - * @property-read string $BINDINGS // Bindings - * @property-read array $COMMUNICATIONS // type crm_activity_communication - * @property-read array $FILES // Added files with diskfile type - * @property-read string $WEBDAV_ELEMENTS + * @property-read int $RESULT_STATUS + * @property-read int $RESULT_STREAM + * @property-read Money|null $RESULT_SUM + * @property-read Money|null $RESULT_VALUE + * @property-read string|null $RESULT_SOURCE_ID + * @property-read array $SETTINGS + * @property-read CarbonImmutable $START_TIME + * @property-read ActivityStatus $STATUS + * @property-read string $SUBJECT + * @property-read ActivityType $TYPE_ID + * @property-read array $WEBDAV_ELEMENTS */ class ActivityItemResult extends AbstractCrmItem { diff --git a/src/Services/CRM/Common/Result/AbstractCrmItem.php b/src/Services/CRM/Common/Result/AbstractCrmItem.php index e32c1934..1718488f 100644 --- a/src/Services/CRM/Common/Result/AbstractCrmItem.php +++ b/src/Services/CRM/Common/Result/AbstractCrmItem.php @@ -51,6 +51,7 @@ public function __get($offset) switch ($offset) { case 'ID': + case 'NOTIFY_VALUE': case 'ASSIGNED_BY_ID': case 'CONTACT_IDS': case 'RESPONSIBLE_ID': @@ -85,6 +86,7 @@ public function __get($offset) case 'RESULT_STREAM': case 'LAST_ACTIVITY_BY': case 'ADDRESS_LOC_ADDR_ID': + case 'OWNER_TYPE_ID': if ($this->data[$offset] !== '' && $this->data[$offset] !== null) { return (int)$this->data[$offset]; } @@ -114,6 +116,7 @@ public function __get($offset) case 'TAX_INCLUDED': case 'CUSTOMIZED': case 'COMPLETED': + case 'IS_INCOMING_CHANNEL': return $this->data[$offset] === 'Y'; case 'DATE_CREATE': case 'CREATED_DATE': @@ -129,6 +132,8 @@ public function __get($offset) case 'movedTime': case 'lastActivityTime': case 'LAST_ACTIVITY_TIME': + case 'START_TIME': + case 'END_TIME': if ($this->data[$offset] !== '') { return CarbonImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]); } @@ -140,6 +145,7 @@ public function __get($offset) case 'PRICE': case 'DISCOUNT_SUM': case 'RESULT_SUM': + case 'RESULT_VALUE': if ($this->data[$offset] !== '' && $this->data[$offset] !== null) { $var = $this->data[$offset] * 100; return new Money((string)$var, new Currency($this->currency->getCode())); diff --git a/src/Services/CRM/Contact/Result/ContactItemResult.php b/src/Services/CRM/Contact/Result/ContactItemResult.php index 357de417..4ef89715 100644 --- a/src/Services/CRM/Contact/Result/ContactItemResult.php +++ b/src/Services/CRM/Contact/Result/ContactItemResult.php @@ -52,16 +52,16 @@ * @property-read CarbonImmutable $LAST_ACTIVITY_TIME * @property-read int $LAST_ACTIVITY_BY * @property-read string|null $LAST_NAME - * @property-read string|null $LINK + * @property-read array|null $LINK * @property-read int $MODIFY_BY_ID * @property-read string $NAME * @property-read string|null $ORIGIN_ID * @property-read string|null $ORIGINATOR_ID * @property-read string|null $ORIGIN_VERSION - * @property-read string $OPENED + * @property-read bool $OPENED * @property-read Phone[] $PHONE * @property-read string|null $POST - * @property-read string|null $PHOTO + * @property-read array|null $PHOTO * @property-read string|null $SECOND_NAME * @property-read string|null $SOURCE_DESCRIPTION * @property-read string|null $SOURCE_ID diff --git a/tests/CustomAssertions/CustomBitrix24Assertions.php b/tests/CustomAssertions/CustomBitrix24Assertions.php index 5f12030d..6fed8c47 100644 --- a/tests/CustomAssertions/CustomBitrix24Assertions.php +++ b/tests/CustomAssertions/CustomBitrix24Assertions.php @@ -12,8 +12,16 @@ namespace Bitrix24\SDK\Tests\CustomAssertions; -use Bitrix24\SDK\Services\CRM\Contact\Result\ContactItemResult; +use Bitrix24\SDK\Services\CRM\Activity\ActivityContentType; +use Bitrix24\SDK\Services\CRM\Activity\ActivityDirectionType; +use Bitrix24\SDK\Services\CRM\Activity\ActivityNotifyType; +use Bitrix24\SDK\Services\CRM\Activity\ActivityPriority; +use Bitrix24\SDK\Services\CRM\Activity\ActivityStatus; +use Bitrix24\SDK\Services\CRM\Activity\ActivityType; +use Carbon\CarbonImmutable; use Typhoon\Reflection\TyphoonReflector; +use function Typhoon\Type\stringify; +use Money\Currency; trait CustomBitrix24Assertions { @@ -42,4 +50,235 @@ protected function assertBitrix24AllResultItemFieldsAnnotated(array $fieldCodesF implode(', ', array_values(array_diff($fieldCodesFromApi, $propsFromAnnotations))) )); } + + protected function assertBitrix24AllResultItemFieldsHasValidTypeAnnotation(array $fieldCodesFromApi, string $resultItemClassName):void + { + // parse keys from phpdoc annotation + $props = TyphoonReflector::build()->reflectClass($resultItemClassName)->properties(); + $propsFromAnnotations = []; + foreach ($props as $meta) { + if ($meta->isAnnotated() && !$meta->isNative()) { + $propsFromAnnotations[$meta->id->name]=stringify($meta->type()); + } + } + + asort($propsFromAnnotations); + asort($fieldCodesFromApi); + foreach($fieldCodesFromApi as $fieldCode => $fieldData){ + // mapping internal bitrix24 types to bitrix24 sdk types + switch ($fieldData['type']){ + case 'string': + case 'crm_status': + // if field code contains currency + if(str_contains($fieldCode, 'CURRENCY_ID')){ + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode], Currency::class), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + Currency::class + ) + ); + break; + } + + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode], 'string',), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'string' + ) + ); + break; + case 'user': + case 'crm_enum_ownertype': + case 'crm_lead': + case 'integer': + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode],'int'), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'int' + ) + ); + break; + case 'double': + $this->assertEquals( + 'Money\Money|null', + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'Money\Money|null' + ) + ); + break; + case 'date': + case 'datetime': + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode],CarbonImmutable::class), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + CarbonImmutable::class + ) + ); + break; + case 'char': + $this->assertEquals( + 'bool', + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'bool' + ) + ); + break; + case 'diskfile': + case 'object': + case 'file': + case 'crm_company': + if(str_contains($fieldCode, '_IDS') || str_contains($fieldCode, 'PHOTO')) { + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode], 'array'), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'array' + ) + ); + break; + } + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode], 'int'), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'int' + ) + ); + break; + case 'crm_enum_activitydirection': + $this->assertEquals( + ActivityDirectionType::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityDirectionType::class + ) + ); + break; + case 'crm_enum_contenttype': + $this->assertEquals( + ActivityContentType::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityContentType::class + ) + ); + break; + case 'crm_enum_activitytype': + $this->assertEquals( + ActivityType::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityType::class + ) + ); + break; + case 'crm_enum_activitynotifytype': + $this->assertEquals( + ActivityNotifyType::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityNotifyType::class + ) + ); + break; + case 'crm_enum_activitypriority': + $this->assertEquals( + ActivityPriority::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityPriority::class + ) + ); + break; + case 'crm_enum_activitystatus': + $this->assertEquals( + ActivityStatus::class, + $propsFromAnnotations[$fieldCode], + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + ActivityStatus::class + ) + ); + break; + case 'crm_activity_binding': + case 'crm_activity_communication': + case 'crm_multifield': + $this->assertTrue( + str_contains($propsFromAnnotations[$fieldCode],'array'), + sprintf('class «%s» field «%s» has invalid type phpdoc annotation «%s», field type from bitrix24 is «%s», expected sdk-type «%s»', + $resultItemClassName, + $fieldCode, + $propsFromAnnotations[$fieldCode], + $fieldData['type'], + 'array' + ) + ); + break; + default: + $this->assertFalse(true, + sprintf('class «%s» field «%s» has unknown field type from bitrix24 «%s», sdk-type from annotation «%s», fix type mapping map in integration test', + $resultItemClassName, + $fieldCode, + $fieldData['type'], + $propsFromAnnotations[$fieldCode], + ) + ); + } + } + } } \ No newline at end of file diff --git a/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php b/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php index 758717ed..7a05a2c0 100644 --- a/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php +++ b/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php @@ -21,23 +21,88 @@ use Bitrix24\SDK\Services\CRM\Activity\Service\Activity; use Bitrix24\SDK\Services\CRM\Activity\ActivityType; use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; +use Bitrix24\SDK\Services\CRM\Deal\Result\DealItemResult; use Bitrix24\SDK\Services\CRM\Deal\Result\DealProductRowItemResult; use Bitrix24\SDK\Tests\Builders\DemoDataGenerator; use Bitrix24\SDK\Tests\Integration\Fabric; +use PHPUnit\Framework\Attributes\CoversFunction; +use PHPUnit\Framework\Attributes\CoversMethod; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Typhoon\Reflection\TyphoonReflector; +use Bitrix24\SDK\Tests\CustomAssertions\CustomBitrix24Assertions; +use Bitrix24\SDK\Core; +#[CoversClass(Activity::class)] +#[CoversMethod(Activity::class, 'add')] +#[CoversMethod(Activity::class, 'delete')] +#[CoversMethod(Activity::class, 'fields')] +#[CoversMethod(Activity::class, 'get')] +#[CoversMethod(Activity::class, 'list')] +#[CoversMethod(Activity::class, 'update')] +#[CoversMethod(Activity::class, 'countByFilter')] class ActivityTest extends TestCase { + use CustomBitrix24Assertions; + private Activity $activityService; private Contact $contactService; private array $contactId; private array $activityId; + public function testAllSystemFieldsAnnotated(): void + { + $propListFromApi = (new Core\Fields\FieldsFilter())->filterSystemFields(array_keys($this->activityService->fields()->getFieldsDescription())); + $this->assertBitrix24AllResultItemFieldsAnnotated($propListFromApi, ActivityItemResult::class); + } + + public function testAllSystemFieldsHasValidTypeAnnotation():void + { + $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( + $this->activityService->fields()->getFieldsDescription(), + ActivityItemResult::class); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testGet(): void + { + $contactId = $this->contactService->add(['NAME' => 'test contact'])->getId(); + $this->contactId[] = $contactId; + + $newActivity = [ + 'OWNER_ID' => $contactId, + 'OWNER_TYPE_ID' => 3, + 'TYPE_ID' => ActivityType::call->value, + 'PROVIDER_ID' => 'VOXIMPLANT_CALL', + 'PROVIDER_TYPE_ID' => 'CALL', + 'SUBJECT' => 'test activity', + 'DESCRIPTION' => 'test activity description', + 'DESCRIPTION_TYPE' => '1', + 'DIRECTION' => '2', + 'COMMUNICATIONS' => [ + 0 => [ + 'TYPE' => 'PHONE', + 'VALUE' => DemoDataGenerator::getMobilePhone()->getNationalNumber(), + ], + ], + 'RESULT_SUM' => 500, + 'RESULT_CURRENCY_ID' => 'USD' + ]; + $activityId = $this->activityService->add($newActivity)->getId(); + $this->activityId[] = $activityId; + + $activity = $this->activityService->get($activityId)->activity(); + + $this->assertEquals($newActivity['OWNER_ID'], $activity->OWNER_ID); + $this->assertEquals($newActivity['SUBJECT'], $activity->SUBJECT); + } + /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Activity::add */ public function testAdd(): void { @@ -69,7 +134,6 @@ public function testAdd(): void /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Activity::delete */ public function testDelete(): void { @@ -110,43 +174,6 @@ public function testFields(): void /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Activity::get - */ - public function testGet(): void - { - $contactId = $this->contactService->add(['NAME' => 'test contact'])->getId(); - $this->contactId[] = $contactId; - - $newActivity = [ - 'OWNER_ID' => $contactId, - 'OWNER_TYPE_ID' => 3, - 'TYPE_ID' => ActivityType::call->value, - 'PROVIDER_ID' => 'VOXIMPLANT_CALL', - 'PROVIDER_TYPE_ID' => 'CALL', - 'SUBJECT' => 'test activity', - 'DESCRIPTION' => 'test activity description', - 'DESCRIPTION_TYPE' => '1', - 'DIRECTION' => '2', - 'COMMUNICATIONS' => [ - 0 => [ - 'TYPE' => 'PHONE', - 'VALUE' => DemoDataGenerator::getMobilePhone()->getNationalNumber(), - ], - ], - ]; - $activityId = $this->activityService->add($newActivity)->getId(); - $this->activityId[] = $activityId; - - $activity = $this->activityService->get($activityId)->activity(); - - $this->assertEquals($newActivity['OWNER_ID'], $activity->OWNER_ID); - $this->assertEquals($newActivity['SUBJECT'], $activity->SUBJECT); - } - - /** - * @throws BaseException - * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Activity::list */ public function testList(): void { @@ -183,13 +210,14 @@ public function testList(): void ["*", "COMMUNICATIONS"], 0 ); - $this->assertEquals(count($newActivity), count($res->getActivities())); + + + $this->assertEquals(count($newActivity), count($res->getActivities())); } /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Activity::update */ public function testUpdate(): void { diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactTest.php index 425fe881..a24da1f4 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactTest.php @@ -15,6 +15,7 @@ use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Exceptions\TransportException; +use Bitrix24\SDK\Services\CRM\Activity\Result\ActivityItemResult; use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\EmailValueType; use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessengerValueType; use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\PhoneValueType; @@ -23,6 +24,8 @@ use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; use Bitrix24\SDK\Tests\CustomAssertions\CustomBitrix24Assertions; use Bitrix24\SDK\Tests\Integration\Fabric; +use PHPUnit\Framework\Attributes\CoversFunction; +use PHPUnit\Framework\Attributes\CoversMethod; use PHPUnit\Framework\TestCase; use Bitrix24\SDK\Core; use Faker; @@ -32,6 +35,12 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Contact\Service */ +#[CoversMethod(Contact::class,'add')] +#[CoversMethod(Contact::class,'delete')] +#[CoversMethod(Contact::class,'fields')] +#[CoversMethod(Contact::class,'get')] +#[CoversMethod(Contact::class,'list')] +#[CoversMethod(Contact::class,'update')] class ContactTest extends TestCase { use CustomBitrix24Assertions; @@ -42,8 +51,8 @@ class ContactTest extends TestCase /** * @throws BaseException * @throws TransportException - * @covers Contact::add */ + public function testAdd(): void { self::assertGreaterThanOrEqual(1, $this->contactService->add(['NAME' => 'test contact'])->getId()); @@ -52,7 +61,6 @@ public function testAdd(): void /** * @throws BaseException * @throws TransportException - * @covers Contact::delete */ public function testDelete(): void { @@ -60,7 +68,6 @@ public function testDelete(): void } /** - * @covers Contact::fields * @throws BaseException * @throws TransportException */ @@ -75,10 +82,26 @@ public function testAllSystemFieldsAnnotated(): void $this->assertBitrix24AllResultItemFieldsAnnotated($propListFromApi, ContactItemResult::class); } + /** + * @throws TransportException + * @throws BaseException + */ + public function testAllSystemFieldsHasValidTypeAnnotation():void + { + $allFields = $this->contactService->fields()->getFieldsDescription(); + $systemFieldsCodes = (new Core\Fields\FieldsFilter())->filterSystemFields(array_keys($allFields)); + $systemFields = array_filter($allFields, static function ($code) use ($systemFieldsCodes) { + return in_array($code, $systemFieldsCodes, true); + }, ARRAY_FILTER_USE_KEY); + + $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( + $systemFields, + ContactItemResult::class); + } + /** * @throws BaseException * @throws TransportException - * @covers Contact::get */ public function testGet(): void { @@ -91,7 +114,6 @@ public function testGet(): void /** * @throws BaseException * @throws TransportException - * @covers Contact::list */ public function testList(): void { @@ -102,7 +124,6 @@ public function testList(): void /** * @throws BaseException * @throws TransportException - * @covers Contact::update */ public function testUpdate(): void { @@ -138,8 +159,6 @@ public function testCountByFilter(): void /** * @return void - * @covers Contact::get - * @covers Contact::add * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -161,8 +180,6 @@ public function testGetEmail(): void /** * @return void - * @covers Contact::get - * @covers Contact::add * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -184,8 +201,6 @@ public function testGetPhone(): void /** * @return void - * @covers Contact::get - * @covers Contact::add * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -207,8 +222,6 @@ public function testGetInstantMessenger(): void /** * @return void - * @covers Contact::get - * @covers Contact::add * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ From 05a940ac55c17d773cc63dda8fdc48b80a19f7d1 Mon Sep 17 00:00:00 2001 From: mesilov Date: Fri, 22 Nov 2024 01:50:16 +0600 Subject: [PATCH 2/2] Fix typehints in ActivityItemResult and ContactItemResult Corrected typehints in `ActivityItemResult` and `ContactItemResult` to ensure proper type definitions. This addresses the issues highlighted in [issue #81](https://github.com/bitrix24/b24phpsdk/issues/81). Signed-off-by: mesilov --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca54cfcf..dc0c61eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ see [bitrix24AccountRepositoryInterface has problem with contract tests design - can't add flusher](https://github.com/bitrix24/b24phpsdk/issues/74). - Fixed error in bitrix24 account contract test data provider, see [incorrect data in data provider](https://github.com/bitrix24/b24phpsdk/issues/77). +- Fixed typehints in `ActivityItemResult`, `ContactItemResult`, + see [wrong type hints in ActivityItemResult](https://github.com/bitrix24/b24phpsdk/issues/81)