From 1baa46f0983eccdefe62225b7fa27cb802d96a54 Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Wed, 16 Apr 2025 13:24:42 +0400 Subject: [PATCH 01/11] add draft classes for crm.address --- .../CRM/Address/Result/AddressItemResult.php | 98 +++++++ .../CRM/Address/Result/AddressResult.php | 33 +++ .../CRM/Address/Result/AddressesResult.php | 40 +++ src/Services/CRM/Address/Service/Address.php | 239 ++++++++++++++++++ src/Services/CRM/Address/Service/Batch.php | 171 +++++++++++++ 5 files changed, 581 insertions(+) create mode 100644 src/Services/CRM/Address/Result/AddressItemResult.php create mode 100644 src/Services/CRM/Address/Result/AddressResult.php create mode 100644 src/Services/CRM/Address/Result/AddressesResult.php create mode 100644 src/Services/CRM/Address/Service/Address.php create mode 100644 src/Services/CRM/Address/Service/Batch.php diff --git a/src/Services/CRM/Address/Result/AddressItemResult.php b/src/Services/CRM/Address/Result/AddressItemResult.php new file mode 100644 index 00000000..29898d8e --- /dev/null +++ b/src/Services/CRM/Address/Result/AddressItemResult.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Address\Result; + +use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem; +use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Email; +use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessenger; +use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone; +use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Website; +use Carbon\CarbonImmutable; +use Money\Currency; +use Money\Money; + +/** + * Class AddressItemResult + * + * @property-read int $ID + * @property-read string $TITLE + * @property-read string|null $HONORIFIC + * @property-read string|null $NAME + * @property-read string|null $SECOND_NAME + * @property-read string|null $LAST_NAME + * @property-read CarbonImmutable|null $BIRTHDATE + * @property-read string|null $COMPANY_TITLE + * @property-read string|null $SOURCE_ID + * @property-read string|null $SOURCE_DESCRIPTION + * @property-read string|null $STATUS_ID + * @property-read string|null $STATUS_DESCRIPTION + * @property-read string|null $STATUS_SEMANTIC_ID + * @property-read string|null $POST + * @property-read string|null $ADDRESS + * @property-read string|null $ADDRESS_2 + * @property-read string|null $ADDRESS_CITY + * @property-read string|null $ADDRESS_POSTAL_CODE + * @property-read string|null $ADDRESS_REGION + * @property-read string|null $ADDRESS_PROVINCE + * @property-read string|null $ADDRESS_COUNTRY + * @property-read string|null $ADDRESS_COUNTRY_CODE + * @property-read int|null $ADDRESS_LOC_ADDR_ID + * @property-read Currency|null $CURRENCY_ID + * @property-read Money|null $OPPORTUNITY + * @property-read bool|null $IS_MANUAL_OPPORTUNITY + * @property-read bool|null $OPENED + * @property-read string|null $COMMENTS + * @property-read bool|null $HAS_PHONE + * @property-read bool|null $HAS_EMAIL + * @property-read bool|null $HAS_IMOL + * @property-read int|null $ASSIGNED_BY_ID + * @property-read int|null $CREATED_BY_ID + * @property-read int|null $MODIFY_BY_ID + * @property-read int|null $MOVED_BY_ID + * @property-read CarbonImmutable|null $DATE_CREATE + * @property-read CarbonImmutable|null $DATE_MODIFY + * @property-read CarbonImmutable|null $MOVED_TIME + * @property-read int|null $COMPANY_ID + * @property-read int|null $CONTACT_ID + * @property-read array|null $CONTACT_IDS + * @property-read bool|null $IS_RETURN_CUSTOMER + * @property-read CarbonImmutable|null $DATE_CLOSED + * @property-read string|null $ORIGINATOR_ID + * @property-read string|null $ORIGIN_ID + * @property-read string|null $UTM_SOURCE + * @property-read string|null $UTM_MEDIUM + * @property-read string|null $UTM_CAMPAIGN + * @property-read string|null $UTM_CONTENT + * @property-read string|null $UTM_TERM + * @property-read Phone[]|null $PHONE + * @property-read Email[]|null $EMAIL + * @property-read Website[]|null $WEB + * @property-read InstantMessenger[]|null $IM + * @property-read array|null $LINK + * @property-read int|null $LAST_ACTIVITY_BY + * @property-read CarbonImmutable|null $LAST_ACTIVITY_TIME + */ +class AddressItemResult extends AbstractCrmItem +{ + /** + * @param string $userfieldName + * + * @return mixed|null + * @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException + */ + public function getUserfieldByFieldName(string $userfieldName) + { + return $this->getKeyWithUserfieldByFieldName($userfieldName); + } +} \ No newline at end of file diff --git a/src/Services/CRM/Address/Result/AddressResult.php b/src/Services/CRM/Address/Result/AddressResult.php new file mode 100644 index 00000000..f3a09a4d --- /dev/null +++ b/src/Services/CRM/Address/Result/AddressResult.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Address\Result; + +use Bitrix24\SDK\Core\Result\AbstractResult; + +/** + * Class LeadResult + * + * @package Bitrix24\SDK\Services\CRM\Address\Result + */ +class AddressResult extends AbstractResult +{ + /** + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + public function address(): AddressItemResult + { + return new AddressItemResult($this->getCoreResponse()->getResponseData()->getResult()); + } +} \ No newline at end of file diff --git a/src/Services/CRM/Address/Result/AddressesResult.php b/src/Services/CRM/Address/Result/AddressesResult.php new file mode 100644 index 00000000..b67d9004 --- /dev/null +++ b/src/Services/CRM/Address/Result/AddressesResult.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Address\Result; + +use Bitrix24\SDK\Core\Exceptions\BaseException; +use Bitrix24\SDK\Core\Result\AbstractResult; + +/** + * Class AddressResult + * + * @package Bitrix24\SDK\Services\CRM\Address\Result + */ +class AddressResult extends AbstractResult +{ + /** + * @return AddressItemResult[] + * @throws BaseException + */ + public function getAddresses(): array + { + $items = []; + foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) { + $items[] = new AddressItemResult($item); + } + + return $items; + } +} \ No newline at end of file diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php new file mode 100644 index 00000000..5498661a --- /dev/null +++ b/src/Services/CRM/Address/Service/Address.php @@ -0,0 +1,239 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Address\Service; + +use Bitrix24\SDK\Attributes\ApiEndpointMetadata; +use Bitrix24\SDK\Attributes\ApiServiceMetadata; +use Bitrix24\SDK\Core\Contracts\CoreInterface; +use Bitrix24\SDK\Core\Credentials\Scope; +use Bitrix24\SDK\Core\Exceptions\BaseException; +use Bitrix24\SDK\Core\Exceptions\TransportException; +use Bitrix24\SDK\Core\Result\AddedItemResult; +use Bitrix24\SDK\Core\Result\DeletedItemResult; +use Bitrix24\SDK\Core\Result\FieldsResult; +use Bitrix24\SDK\Core\Result\UpdatedItemResult; +use Bitrix24\SDK\Services\AbstractService; +use Bitrix24\SDK\Services\CRM\Address\Result\AddressResult; +use Bitrix24\SDK\Services\CRM\Address\Result\AddressesResult; +use Psr\Log\LoggerInterface; +#[ApiServiceMetadata(new Scope(['crm']))] +class Address extends AbstractService +{ + public Batch $batch; + + /** + * Address constructor. + * + * @param Batch $batch + * @param CoreInterface $core + * @param LoggerInterface $log + */ + public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $log) + { + parent::__construct($core, $log); + $this->batch = $batch; + } + + /** + * add new address + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-add.html + * + * @param array{ + * TYPE_ID?: int, + * ENTITY_TYPE_ID?: int, + * ENTITY_ID?: string, + * ADDRESS_1?: string, + * ADDRESS_2?: string, + * CITY?: string, + * POSTAL_CODE?: string, + * REGION?: string, + * PROVINCE?: string, + * COUNTRY?: string, + * COUNTRY_CODE?: string, + * LOC_ADDR_ID?: int, + * } $fields + * + * @return AddedItemResult + * @throws BaseException + * @throws TransportException + */ + #[ApiEndpointMetadata( + 'crm.address.add', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-add.html', + 'Method adds new address' + )] + public function add(array $fields): AddedItemResult + { + return new AddedItemResult( + $this->core->call( + 'crm.address.add', + [ + 'fields' => $fields, + ] + ) + ); + } + + /** + * Deletes the specified address. + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html + * + * @param int $id + * + * @return DeletedItemResult + * @throws BaseException + * @throws TransportException + */ + #[ApiEndpointMetadata( + 'crm.address.delete', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html', + 'Deletes the specified address.' + )] + public function delete(array $fields): DeletedItemResult + { + return new DeletedItemResult( + $this->core->call( + 'crm.address.delete', + [ + 'fields' => $fields, + ] + ) + ); + } + + /** + * Returns the description of the address fields. + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-fields.html + * + * @return FieldsResult + * @throws BaseException + * @throws TransportException + */ + #[ApiEndpointMetadata( + 'crm.address.fields', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-fields.html', + 'Returns the description of the address fields.' + )] + public function fields(): FieldsResult + { + return new FieldsResult($this->core->call('crm.address.fields')); + } + + /** + * Get list of address items. + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-list.html + * + * @param array $order - order of address items + * @param array $filter - filter array + * @param array $select = ['TYPE_ID','ENTITY_TYPE_ID','ENTITY_ID','ADDRESS_1','ADDRESS_2','CITY','POSTAL_CODE','REGION','PROVINCE','COUNTRY','COUNTRY_CODE','LOC_ADDR_ID','ANCHOR_TYPE_ID','ANCHOR_ID'] + * @param integer $startItem - entity number to start from (usually returned in 'next' field of previous 'crm.address.list' API call) + * + * @throws BaseException + * @throws TransportException + * @return AddressesResult + */ + #[ApiEndpointMetadata( + 'crm.address.list', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-list.html', + 'Get list of address items.' + )] + public function list(array $order, array $filter, array $select, int $startItem = 0): AddressesResult + { + return new AddressesResult( + $this->core->call( + 'crm.address.list', + [ + 'order' => $order, + 'filter' => $filter, + 'select' => $select, + 'start' => $startItem, + ] + ) + ); + } + + /** + * Updates the specified (existing) address. + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-update.html + * + * @param array{ + * TYPE_ID?: int, + * ENTITY_TYPE_ID?: int, + * ENTITY_ID?: string, + * ADDRESS_1?: string, + * ADDRESS_2?: string, + * CITY?: string, + * POSTAL_CODE?: string, + * REGION?: string, + * PROVINCE?: string, + * COUNTRY?: string, + * COUNTRY_CODE?: string, + * LOC_ADDR_ID?: int, + * } $fields + * + * @return UpdatedItemResult + * @throws BaseException + * @throws TransportException + */ + #[ApiEndpointMetadata( + 'crm.address.update', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-update.html', + 'Updates the specified (existing) address.' + )] + public function update(array $fields): UpdatedItemResult + { + return new UpdatedItemResult( + $this->core->call( + 'crm.address.update', + [ + 'fields' => $fields, + ] + ) + ); + } + + /** + * Count Addresses by filter + * + * @param array{ + * TYPE_ID?: int, + * ENTITY_TYPE_ID?: int, + * ENTITY_ID?: string, + * ADDRESS_1?: string, + * ADDRESS_2?: string, + * CITY?: string, + * POSTAL_CODE?: string, + * REGION?: string, + * PROVINCE?: string, + * COUNTRY?: string, + * COUNTRY_CODE?: string, + * LOC_ADDR_ID?: int, + * ANCHOR_TYPE_ID?: int, + * ANCHOR_ID?: int, + * } $filter + * + * @return int + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + * @throws \Bitrix24\SDK\Core\Exceptions\TransportException + */ + public function countByFilter(array $filter = []): int + { + return $this->list([], $filter, ['ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); + } +} \ No newline at end of file diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php new file mode 100644 index 00000000..7a54a07b --- /dev/null +++ b/src/Services/CRM/Address/Service/Batch.php @@ -0,0 +1,171 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Address\Service; + +use Bitrix24\SDK\Attributes\ApiBatchMethodMetadata; +use Bitrix24\SDK\Attributes\ApiBatchServiceMetadata; +use Bitrix24\SDK\Core\Contracts\BatchOperationsInterface; +use Bitrix24\SDK\Core\Credentials\Scope; +use Bitrix24\SDK\Core\Exceptions\BaseException; +use Bitrix24\SDK\Core\Result\AddedItemBatchResult; +use Bitrix24\SDK\Core\Result\DeletedItemBatchResult; +use Bitrix24\SDK\Services\CRM\Address\Result\AddressItemResult; +use Generator; +use Psr\Log\LoggerInterface; + +#[ApiBatchServiceMetadata(new Scope(['crm']))] +class Batch +{ + protected BatchOperationsInterface $batch; + protected LoggerInterface $log; + + /** + * Batch constructor. + * + * @param BatchOperationsInterface $batch + * @param LoggerInterface $log + */ + public function __construct(BatchOperationsInterface $batch, LoggerInterface $log) + { + $this->batch = $batch; + $this->log = $log; + } + + /** + * Batch list method for Addresses + * + * @param array{ + * TYPE_ID?: int, + * ENTITY_TYPE_ID?: int, + * ENTITY_ID?: string, + * ADDRESS_1?: string, + * ADDRESS_2?: string, + * CITY?: string, + * POSTAL_CODE?: string, + * REGION?: string, + * PROVINCE?: string, + * COUNTRY?: string, + * COUNTRY_CODE?: string, + * LOC_ADDR_ID?: int, + * ANCHOR_TYPE_ID?: int, + * ANCHOR_ID?: int, + * } $order + * + * @param array{ + * TYPE_ID?: int, + * ENTITY_TYPE_ID?: int, + * ENTITY_ID?: string, + * ADDRESS_1?: string, + * ADDRESS_2?: string, + * CITY?: string, + * POSTAL_CODE?: string, + * REGION?: string, + * PROVINCE?: string, + * COUNTRY?: string, + * COUNTRY_CODE?: string, + * LOC_ADDR_ID?: int, + * ANCHOR_TYPE_ID?: int, + * ANCHOR_ID?: int, + * } $filter + * @param array $select = ['TYPE_ID','ENTITY_TYPE_ID','ENTITY_ID','ADDRESS_1','ADDRESS_2','CITY','POSTAL_CODE','REGION','PROVINCE','COUNTRY','COUNTRY_CODE','LOC_ADDR_ID','ANCHOR_TYPE_ID','ANCHOR_ID'] + * @param int|null $limit + * + * @return Generator + * @throws BaseException + */ + #[ApiBatchMethodMetadata( + 'crm.address.list', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-list.html', + 'Batch list method for addresses' + )] + public function list(array $order, array $filter, array $select, ?int $limit = null): Generator + { + $this->log->debug( + 'batchList', + [ + 'order' => $order, + 'filter' => $filter, + 'select' => $select, + 'limit' => $limit, + ] + ); + foreach ($this->batch->getTraversableList('crm.address.list', $order, $filter, $select, $limit) as $key => $value) { + yield $key => new AddressItemResult($value); + } + } + + /** + * Batch adding addresses + * + * @param array $addresses + * + * @return Generator + * @throws BaseException + */ + #[ApiBatchMethodMetadata( + 'crm.address.add', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-add.html', + 'Batch adding addresses' + )] + public function add(array $addresses): Generator + { + $items = []; + foreach ($addresses as $address) { + $items[] = [ + 'fields' => $address, + ]; + } + foreach ($this->batch->addEntityItems('crm.address.add', $items) as $key => $item) { + yield $key => new AddedItemBatchResult($item); + } + } + + /** + * Batch delete addresses + * + * @param array $addressKeys + * + * @return Generator + * @throws BaseException + */ + #[ApiBatchMethodMetadata( + 'crm.address.delete', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html', + 'Batch delete addresses' + )] + public function delete(array $addressKeys): Generator + { + foreach ($this->batch->deleteEntityItems('crm.address.delete', $addressKeys) as $key => $item) { + yield $key => new DeletedItemBatchResult($item); + } + } + +} \ No newline at end of file From ca42f184d5521b5f29f4ea975f05b026469f16ac Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Wed, 16 Apr 2025 14:04:07 +0400 Subject: [PATCH 02/11] edit CRM Address Result classes --- .../CRM/Address/Result/AddressItemResult.php | 80 ++++--------------- .../CRM/Address/Result/AddressResult.php | 2 +- 2 files changed, 16 insertions(+), 66 deletions(-) diff --git a/src/Services/CRM/Address/Result/AddressItemResult.php b/src/Services/CRM/Address/Result/AddressItemResult.php index 29898d8e..6eb67f3a 100644 --- a/src/Services/CRM/Address/Result/AddressItemResult.php +++ b/src/Services/CRM/Address/Result/AddressItemResult.php @@ -14,85 +14,35 @@ namespace Bitrix24\SDK\Services\CRM\Address\Result; use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem; -use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Email; -use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessenger; -use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone; -use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Website; -use Carbon\CarbonImmutable; -use Money\Currency; -use Money\Money; /** * Class AddressItemResult * - * @property-read int $ID - * @property-read string $TITLE - * @property-read string|null $HONORIFIC - * @property-read string|null $NAME - * @property-read string|null $SECOND_NAME - * @property-read string|null $LAST_NAME - * @property-read CarbonImmutable|null $BIRTHDATE - * @property-read string|null $COMPANY_TITLE - * @property-read string|null $SOURCE_ID - * @property-read string|null $SOURCE_DESCRIPTION - * @property-read string|null $STATUS_ID - * @property-read string|null $STATUS_DESCRIPTION - * @property-read string|null $STATUS_SEMANTIC_ID - * @property-read string|null $POST - * @property-read string|null $ADDRESS + * @property-read int $TYPE_ID + * @property-read int $ENTITY_TYPE_ID + * @property-read string $ENTITY_ID + * @property-read string|null $ADDRESS_1 * @property-read string|null $ADDRESS_2 - * @property-read string|null $ADDRESS_CITY - * @property-read string|null $ADDRESS_POSTAL_CODE - * @property-read string|null $ADDRESS_REGION - * @property-read string|null $ADDRESS_PROVINCE - * @property-read string|null $ADDRESS_COUNTRY - * @property-read string|null $ADDRESS_COUNTRY_CODE - * @property-read int|null $ADDRESS_LOC_ADDR_ID - * @property-read Currency|null $CURRENCY_ID - * @property-read Money|null $OPPORTUNITY - * @property-read bool|null $IS_MANUAL_OPPORTUNITY - * @property-read bool|null $OPENED - * @property-read string|null $COMMENTS - * @property-read bool|null $HAS_PHONE - * @property-read bool|null $HAS_EMAIL - * @property-read bool|null $HAS_IMOL - * @property-read int|null $ASSIGNED_BY_ID - * @property-read int|null $CREATED_BY_ID - * @property-read int|null $MODIFY_BY_ID - * @property-read int|null $MOVED_BY_ID - * @property-read CarbonImmutable|null $DATE_CREATE - * @property-read CarbonImmutable|null $DATE_MODIFY - * @property-read CarbonImmutable|null $MOVED_TIME - * @property-read int|null $COMPANY_ID - * @property-read int|null $CONTACT_ID - * @property-read array|null $CONTACT_IDS - * @property-read bool|null $IS_RETURN_CUSTOMER - * @property-read CarbonImmutable|null $DATE_CLOSED - * @property-read string|null $ORIGINATOR_ID - * @property-read string|null $ORIGIN_ID - * @property-read string|null $UTM_SOURCE - * @property-read string|null $UTM_MEDIUM - * @property-read string|null $UTM_CAMPAIGN - * @property-read string|null $UTM_CONTENT - * @property-read string|null $UTM_TERM - * @property-read Phone[]|null $PHONE - * @property-read Email[]|null $EMAIL - * @property-read Website[]|null $WEB - * @property-read InstantMessenger[]|null $IM - * @property-read array|null $LINK - * @property-read int|null $LAST_ACTIVITY_BY - * @property-read CarbonImmutable|null $LAST_ACTIVITY_TIME + * @property-read string|null $CITY + * @property-read string|null $POSTAL_CODE + * @property-read string|null $REGION + * @property-read string|null $PROVINCE + * @property-read string|null $COUNTRY + * @property-read string|null $COUNTRY_CODE + * @property-read int|null $LOC_ADDR_ID + * @property-read int|null $ANCHOR_TYPE_ID + * @property-read int|null $ANCHOR_ID */ class AddressItemResult extends AbstractCrmItem { /** * @param string $userfieldName * - * @return mixed|null + * @return null * @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException */ public function getUserfieldByFieldName(string $userfieldName) { - return $this->getKeyWithUserfieldByFieldName($userfieldName); + return; } } \ No newline at end of file diff --git a/src/Services/CRM/Address/Result/AddressResult.php b/src/Services/CRM/Address/Result/AddressResult.php index f3a09a4d..26adb842 100644 --- a/src/Services/CRM/Address/Result/AddressResult.php +++ b/src/Services/CRM/Address/Result/AddressResult.php @@ -17,7 +17,7 @@ use Bitrix24\SDK\Core\Result\AbstractResult; /** - * Class LeadResult + * Class AddressResult * * @package Bitrix24\SDK\Services\CRM\Address\Result */ From 06083c60f8a006729f1a9205e3a076eb7ca81e46 Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Wed, 16 Apr 2025 16:32:15 +0400 Subject: [PATCH 03/11] add CRM Enum OwnerTape --- src/Services/CRM/Enum/OwnerType.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Services/CRM/Enum/OwnerType.php diff --git a/src/Services/CRM/Enum/OwnerType.php b/src/Services/CRM/Enum/OwnerType.php new file mode 100644 index 00000000..7e8f4a08 --- /dev/null +++ b/src/Services/CRM/Enum/OwnerType.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Services\CRM\Enum; + +enum OwnerType: int +{ + case lead = 1; + case deal = 2; + case contact = 3; + case company = 4; + case invoice = 5; + case smart_invoice = 31; + case estimate = 7; + case requisite = 8; + case all_inclusive = 130; +} \ No newline at end of file From 50caa3a491395dabe8284fc798312304c07440ae Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Thu, 17 Apr 2025 09:16:12 +0400 Subject: [PATCH 04/11] change filter param --- src/Services/CRM/Address/Service/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index 5498661a..6e6b1e4a 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -234,6 +234,6 @@ public function update(array $fields): UpdatedItemResult */ public function countByFilter(array $filter = []): int { - return $this->list([], $filter, ['ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); + return $this->list([], $filter, ['TYPE_ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); } } \ No newline at end of file From 0b8bdce74fded4bc9b0fa3daca23769135763770 Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Thu, 17 Apr 2025 09:16:55 +0400 Subject: [PATCH 05/11] start coding Address tests --- .../CRM/Address/Service/AddressTest.php | 165 ++++++++++++++++++ .../CRM/Address/Service/BatchTest.php | 106 +++++++++++ 2 files changed, 271 insertions(+) create mode 100644 tests/Integration/Services/CRM/Address/Service/AddressTest.php create mode 100644 tests/Integration/Services/CRM/Address/Service/BatchTest.php diff --git a/tests/Integration/Services/CRM/Address/Service/AddressTest.php b/tests/Integration/Services/CRM/Address/Service/AddressTest.php new file mode 100644 index 00000000..8b519e93 --- /dev/null +++ b/tests/Integration/Services/CRM/Address/Service/AddressTest.php @@ -0,0 +1,165 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Address\Service; + +use Bitrix24\SDK\Core\Exceptions\BaseException; +use Bitrix24\SDK\Core\Exceptions\TransportException; +use Bitrix24\SDK\Core; +use Bitrix24\SDK\Services\CRM\Address\Service\Address; +use Bitrix24\SDK\Services\CRM\Address\Result\AddressItemResult; +use Bitrix24\SDK\Services\ServiceBuilder; +use Bitrix24\SDK\Tests\Builders\Services\CRM\CompanyBuilder; +use Bitrix24\SDK\Services\CRM\Enum\AddressType; +use Bitrix24\SDK\Services\CRM\Enum\OwnerType; + +use Bitrix24\SDK\Services\CRM\Contact\Result\ContactItemResult; +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; + +/** + * Class LeadTest + * + * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Address\Service + */ +#[CoversMethod(Address::class,'add')] +#[CoversMethod(Address::class,'delete')] +#[CoversMethod(Address::class,'list')] +#[CoversMethod(Address::class,'fields')] +#[CoversMethod(Address::class,'update')] +class AddressTest extends TestCase +{ + use CustomBitrix24Assertions; + + protected ServiceBuilder $sb; + protected Address $addressService; + + public function setUp(): void + { + $this->sb = Fabric::getServiceBuilder(); + $this->addressService = Fabric::getServiceBuilder()->getCRMScope()->address(); + } + + public function testAllSystemFieldsAnnotated(): void + { + $propListFromApi = (new Core\Fields\FieldsFilter())->filterSystemFields(array_keys($this->addressService->fields()->getFieldsDescription())); + $this->assertBitrix24AllResultItemFieldsAnnotated($propListFromApi, AddressItemResult::class); + } + + public function testAllSystemFieldsHasValidTypeAnnotation():void + { + $allFields = $this->addressService->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, + AddressItemResult::class); + } + + /** + * @throws BaseException + * @throws TransportException + * @covers Address::add + */ + public function testAdd(): void + { + $companyId = $this->sb->getCRMScope()->company()->add((new CompanyBuilder())->build())->getId(); + self::assertEquals(1, $this->addressService->add( + [ + 'TYPE_ID' => AddressType::actual->value(), + 'ENTITY_TYPE_ID' => OwnerType::company->value(), + 'ENTITY_ID' => $companyId, + ])->getCoreResponse()->getResponseData()->getResult()[0]); + } + + /** + * @throws BaseException + * @throws TransportException + * @covers Address::delete + */ + public function testDelete(): void + { + self::assertTrue($this->addressService->delete($this->addressService->add(['TITLE' => 'test lead'])->getId())->isSuccess()); + } + + /** + * @covers Address::fields + * @throws BaseException + * @throws TransportException + */ + public function testFields(): void + { + self::assertIsArray($this->addressService->fields()->getFieldsDescription()); + } + + /** + * @throws BaseException + * @throws TransportException + * @covers Address::list + */ + public function testList(): void + { + $companyId = $this->sb->getCRMScope()->company()->add((new CompanyBuilder())->build())->getId(); + $this->addressService->add([ + 'TYPE_ID' => AddressType::actual->value(), + 'ENTITY_TYPE_ID' => OwnerType::company->value(), + 'ENTITY_ID' => $companyId, + ]); + self::assertGreaterThanOrEqual(1, $this->addressService->list([], [], ['TYPE_ID'])->getAddresses()); + } + + /** + * @throws BaseException + * @throws TransportException + * @covers Address::update + */ + public function testUpdate(): void + { + $deal = $this->addressService->add(['TITLE' => 'test lead']); + $newTitle = 'test2'; + + self::assertTrue($this->addressService->update($deal->getId(), ['TITLE' => $newTitle], [])->isSuccess()); + self::assertEquals($newTitle, $this->addressService->get($deal->getId())->lead()->TITLE); + } + + /** + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + * @throws \Bitrix24\SDK\Core\Exceptions\TransportException + * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Deal::countByFilter + */ + public function testCountByFilter(): void + { + $before = $this->addressService->countByFilter(); + + $newItemsCount = 60; + $items = []; + for ($i = 1; $i <= $newItemsCount; $i++) { + $items[] = ['TITLE' => 'TITLE-' . $i]; + } + $cnt = 0; + foreach ($this->addressService->batch->add($items) as $item) { + $cnt++; + } + self::assertEquals(count($items), $cnt); + + $after = $this->addressService->countByFilter(); + + $this->assertEquals($before + $newItemsCount, $after); + } +} \ No newline at end of file diff --git a/tests/Integration/Services/CRM/Address/Service/BatchTest.php b/tests/Integration/Services/CRM/Address/Service/BatchTest.php new file mode 100644 index 00000000..23bfd35c --- /dev/null +++ b/tests/Integration/Services/CRM/Address/Service/BatchTest.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please view the MIT-LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Lead\Service; + +use Bitrix24\SDK\Core\Exceptions\BaseException; +use Bitrix24\SDK\Core\Exceptions\TransportException; +use Bitrix24\SDK\Services\CRM\Lead\Service\Lead; +use Bitrix24\SDK\Tests\Integration\Fabric; +use PHPUnit\Framework\TestCase; + +/** + * Class BatchTest + * + * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Lead\Service + */ +class BatchTest extends TestCase +{ + protected Lead $leadService; + + /** + * @testdox Batch list leads + * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::list() + * @throws BaseException + * @throws TransportException + */ + public function testBatchList(): void + { + $itemId = $this->leadService->add(['TITLE' => 'test lead'])->getId(); + $cnt = 0; + + foreach ($this->leadService->batch->list([], ['ID' => $itemId], ['ID', 'NAME'], 1) as $item) { + $cnt++; + } + self::assertGreaterThanOrEqual(1, $cnt); + + $this->leadService->delete($itemId); + } + + /** + * @testdox Batch add lead + * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::add() + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + public function testBatchAdd(): void + { + $items = []; + for ($i = 1; $i < 60; $i++) { + $items[] = ['TITLE' => 'TITLE-' . $i]; + } + $cnt = 0; + $itemId = []; + foreach ($this->leadService->batch->add($items) as $item) { + $cnt++; + $itemId[] = $item->getId(); + } + self::assertEquals(count($items), $cnt); + + $cnt = 0; + foreach ($this->leadService->batch->delete($itemId) as $cnt => $deleteResult) { + $cnt++; + } + self::assertEquals(count($items), $cnt); + } + + /** + * @testdox Batch delete deals + * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::add() + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + public function testBatchDelete(): void + { + $deals = []; + for ($i = 1; $i < 60; $i++) { + $deals[] = ['TITLE' => 'TITLE-' . $i]; + } + $cnt = 0; + $dealId = []; + foreach ($this->leadService->batch->add($deals) as $item) { + $cnt++; + $dealId[] = $item->getId(); + } + self::assertEquals(count($deals), $cnt); + + $cnt = 0; + foreach ($this->leadService->batch->delete($dealId) as $cnt => $deleteResult) { + $cnt++; + } + self::assertEquals(count($deals), $cnt); + } + + public function setUp(): void + { + $this->leadService = Fabric::getServiceBuilder()->getCRMScope()->lead(); + } +} \ No newline at end of file From 8d3f746bff0d6beb87a37edace85b580bce01d9c Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Thu, 17 Apr 2025 10:31:22 +0400 Subject: [PATCH 06/11] make edits based on code review from 16 Apr 25 --- CHANGELOG.md | 7 +++++++ .../CRM/Address/Result/AddressItemResult.php | 13 ++----------- src/Services/CRM/Address/Result/AddressResult.php | 2 +- .../CRM/Address/Result/AddressesResult.php | 2 +- src/Services/CRM/Address/Service/Address.php | 14 ++++++++++---- src/Services/CRM/Address/Service/Batch.php | 2 +- src/Services/CRM/Enum/OwnerType.php | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f55a8d..0767b223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ ### Added +- Added service `Services\CRM\Address\Service\Address` with support methods, + see [add crm.address REST methods](https://github.com/bitrix24/b24phpsdk/issues/138): + - `list` get item list, with batch calls support + - `add` add new item, with batch calls support + - `delete` delete item, with batch calls support + - `update` update item +- Added enum `Services\CRM\Enum\OwnerType` - Added **PHP 8.4** [support](https://github.com/bitrix24/b24phpsdk/issues/120) 🚀 - Added method `Bitrix24\SDK\Services\Main\Service::guardValidateCurrentAuthToken` for validate current auth token with api-call `app.info` on vendor OAUTH server. diff --git a/src/Services/CRM/Address/Result/AddressItemResult.php b/src/Services/CRM/Address/Result/AddressItemResult.php index 6eb67f3a..86f4aaad 100644 --- a/src/Services/CRM/Address/Result/AddressItemResult.php +++ b/src/Services/CRM/Address/Result/AddressItemResult.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. @@ -35,14 +35,5 @@ */ class AddressItemResult extends AbstractCrmItem { - /** - * @param string $userfieldName - * - * @return null - * @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException - */ - public function getUserfieldByFieldName(string $userfieldName) - { - return; - } + } \ No newline at end of file diff --git a/src/Services/CRM/Address/Result/AddressResult.php b/src/Services/CRM/Address/Result/AddressResult.php index 26adb842..b8e56626 100644 --- a/src/Services/CRM/Address/Result/AddressResult.php +++ b/src/Services/CRM/Address/Result/AddressResult.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. diff --git a/src/Services/CRM/Address/Result/AddressesResult.php b/src/Services/CRM/Address/Result/AddressesResult.php index b67d9004..c686f212 100644 --- a/src/Services/CRM/Address/Result/AddressesResult.php +++ b/src/Services/CRM/Address/Result/AddressesResult.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index 6e6b1e4a..bc1b2f7c 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. @@ -91,7 +91,9 @@ public function add(array $fields): AddedItemResult * * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html * - * @param int $id + * @param int $typeId + * @param int $entityTypeId + * @param string $entityId * * @return DeletedItemResult * @throws BaseException @@ -102,13 +104,17 @@ public function add(array $fields): AddedItemResult 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html', 'Deletes the specified address.' )] - public function delete(array $fields): DeletedItemResult + public function delete(int $typeId, int $entityTypeId, string $entityId): DeletedItemResult { return new DeletedItemResult( $this->core->call( 'crm.address.delete', [ - 'fields' => $fields, + 'fields' => [ + 'TYPE_ID' => $typeId, + 'ENTITY_TYPE_ID' => $entityTypeId, + 'ENTITY_ID' => $entityId, + ], ] ) ); diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php index 7a54a07b..6adfb90f 100644 --- a/src/Services/CRM/Address/Service/Batch.php +++ b/src/Services/CRM/Address/Service/Batch.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. diff --git a/src/Services/CRM/Enum/OwnerType.php b/src/Services/CRM/Enum/OwnerType.php index 7e8f4a08..a773ed62 100644 --- a/src/Services/CRM/Enum/OwnerType.php +++ b/src/Services/CRM/Enum/OwnerType.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. From 569a262b36218fea48758d0c346318a401817c58 Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Thu, 17 Apr 2025 16:12:44 +0400 Subject: [PATCH 07/11] fix add and update methods --- CHANGELOG.md | 6 +-- Makefile | 4 ++ phpunit.xml.dist | 3 ++ src/Core/Batch.php | 26 ++++++++--- .../CRM/Address/Result/AddressesResult.php | 4 +- src/Services/CRM/Address/Service/Address.php | 10 ++--- src/Services/CRM/Address/Service/Batch.php | 44 +++++++++++++++++-- src/Services/CRM/CRMServiceBuilder.php | 13 ++++++ 8 files changed, 89 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0767b223..b9602aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - `list` get item list, with batch calls support - `add` add new item, with batch calls support - `delete` delete item, with batch calls support - - `update` update item + - `update` update item, with batch calls support - Added enum `Services\CRM\Enum\OwnerType` - Added **PHP 8.4** [support](https://github.com/bitrix24/b24phpsdk/issues/120) 🚀 - Added method `Bitrix24\SDK\Services\Main\Service::guardValidateCurrentAuthToken` for validate current auth token with @@ -19,8 +19,8 @@ see [fix entity.item.* methods](https://github.com/bitrix24/b24phpsdk/issues/53): - `get` get item, with batch calls support - `add` add new item, with batch calls support - - `delete` delete item, with batch calls support - - `update` update item, with batch calls support + - `delete` delete item + - `update` update item - Added service `Services\Entity\Service\Entity` with support methods, see [fix entity.* methods](https://github.com/bitrix24/b24phpsdk/issues/53): - `get` get entity diff --git a/Makefile b/Makefile index 14385044..15f401bb 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,10 @@ test-integration-scope-entity: .PHONY: test-integration-scope-ai-admin test-integration-scope-ai-admin: docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_ai_admin + +.PHONY: test-integration-scope-crm-address +test-integration-scope-crm-address: + docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_address # work dev environment .PHONY: php-dev-server-up diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 624b64f3..17513709 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -43,6 +43,9 @@ ./tests/Integration/Services/AI/ + + ./tests/Integration/Services/CRM/Address/ + diff --git a/src/Core/Batch.php b/src/Core/Batch.php index 1dc7d46f..4e78a6af 100644 --- a/src/Core/Batch.php +++ b/src/Core/Batch.php @@ -125,11 +125,13 @@ public function deleteEntityItems( 'additionalParameters' => $additionalParameters, ] ); + + $useFieldsInsteadOfId = in_array($apiMethod, ['crm.address.delete',]); try { $this->clearCommands(); foreach ($entityItemId as $cnt => $itemId) { - if (!is_int($itemId)) { + if (!$useFieldsInsteadOfId && !is_int($itemId)) { throw new InvalidArgumentException( sprintf( 'invalid type «%s» of entity id «%s» at position %s, entity id must be integer type', @@ -140,7 +142,8 @@ public function deleteEntityItems( ); } - $parameters = ['ID' => $itemId]; + $parameters = $useFieldsInsteadOfId ? ['fields' => $itemId] : ['ID' => $itemId]; + // TODO: delete after migration to RestAPI v2 if ($apiMethod === 'entity.item.delete') { $parameters = array_merge($parameters, $additionalParameters); } @@ -201,8 +204,11 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera try { $this->clearCommands(); + + $useFieldsInsteadOfId = in_array($apiMethod, ['crm.address.update',]); + foreach ($entityItems as $entityItemId => $entityItem) { - if (!is_int($entityItemId)) { + if (!$useFieldsInsteadOfId && !is_int($entityItemId)) { throw new InvalidArgumentException( sprintf( 'invalid type «%s» of entity id «%s», entity id must be integer type', @@ -219,10 +225,16 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera ); } - $cmdArguments = [ - 'id' => $entityItemId, - 'fields' => $entityItem['fields'] - ]; + if ($useFieldsInsteadOfId) { + $cmdArguments = [ + 'fields' => $entityItem['fields'] + ]; + } else { + $cmdArguments = [ + 'id' => $entityItemId, + 'fields' => $entityItem['fields'] + ]; + } if (array_key_exists('params', $entityItem)) { $cmdArguments['params'] = $entityItem['params']; } diff --git a/src/Services/CRM/Address/Result/AddressesResult.php b/src/Services/CRM/Address/Result/AddressesResult.php index c686f212..9ff878f2 100644 --- a/src/Services/CRM/Address/Result/AddressesResult.php +++ b/src/Services/CRM/Address/Result/AddressesResult.php @@ -18,11 +18,11 @@ use Bitrix24\SDK\Core\Result\AbstractResult; /** - * Class AddressResult + * Class AddressesResult * * @package Bitrix24\SDK\Services\CRM\Address\Result */ -class AddressResult extends AbstractResult +class AddressesResult extends AbstractResult { /** * @return AddressItemResult[] diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index bc1b2f7c..49297d75 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -53,7 +53,7 @@ public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $ * @param array{ * TYPE_ID?: int, * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: string, + * ENTITY_ID?: int, * ADDRESS_1?: string, * ADDRESS_2?: string, * CITY?: string, @@ -93,7 +93,7 @@ public function add(array $fields): AddedItemResult * * @param int $typeId * @param int $entityTypeId - * @param string $entityId + * @param int $entityId * * @return DeletedItemResult * @throws BaseException @@ -104,7 +104,7 @@ public function add(array $fields): AddedItemResult 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html', 'Deletes the specified address.' )] - public function delete(int $typeId, int $entityTypeId, string $entityId): DeletedItemResult + public function delete(int $typeId, int $entityTypeId, int $entityId): DeletedItemResult { return new DeletedItemResult( $this->core->call( @@ -181,7 +181,7 @@ public function list(array $order, array $filter, array $select, int $startItem * @param array{ * TYPE_ID?: int, * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: string, + * ENTITY_ID?: int, * ADDRESS_1?: string, * ADDRESS_2?: string, * CITY?: string, @@ -220,7 +220,7 @@ public function update(array $fields): UpdatedItemResult * @param array{ * TYPE_ID?: int, * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: string, + * ENTITY_ID?: int, * ADDRESS_1?: string, * ADDRESS_2?: string, * CITY?: string, diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php index 6adfb90f..608b3e4f 100644 --- a/src/Services/CRM/Address/Service/Batch.php +++ b/src/Services/CRM/Address/Service/Batch.php @@ -21,6 +21,7 @@ use Bitrix24\SDK\Core\Result\AddedItemBatchResult; use Bitrix24\SDK\Core\Result\DeletedItemBatchResult; use Bitrix24\SDK\Services\CRM\Address\Result\AddressItemResult; +use Bitrix24\SDK\Core\Result\UpdatedItemBatchResult; use Generator; use Psr\Log\LoggerInterface; @@ -48,7 +49,7 @@ public function __construct(BatchOperationsInterface $batch, LoggerInterface $lo * @param array{ * TYPE_ID?: int, * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: string, + * ENTITY_ID?: int, * ADDRESS_1?: string, * ADDRESS_2?: string, * CITY?: string, @@ -65,7 +66,7 @@ public function __construct(BatchOperationsInterface $batch, LoggerInterface $lo * @param array{ * TYPE_ID?: int, * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: string, + * ENTITY_ID?: int, * ADDRESS_1?: string, * ADDRESS_2?: string, * CITY?: string, @@ -111,7 +112,7 @@ public function list(array $order, array $filter, array $select, ?int $limit = n * @param array $addressKeys * * @return Generator @@ -168,4 +169,39 @@ public function delete(array $addressKeys): Generator } } + /** + * Batch update addresses + * + * @param array $fields + * + * @return Generator + * @throws BaseException + */ + #[ApiBatchMethodMetadata( + 'crm.address.update', + 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-update.html', + 'Batch update addresses' + )] + public function update(array $fields): Generator + { + foreach ($this->batch->updateEntityItems('crm.address.update', $fields) as $key => $item) { + yield $key => new UpdatedItemBatchResult($item); + } + } + } \ No newline at end of file diff --git a/src/Services/CRM/CRMServiceBuilder.php b/src/Services/CRM/CRMServiceBuilder.php index 40856782..74c58b5d 100644 --- a/src/Services/CRM/CRMServiceBuilder.php +++ b/src/Services/CRM/CRMServiceBuilder.php @@ -295,6 +295,19 @@ public function activityFetcher(): Activity\ActivityFetcherBuilder return $this->serviceCache[__METHOD__]; } + + public function address(): Address\Service\Address + { + if (!isset($this->serviceCache[__METHOD__])) { + $this->serviceCache[__METHOD__] = new Address\Service\Address( + new Address\Service\Batch($this->batch, $this->log), + $this->core, + $this->log + ); + } + + return $this->serviceCache[__METHOD__]; + } public function item(): Item\Service\Item { From a4cd5b1a66461a855c57cc86fe01bdd1541c38eb Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Mon, 21 Apr 2025 16:16:28 +0400 Subject: [PATCH 08/11] run address integration tests --- .php-cs-fixer.php | 1 + phpstan.neon.dist | 1 + rector.php | 1 + .../CRM/Address/Result/AddressItemResult.php | 5 +- .../CRM/Address/Result/AddressResult.php | 2 +- .../CRM/Address/Result/AddressesResult.php | 2 +- src/Services/CRM/Address/Service/Address.php | 5 +- src/Services/CRM/Address/Service/Batch.php | 12 +- .../CRM/Address/Service/AddressTest.php | 143 ++++++++++--- .../CRM/Address/Service/BatchTest.php | 188 ++++++++++++++---- 10 files changed, 284 insertions(+), 76 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index ce2866f3..fe20df03 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -9,6 +9,7 @@ ->in(__DIR__ . '/src/Services/CRM/VatRates/') ->in(__DIR__ . '/src/Services/CRM/Contact/') ->in(__DIR__ . '/src/Services/CRM/Requisites/') + ->in(__DIR__ . '/src/Services/CRM/Address/') ->name('*.php') ->exclude(['vendor', 'storage', 'docker', 'docs']) // Exclude directories ->ignoreDotFiles(true) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d7b241df..636aa44f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,6 +11,7 @@ parameters: - tests/Integration/Services/IMOpenLines - tests/Integration/Services/Main - tests/Integration/Services/Placement + - tests/Integration/Services/CRM bootstrapFiles: - tests/bootstrap.php parallel: diff --git a/rector.php b/rector.php index 402daf01..778fa552 100644 --- a/rector.php +++ b/rector.php @@ -30,6 +30,7 @@ __DIR__ . '/tests/Integration/Services/IM', __DIR__ . '/src/Services/IMOpenLines', __DIR__ . '/tests/Integration/Services/IMOpenLines', + __DIR__ . '/tests/Integration/Services/CRM', __DIR__ . '/src/Services/Main', __DIR__ . '/tests/Integration/Services/Main', __DIR__ . '/src/Services/Placement', diff --git a/src/Services/CRM/Address/Result/AddressItemResult.php b/src/Services/CRM/Address/Result/AddressItemResult.php index 86f4aaad..3d9d21c7 100644 --- a/src/Services/CRM/Address/Result/AddressItemResult.php +++ b/src/Services/CRM/Address/Result/AddressItemResult.php @@ -20,7 +20,7 @@ * * @property-read int $TYPE_ID * @property-read int $ENTITY_TYPE_ID - * @property-read string $ENTITY_ID + * @property-read int $ENTITY_ID * @property-read string|null $ADDRESS_1 * @property-read string|null $ADDRESS_2 * @property-read string|null $CITY @@ -35,5 +35,4 @@ */ class AddressItemResult extends AbstractCrmItem { - -} \ No newline at end of file +} diff --git a/src/Services/CRM/Address/Result/AddressResult.php b/src/Services/CRM/Address/Result/AddressResult.php index b8e56626..8209de49 100644 --- a/src/Services/CRM/Address/Result/AddressResult.php +++ b/src/Services/CRM/Address/Result/AddressResult.php @@ -30,4 +30,4 @@ public function address(): AddressItemResult { return new AddressItemResult($this->getCoreResponse()->getResponseData()->getResult()); } -} \ No newline at end of file +} diff --git a/src/Services/CRM/Address/Result/AddressesResult.php b/src/Services/CRM/Address/Result/AddressesResult.php index 9ff878f2..7ea3c8f3 100644 --- a/src/Services/CRM/Address/Result/AddressesResult.php +++ b/src/Services/CRM/Address/Result/AddressesResult.php @@ -37,4 +37,4 @@ public function getAddresses(): array return $items; } -} \ No newline at end of file +} diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index 49297d75..4e450dad 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -27,6 +27,7 @@ use Bitrix24\SDK\Services\CRM\Address\Result\AddressResult; use Bitrix24\SDK\Services\CRM\Address\Result\AddressesResult; use Psr\Log\LoggerInterface; + #[ApiServiceMetadata(new Scope(['crm']))] class Address extends AbstractService { @@ -240,6 +241,6 @@ public function update(array $fields): UpdatedItemResult */ public function countByFilter(array $filter = []): int { - return $this->list([], $filter, ['TYPE_ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); + return $this->list([], $filter, ['TYPE_ID'], -1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); } -} \ No newline at end of file +} diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php index 608b3e4f..ba71c88a 100644 --- a/src/Services/CRM/Address/Service/Batch.php +++ b/src/Services/CRM/Address/Service/Batch.php @@ -82,7 +82,7 @@ public function __construct(BatchOperationsInterface $batch, LoggerInterface $lo * @param array $select = ['TYPE_ID','ENTITY_TYPE_ID','ENTITY_ID','ADDRESS_1','ADDRESS_2','CITY','POSTAL_CODE','REGION','PROVINCE','COUNTRY','COUNTRY_CODE','LOC_ADDR_ID','ANCHOR_TYPE_ID','ANCHOR_ID'] * @param int|null $limit * - * @return Generator + * @return Generator * @throws BaseException */ #[ApiBatchMethodMetadata( @@ -168,12 +168,12 @@ public function delete(array $addressKeys): Generator yield $key => new DeletedItemBatchResult($item); } } - + /** * Batch update addresses * * @param array $fields * * @return Generator @@ -203,5 +203,5 @@ public function update(array $fields): Generator yield $key => new UpdatedItemBatchResult($item); } } - -} \ No newline at end of file + +} diff --git a/tests/Integration/Services/CRM/Address/Service/AddressTest.php b/tests/Integration/Services/CRM/Address/Service/AddressTest.php index 8b519e93..691f2133 100644 --- a/tests/Integration/Services/CRM/Address/Service/AddressTest.php +++ b/tests/Integration/Services/CRM/Address/Service/AddressTest.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. @@ -18,8 +18,11 @@ use Bitrix24\SDK\Core; use Bitrix24\SDK\Services\CRM\Address\Service\Address; use Bitrix24\SDK\Services\CRM\Address\Result\AddressItemResult; -use Bitrix24\SDK\Services\ServiceBuilder; +use Bitrix24\SDK\Services\CRM\Company\Service\Company; +use Bitrix24\SDK\Services\CRM\Requisites\Service\Requisite; use Bitrix24\SDK\Tests\Builders\Services\CRM\CompanyBuilder; +use Bitrix24\SDK\Tests\Builders\Services\CRM\RequisiteBuilder; +use Bitrix24\SDK\Services\ServiceBuilder; use Bitrix24\SDK\Services\CRM\Enum\AddressType; use Bitrix24\SDK\Services\CRM\Enum\OwnerType; @@ -46,11 +49,25 @@ class AddressTest extends TestCase protected ServiceBuilder $sb; protected Address $addressService; + protected Company $companyService; + protected Requisite $requisiteService; + protected array $addressTypes = []; + protected array $presets = []; public function setUp(): void { $this->sb = Fabric::getServiceBuilder(); - $this->addressService = Fabric::getServiceBuilder()->getCRMScope()->address(); + $this->addressService = $this->sb->getCRMScope()->address(); + $this->companyService = $this->sb->getCRMScope()->company(); + $this->requisiteService = $this->sb->getCRMScope()->requisite(); + $requisitePreset = $this->sb->getCRMScope()->requisitePreset(); + foreach ($requisitePreset->list()->getRequisitePresets() as $item) { + $this->presets[] = $item->ID; + } + $enum = $this->sb->getCRMScope()->enum(); + foreach ($enum->addressType()->getItems() as $item) { + $this->addressTypes[] = $item->ID; + } } public function testAllSystemFieldsAnnotated(): void @@ -79,13 +96,19 @@ public function testAllSystemFieldsHasValidTypeAnnotation():void */ public function testAdd(): void { - $companyId = $this->sb->getCRMScope()->company()->add((new CompanyBuilder())->build())->getId(); - self::assertEquals(1, $this->addressService->add( - [ - 'TYPE_ID' => AddressType::actual->value(), - 'ENTITY_TYPE_ID' => OwnerType::company->value(), - 'ENTITY_ID' => $companyId, - ])->getCoreResponse()->getResponseData()->getResult()[0]); + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '123, Test str.' + ]; + self::assertEquals( + 1, + $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult()[0] + ); + + $this->companyService->delete($companyId); } /** @@ -95,7 +118,23 @@ public function testAdd(): void */ public function testDelete(): void { - self::assertTrue($this->addressService->delete($this->addressService->add(['TITLE' => 'test lead'])->getId())->isSuccess()); + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => 'Test str.' + ]; + + $addRes = $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult(); + self::assertTrue( + $this->addressService->delete( + $fields['TYPE_ID'], + $fields['ENTITY_TYPE_ID'], + $fields['ENTITY_ID'] + )->isSuccess() + ); + $this->companyService->delete($companyId); } /** @@ -115,13 +154,17 @@ public function testFields(): void */ public function testList(): void { - $companyId = $this->sb->getCRMScope()->company()->add((new CompanyBuilder())->build())->getId(); - $this->addressService->add([ - 'TYPE_ID' => AddressType::actual->value(), - 'ENTITY_TYPE_ID' => OwnerType::company->value(), - 'ENTITY_ID' => $companyId, - ]); + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => 'Test str.' + ]; + $this->addressService->add($fields); self::assertGreaterThanOrEqual(1, $this->addressService->list([], [], ['TYPE_ID'])->getAddresses()); + + $this->companyService->delete($companyId); } /** @@ -131,26 +174,59 @@ public function testList(): void */ public function testUpdate(): void { - $deal = $this->addressService->add(['TITLE' => 'test lead']); - $newTitle = 'test2'; + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $address = $this->addressService->add([ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '123, Test str.' + ]); + $newAddress = 'Updated 123, Test str.'; + $newFields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => $newAddress + ]; - self::assertTrue($this->addressService->update($deal->getId(), ['TITLE' => $newTitle], [])->isSuccess()); - self::assertEquals($newTitle, $this->addressService->get($deal->getId())->lead()->TITLE); + self::assertTrue($this->addressService->update($newFields)->isSuccess()); + $filter = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + ]; + $response = $this->addressService->list( + [], + $filter, + ['ADDRESS_1'] + )->getCoreResponse()->getResponseData()->getResult()[0]['ADDRESS_1']; + self::assertEquals($newAddress, $response); + + $this->companyService->delete($companyId); } /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Deal::countByFilter + * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Address::countByFilter */ public function testCountByFilter(): void { $before = $this->addressService->countByFilter(); - $newItemsCount = 60; + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '0, Test str.' + ]; $items = []; - for ($i = 1; $i <= $newItemsCount; $i++) { - $items[] = ['TITLE' => 'TITLE-' . $i]; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $items[] = $stepFields; } $cnt = 0; foreach ($this->addressService->batch->add($items) as $item) { @@ -160,6 +236,21 @@ public function testCountByFilter(): void $after = $this->addressService->countByFilter(); - $this->assertEquals($before + $newItemsCount, $after); + $this->assertEquals($before + count($this->addressTypes), $after); + + $this->companyService->delete($companyId); + } + + protected function addCompanyAndRequisite(): array { + $companyId = $this->companyService->add((new CompanyBuilder())->build())->getId(); + $requisiteId = $this->requisiteService->add( + $companyId, + 4, + $this->presets[0], + 'Test requisite', + (new RequisiteBuilder(OwnerType::company->value, $companyId, $this->presets[0]))->build() + )->getId(); + + return [$companyId, $requisiteId]; } } \ No newline at end of file diff --git a/tests/Integration/Services/CRM/Address/Service/BatchTest.php b/tests/Integration/Services/CRM/Address/Service/BatchTest.php index 23bfd35c..f8718082 100644 --- a/tests/Integration/Services/CRM/Address/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Address/Service/BatchTest.php @@ -3,7 +3,7 @@ /** * This file is part of the bitrix24-php-sdk package. * - * © Maksim Mesilov + * © Vadim Soluyanov * * For the full copyright and license information, please view the MIT-LICENSE.txt * file that was distributed with this source code. @@ -11,96 +11,210 @@ declare(strict_types=1); -namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Lead\Service; +namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Address\Service; use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Exceptions\TransportException; -use Bitrix24\SDK\Services\CRM\Lead\Service\Lead; +use Bitrix24\SDK\Services\ServiceBuilder; +use Bitrix24\SDK\Services\CRM\Address\Service\Address; +use Bitrix24\SDK\Services\CRM\Enum\AddressType; +use Bitrix24\SDK\Services\CRM\Company\Service\Company; +use Bitrix24\SDK\Services\CRM\Requisites\Service\Requisite; +use Bitrix24\SDK\Tests\Builders\Services\CRM\CompanyBuilder; +use Bitrix24\SDK\Tests\Builders\Services\CRM\RequisiteBuilder; +use Bitrix24\SDK\Services\CRM\Enum\OwnerType; use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; /** * Class BatchTest * - * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Lead\Service + * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Address\Service */ class BatchTest extends TestCase { - protected Lead $leadService; + protected ServiceBuilder $sb; + protected Address $addressService; + protected Company $companyService; + protected Requisite $requisiteService; + protected array $addressTypes = []; + protected array $presets = []; + + public function setUp(): void + { + $this->sb = Fabric::getServiceBuilder(); + $this->addressService = $this->sb->getCRMScope()->address(); + $this->companyService = $this->sb->getCRMScope()->company(); + $this->requisiteService = $this->sb->getCRMScope()->requisite(); + $requisitePreset = $this->sb->getCRMScope()->requisitePreset(); + foreach ($requisitePreset->list()->getRequisitePresets() as $item) { + $this->presets[] = $item->ID; + } + $enum = Fabric::getServiceBuilder()->getCRMScope()->enum(); + foreach ($enum->addressType()->getItems() as $item) { + $this->addressTypes[] = $item->ID; + } + } /** - * @testdox Batch list leads - * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::list() + * @testdox Batch list addresses + * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::list() * @throws BaseException * @throws TransportException */ public function testBatchList(): void { - $itemId = $this->leadService->add(['TITLE' => 'test lead'])->getId(); + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => $this->addressTypes[1], + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '123, Test str.' + ]; + $this->addressService->add($fields); $cnt = 0; - - foreach ($this->leadService->batch->list([], ['ID' => $itemId], ['ID', 'NAME'], 1) as $item) { + $list = $this->addressService->batch->list([], ['TYPE_ID' => $this->addressTypes[1]], ['TYPE_ID'], 1); + foreach ($list as $item) { $cnt++; } self::assertGreaterThanOrEqual(1, $cnt); - - $this->leadService->delete($itemId); + + $this->companyService->delete($companyId); } /** - * @testdox Batch add lead - * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::add() + * @testdox Batch add address + * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ public function testBatchAdd(): void { + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => 0, + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '0, Test str.' + ]; + $items = []; - for ($i = 1; $i < 60; $i++) { - $items[] = ['TITLE' => 'TITLE-' . $i]; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $items[] = $stepFields; } + $cnt = 0; - $itemId = []; - foreach ($this->leadService->batch->add($items) as $item) { + foreach ($this->addressService->batch->add($items) as $item) { $cnt++; - $itemId[] = $item->getId(); } self::assertEquals(count($items), $cnt); + $this->companyService->delete($companyId); + } + + /** + * @testdox Batch delete address + * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::add() + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + public function testBatchDelete(): void + { + $items = []; + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => 0, + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '0, Test str.' + ]; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $items[] = $stepFields; + } + $cnt = 0; - foreach ($this->leadService->batch->delete($itemId) as $cnt => $deleteResult) { + foreach ($this->addressService->batch->add($items) as $item) { $cnt++; } self::assertEquals(count($items), $cnt); - } + $cnt = 0; + $items = []; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + unset($stepFields['ADDRESS_1']); + $items[] = $stepFields; + } + foreach ($this->addressService->batch->delete($items) as $cnt => $deleteResult) { + $cnt++; + } + self::assertEquals(count($items), $cnt); + + $this->companyService->delete($companyId); + } + /** - * @testdox Batch delete deals - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::add() + * @testdox Batch update address + * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::update() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ - public function testBatchDelete(): void + public function testBatchUpdate(): void { - $deals = []; - for ($i = 1; $i < 60; $i++) { - $deals[] = ['TITLE' => 'TITLE-' . $i]; + $items = []; + list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + $fields = [ + 'TYPE_ID' => 0, + 'ENTITY_TYPE_ID' => OwnerType::requisite->value, + 'ENTITY_ID' => $requisiteId, + 'ADDRESS_1' => '0, Test str.' + ]; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $items[] = $stepFields; } + $cnt = 0; - $dealId = []; - foreach ($this->leadService->batch->add($deals) as $item) { + foreach ($this->addressService->batch->add($items) as $item) { $cnt++; - $dealId[] = $item->getId(); } - self::assertEquals(count($deals), $cnt); + self::assertEquals(count($items), $cnt); $cnt = 0; - foreach ($this->leadService->batch->delete($dealId) as $cnt => $deleteResult) { + $items = []; + $newAddress1 = 'Updated address 1'; + foreach ($this->addressTypes as $typeId) { + $stepFields = $fields; + $stepFields['TYPE_ID'] = $typeId; + $stepFields['ADDRESS_1'] = $newAddress1; + $stepFields = ['fields' => $stepFields]; + + $items[] = $stepFields; + } + foreach ($this->addressService->batch->update($items) as $cnt => $updateResult) { $cnt++; } - self::assertEquals(count($deals), $cnt); + self::assertEquals(count($items), $cnt); + + $this->companyService->delete($companyId); } - - public function setUp(): void - { - $this->leadService = Fabric::getServiceBuilder()->getCRMScope()->lead(); + + protected function addCompanyAndRequisite(): array { + $companyId = $this->companyService->add((new CompanyBuilder())->build())->getId(); + $requisiteId = $this->requisiteService->add( + $companyId, + 4, + $this->presets[0], + 'Test requisite', + (new RequisiteBuilder(OwnerType::company->value, $companyId, $this->presets[0]))->build() + )->getId(); + + return [$companyId, $requisiteId]; } } \ No newline at end of file From 185b33dce3b33941fbc918f63a1f2213393ef40a Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Tue, 22 Apr 2025 13:07:13 +0400 Subject: [PATCH 09/11] run linters --- Makefile | 3 + phpunit.xml.dist | 3 + src/Core/Batch.php | 5 +- .../Contracts/BatchOperationsInterface.php | 2 +- src/Services/CRM/Address/Service/Address.php | 6 +- .../Activity/ReadModel/EmailFetcherTest.php | 6 +- .../ReadModel/OpenLineFetcherTest.php | 6 +- .../ReadModel/VoximplantFetcherTest.php | 6 +- .../Activity/ReadModel/WebFormFetcherTest.php | 6 +- .../CRM/Activity/Service/ActivityTest.php | 16 ++-- .../CRM/Activity/Service/BatchTest.php | 23 +++-- .../CRM/Address/Service/AddressTest.php | 68 ++++++++------- .../CRM/Address/Service/BatchTest.php | 83 +++++++++++-------- .../CRM/Company/Service/BatchTest.php | 15 +++- .../Company/Service/CompanyContactTest.php | 18 ++-- .../CompanyDetailsConfigurationTest.php | 7 +- .../CRM/Company/Service/CompanyTest.php | 29 ++++--- .../Company/Service/CompanyUserfieldTest.php | 50 ++++++----- .../CRM/Contact/Service/ContactBatchTest.php | 13 +-- .../Contact/Service/ContactCompanyTest.php | 22 ++--- .../CRM/Contact/Service/ContactTest.php | 20 ++--- .../Contact/Service/ContactUserfieldTest.php | 60 +++++--------- .../Service/ContactUserfieldUseCaseTest.php | 17 ++-- .../Services/CRM/Deal/Service/BatchTest.php | 25 ++++-- .../Deal/Service/DealCategoryStageTest.php | 10 +-- .../CRM/Deal/Service/DealCategoryTest.php | 26 ++---- .../CRM/Deal/Service/DealContactTest.php | 11 +-- .../CRM/Deal/Service/DealProductRowsTest.php | 23 ++--- .../Services/CRM/Deal/Service/DealTest.php | 17 ++-- .../CRM/Deal/Service/DealUserfieldTest.php | 28 +++---- .../Deal/Service/DealUserfieldUseCaseTest.php | 18 ++-- .../CRM/Duplicates/Service/DuplicateTest.php | 36 ++++---- .../Services/CRM/Enum/Service/EnumTest.php | 35 ++++---- .../Services/CRM/Lead/Service/BatchTest.php | 20 +++-- .../Services/CRM/Lead/Service/LeadTest.php | 21 ++--- .../CRM/Products/Service/ProductsTest.php | 17 ++-- .../Service/RequisitePresetTest.php | 32 +++---- .../CRM/Requisites/Service/RequisiteTest.php | 42 ++++------ .../CRM/Userfield/Service/UserfieldTest.php | 14 ++-- .../Services/CRM/VatRates/Service/VatTest.php | 35 ++++---- 40 files changed, 442 insertions(+), 452 deletions(-) diff --git a/Makefile b/Makefile index 15f401bb..971bdbf7 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,9 @@ test-integration-scope-entity: test-integration-scope-ai-admin: docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_ai_admin +.PHONY: test-integration-scope-crm +test-integration-scope-crm: + docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm .PHONY: test-integration-scope-crm-address test-integration-scope-crm-address: docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_address diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 17513709..7685854a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -43,6 +43,9 @@ ./tests/Integration/Services/AI/ + + ./tests/Integration/Services/CRM/ + ./tests/Integration/Services/CRM/Address/ diff --git a/src/Core/Batch.php b/src/Core/Batch.php index 4e78a6af..65740cec 100644 --- a/src/Core/Batch.php +++ b/src/Core/Batch.php @@ -126,7 +126,7 @@ public function deleteEntityItems( ] ); - $useFieldsInsteadOfId = in_array($apiMethod, ['crm.address.delete',]); + $useFieldsInsteadOfId = $apiMethod === 'crm.address.delete'; try { $this->clearCommands(); @@ -205,7 +205,7 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera try { $this->clearCommands(); - $useFieldsInsteadOfId = in_array($apiMethod, ['crm.address.update',]); + $useFieldsInsteadOfId = $apiMethod === 'crm.address.update'; foreach ($entityItems as $entityItemId => $entityItem) { if (!$useFieldsInsteadOfId && !is_int($entityItemId)) { @@ -235,6 +235,7 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera 'fields' => $entityItem['fields'] ]; } + if (array_key_exists('params', $entityItem)) { $cmdArguments['params'] = $entityItem['params']; } diff --git a/src/Core/Contracts/BatchOperationsInterface.php b/src/Core/Contracts/BatchOperationsInterface.php index 76bd8938..39af2248 100644 --- a/src/Core/Contracts/BatchOperationsInterface.php +++ b/src/Core/Contracts/BatchOperationsInterface.php @@ -71,7 +71,7 @@ public function addEntityItems(string $apiMethod, array $entityItems): Generator /** * Delete entity items with batch call * - * @param array $entityItemId + * @param array $entityItemId * * @return Generator|ResponseData[] * @throws BaseException diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index 4e450dad..038919ee 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -217,6 +217,10 @@ public function update(array $fields): UpdatedItemResult /** * Count Addresses by filter + * + * Meanwhile this method works with an error + * because of a bug in bx24 rest-api. + * Issue: https://github.com/bitrix24/b24phpsdk/issues/144 * * @param array{ * TYPE_ID?: int, @@ -241,6 +245,6 @@ public function update(array $fields): UpdatedItemResult */ public function countByFilter(array $filter = []): int { - return $this->list([], $filter, ['TYPE_ID'], -1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); + return $this->list([], $filter, ['TYPE_ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); } } diff --git a/tests/Integration/Services/CRM/Activity/ReadModel/EmailFetcherTest.php b/tests/Integration/Services/CRM/Activity/ReadModel/EmailFetcherTest.php index b9855548..4f0332a3 100644 --- a/tests/Integration/Services/CRM/Activity/ReadModel/EmailFetcherTest.php +++ b/tests/Integration/Services/CRM/Activity/ReadModel/EmailFetcherTest.php @@ -17,14 +17,13 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::class)] class EmailFetcherTest extends TestCase { private EmailFetcher $emailFetcher; /** - * @return void * @throws \Bitrix24\SDK\Core\Exceptions\BaseException - * @covers \Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::getList */ public function testGetListWithAllResults(): void { @@ -39,10 +38,11 @@ public function testGetListWithAllResults(): void // $item->SUBJECT, // ) . PHP_EOL); } + $this->assertTrue(true); } - public function setUp(): void + protected function setUp(): void { $this->emailFetcher = Fabric::getServiceBuilder()->getCRMScope()->activityFetcher()->emailFetcher(); } diff --git a/tests/Integration/Services/CRM/Activity/ReadModel/OpenLineFetcherTest.php b/tests/Integration/Services/CRM/Activity/ReadModel/OpenLineFetcherTest.php index c4ad949f..4548a7ee 100644 --- a/tests/Integration/Services/CRM/Activity/ReadModel/OpenLineFetcherTest.php +++ b/tests/Integration/Services/CRM/Activity/ReadModel/OpenLineFetcherTest.php @@ -17,14 +17,13 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::class)] class OpenLineFetcherTest extends TestCase { private OpenLineFetcher $openLineFetcher; /** - * @return void * @throws \Bitrix24\SDK\Core\Exceptions\BaseException - * @covers \Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::getList */ public function testGetListWithAllResults(): void { @@ -39,10 +38,11 @@ public function testGetListWithAllResults(): void // $item->SUBJECT, // ) . PHP_EOL); } + $this->assertTrue(true); } - public function setUp(): void + protected function setUp(): void { $this->openLineFetcher = Fabric::getServiceBuilder()->getCRMScope()->activityFetcher()->openLineFetcher(); } diff --git a/tests/Integration/Services/CRM/Activity/ReadModel/VoximplantFetcherTest.php b/tests/Integration/Services/CRM/Activity/ReadModel/VoximplantFetcherTest.php index 273739f3..cdb9f58a 100644 --- a/tests/Integration/Services/CRM/Activity/ReadModel/VoximplantFetcherTest.php +++ b/tests/Integration/Services/CRM/Activity/ReadModel/VoximplantFetcherTest.php @@ -18,14 +18,13 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::class)] class VoximplantFetcherTest extends TestCase { private VoximplantFetcher $voximplantFetcher; /** - * @return void * @throws \Bitrix24\SDK\Core\Exceptions\BaseException - * @covers \Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::getList */ public function testGetListWithAllResults(): void { @@ -40,10 +39,11 @@ public function testGetListWithAllResults(): void // $item->SUBJECT, // ) . PHP_EOL); } + $this->assertTrue(true); } - public function setUp(): void + protected function setUp(): void { $this->voximplantFetcher = Fabric::getServiceBuilder()->getCRMScope()->activityFetcher()->voximplantFetcher(); } diff --git a/tests/Integration/Services/CRM/Activity/ReadModel/WebFormFetcherTest.php b/tests/Integration/Services/CRM/Activity/ReadModel/WebFormFetcherTest.php index 92bc50e7..41cf8d11 100644 --- a/tests/Integration/Services/CRM/Activity/ReadModel/WebFormFetcherTest.php +++ b/tests/Integration/Services/CRM/Activity/ReadModel/WebFormFetcherTest.php @@ -17,14 +17,13 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::class)] class WebFormFetcherTest extends TestCase { private WebFormFetcher $webFormFetcher; /** - * @return void * @throws \Bitrix24\SDK\Core\Exceptions\BaseException - * @covers \Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher::getList */ public function testGetListWithAllWebFormResults(): void { @@ -39,10 +38,11 @@ public function testGetListWithAllWebFormResults(): void // $item->SUBJECT, // ) . PHP_EOL); } + $this->assertTrue(true); } - public function setUp(): void + protected function setUp(): void { $this->webFormFetcher = Fabric::getServiceBuilder()->getCRMScope()->activityFetcher()->webFormFetcher(); } diff --git a/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php b/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php index 7a05a2c0..cd217c02 100644 --- a/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php +++ b/tests/Integration/Services/CRM/Activity/Service/ActivityTest.php @@ -46,8 +46,11 @@ class ActivityTest extends TestCase use CustomBitrix24Assertions; private Activity $activityService; + private Contact $contactService; + private array $contactId; + private array $activityId; public function testAllSystemFieldsAnnotated(): void @@ -162,7 +165,6 @@ public function testDelete(): void } /** - * @covers Contact::fields * @throws BaseException * @throws TransportException */ @@ -202,7 +204,7 @@ public function testList(): void $this->activityId[] = $this->activityService->add($newActivity[$i])->getId();; } - $res = $this->activityService->list( + $activitiesResult = $this->activityService->list( ['ID' => 'DESC'], [ 'OWNER_ID' => $contactId, @@ -212,7 +214,7 @@ public function testList(): void ); - $this->assertEquals(count($newActivity), count($res->getActivities())); + $this->assertEquals(count($newActivity), count($activitiesResult->getActivities())); } /** @@ -293,15 +295,11 @@ public function testCountByFilter(): void ); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->activityService->batch->delete($this->activityId) as $result) { - } - foreach ($this->contactService->batch->delete($this->contactId) as $result) { - } } - public function setUp(): void + protected function setUp(): void { $this->activityService = Fabric::getServiceBuilder()->getCRMScope()->activity(); $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); diff --git a/tests/Integration/Services/CRM/Activity/Service/BatchTest.php b/tests/Integration/Services/CRM/Activity/Service/BatchTest.php index f2d32bd1..36978e63 100644 --- a/tests/Integration/Services/CRM/Activity/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Activity/Service/BatchTest.php @@ -21,18 +21,22 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Activity\Service\Batch::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Contact\Service\Batch::class)] class BatchTest extends TestCase { private Contact $contactService; + private Activity $activityService; + private const BATCH_TEST_ELEMENTS_COUNT = 60; + private array $contactId; /** - * @testdox Batch add deals - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch add deals')] public function testBatchAdd(): void { $contactId = $this->contactService->add(['NAME' => 'test contact'])->getId(); @@ -65,20 +69,21 @@ public function testBatchAdd(): void $cnt++; $activityId[] = $item->getId(); } + self::assertEquals(count($items), $cnt); $cnt = 0; foreach ($this->activityService->batch->delete($activityId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($items), $cnt); } /** - * @testdox Batch delete activities - * @covers \Bitrix24\SDK\Services\CRM\Activity\Service\Batch::delete() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete activities')] public function testBatchDelete(): void { $contactId = $this->contactService->add(['NAME' => 'test contact'])->getId(); @@ -111,12 +116,14 @@ public function testBatchDelete(): void $cnt++; $activityId[] = $item->getId(); } + self::assertEquals(count($items), $cnt); $cnt = 0; foreach ($this->activityService->batch->delete($activityId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($items), $cnt); @@ -131,11 +138,10 @@ public function testBatchDelete(): void } /** - * @testdox Batch list deals - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\Batch::list() * @throws BaseException * @throws TransportException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch list deals')] public function testBatchList(): void { $contactId = $this->contactService->add(['NAME' => 'test contact'])->getId(); @@ -174,6 +180,7 @@ public function testBatchList(): void foreach ($this->activityService->batch->list(['ID' => 'DESC'], ['OWNER_ID' => $contactId], ['*']) as $item) { $itemsCnt++; } + $this->assertEquals( count($activityId), $itemsCnt, @@ -185,12 +192,12 @@ public function testBatchList(): void ); } - public function tearDown(): void + protected function tearDown(): void { $this->contactService->batch->delete($this->contactId); } - public function setUp(): void + protected function setUp(): void { $this->activityService = Fabric::getServiceBuilder()->getCRMScope()->activity(); $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); diff --git a/tests/Integration/Services/CRM/Address/Service/AddressTest.php b/tests/Integration/Services/CRM/Address/Service/AddressTest.php index 691f2133..97842698 100644 --- a/tests/Integration/Services/CRM/Address/Service/AddressTest.php +++ b/tests/Integration/Services/CRM/Address/Service/AddressTest.php @@ -43,30 +43,37 @@ #[CoversMethod(Address::class,'list')] #[CoversMethod(Address::class,'fields')] #[CoversMethod(Address::class,'update')] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Address\Service\Address::class)] class AddressTest extends TestCase { use CustomBitrix24Assertions; - + protected ServiceBuilder $sb; + protected Address $addressService; + protected Company $companyService; + protected Requisite $requisiteService; + protected array $addressTypes = []; + protected array $presets = []; - - public function setUp(): void + + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $this->addressService = $this->sb->getCRMScope()->address(); $this->companyService = $this->sb->getCRMScope()->company(); $this->requisiteService = $this->sb->getCRMScope()->requisite(); $requisitePreset = $this->sb->getCRMScope()->requisitePreset(); - foreach ($requisitePreset->list()->getRequisitePresets() as $item) { - $this->presets[] = $item->ID; + foreach ($requisitePreset->list()->getRequisitePresets() as $addressTypeFieldItemResult) { + $this->presets[] = $addressTypeFieldItemResult->ID; } + $enum = $this->sb->getCRMScope()->enum(); - foreach ($enum->addressType()->getItems() as $item) { - $this->addressTypes[] = $item->ID; + foreach ($enum->addressType()->getItems() as $addressTypeFieldItemResult) { + $this->addressTypes[] = $addressTypeFieldItemResult->ID; } } @@ -80,9 +87,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation():void { $allFields = $this->addressService->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -92,11 +97,10 @@ public function testAllSystemFieldsHasValidTypeAnnotation():void /** * @throws BaseException * @throws TransportException - * @covers Address::add */ public function testAdd(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -107,26 +111,25 @@ public function testAdd(): void 1, $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult()[0] ); - + $this->companyService->delete($companyId); } /** * @throws BaseException * @throws TransportException - * @covers Address::delete */ public function testDelete(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, 'ENTITY_ID' => $requisiteId, 'ADDRESS_1' => 'Test str.' ]; - - $addRes = $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult(); + + $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult(); self::assertTrue( $this->addressService->delete( $fields['TYPE_ID'], @@ -138,7 +141,6 @@ public function testDelete(): void } /** - * @covers Address::fields * @throws BaseException * @throws TransportException */ @@ -150,11 +152,10 @@ public function testFields(): void /** * @throws BaseException * @throws TransportException - * @covers Address::list */ public function testList(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -170,12 +171,11 @@ public function testList(): void /** * @throws BaseException * @throws TransportException - * @covers Address::update */ public function testUpdate(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); - $address = $this->addressService->add([ + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); + $this->addressService->add([ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, 'ENTITY_ID' => $requisiteId, @@ -201,20 +201,21 @@ public function testUpdate(): void ['ADDRESS_1'] )->getCoreResponse()->getResponseData()->getResult()[0]['ADDRESS_1']; self::assertEquals($newAddress, $response); - + $this->companyService->delete($companyId); } /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException - * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Address::countByFilter */ + /* + // restApi bug. Issue: https://github.com/bitrix24/b24phpsdk/issues/144 public function testCountByFilter(): void { $before = $this->addressService->countByFilter(); - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -222,25 +223,28 @@ public function testCountByFilter(): void 'ADDRESS_1' => '0, Test str.' ]; $items = []; - foreach ($this->addressTypes as $typeId) { + foreach ($this->addressTypes as $addressType) { $stepFields = $fields; - $stepFields['TYPE_ID'] = $typeId; - $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $stepFields['TYPE_ID'] = $addressType; + $stepFields['ADDRESS_1'] = $addressType . $stepFields['ADDRESS_1']; $items[] = $stepFields; } + $cnt = 0; foreach ($this->addressService->batch->add($items) as $item) { $cnt++; } + self::assertEquals(count($items), $cnt); $after = $this->addressService->countByFilter(); $this->assertEquals($before + count($this->addressTypes), $after); - + $this->companyService->delete($companyId); } - + */ + protected function addCompanyAndRequisite(): array { $companyId = $this->companyService->add((new CompanyBuilder())->build())->getId(); $requisiteId = $this->requisiteService->add( @@ -250,7 +254,7 @@ protected function addCompanyAndRequisite(): array { 'Test requisite', (new RequisiteBuilder(OwnerType::company->value, $companyId, $this->presets[0]))->build() )->getId(); - + return [$companyId, $requisiteId]; } } \ No newline at end of file diff --git a/tests/Integration/Services/CRM/Address/Service/BatchTest.php b/tests/Integration/Services/CRM/Address/Service/BatchTest.php index f8718082..2c7770ad 100644 --- a/tests/Integration/Services/CRM/Address/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Address/Service/BatchTest.php @@ -31,40 +31,46 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Address\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Address\Service\Batch::class)] class BatchTest extends TestCase { protected ServiceBuilder $sb; + protected Address $addressService; + protected Company $companyService; + protected Requisite $requisiteService; + protected array $addressTypes = []; + protected array $presets = []; - - public function setUp(): void + + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $this->addressService = $this->sb->getCRMScope()->address(); $this->companyService = $this->sb->getCRMScope()->company(); $this->requisiteService = $this->sb->getCRMScope()->requisite(); $requisitePreset = $this->sb->getCRMScope()->requisitePreset(); - foreach ($requisitePreset->list()->getRequisitePresets() as $item) { - $this->presets[] = $item->ID; + foreach ($requisitePreset->list()->getRequisitePresets() as $addressTypeFieldItemResult) { + $this->presets[] = $addressTypeFieldItemResult->ID; } + $enum = Fabric::getServiceBuilder()->getCRMScope()->enum(); - foreach ($enum->addressType()->getItems() as $item) { - $this->addressTypes[] = $item->ID; + foreach ($enum->addressType()->getItems() as $addressTypeFieldItemResult) { + $this->addressTypes[] = $addressTypeFieldItemResult->ID; } } /** - * @testdox Batch list addresses - * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::list() * @throws BaseException * @throws TransportException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch list addresses')] public function testBatchList(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => $this->addressTypes[1], 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -77,52 +83,52 @@ public function testBatchList(): void foreach ($list as $item) { $cnt++; } + self::assertGreaterThanOrEqual(1, $cnt); - + $this->companyService->delete($companyId); } /** - * @testdox Batch add address - * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch add address')] public function testBatchAdd(): void { - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => 0, 'ENTITY_TYPE_ID' => OwnerType::requisite->value, 'ENTITY_ID' => $requisiteId, 'ADDRESS_1' => '0, Test str.' ]; - + $items = []; - foreach ($this->addressTypes as $typeId) { + foreach ($this->addressTypes as $addressType) { $stepFields = $fields; - $stepFields['TYPE_ID'] = $typeId; - $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; + $stepFields['TYPE_ID'] = $addressType; + $stepFields['ADDRESS_1'] = $addressType . $stepFields['ADDRESS_1']; $items[] = $stepFields; } - + $cnt = 0; foreach ($this->addressService->batch->add($items) as $item) { $cnt++; } + self::assertEquals(count($items), $cnt); $this->companyService->delete($companyId); } /** - * @testdox Batch delete address - * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete address')] public function testBatchDelete(): void { $items = []; - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => 0, 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -135,38 +141,40 @@ public function testBatchDelete(): void $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; $items[] = $stepFields; } - + $cnt = 0; foreach ($this->addressService->batch->add($items) as $item) { $cnt++; } + self::assertEquals(count($items), $cnt); $cnt = 0; $items = []; - foreach ($this->addressTypes as $typeId) { + foreach ($this->addressTypes as $addressType) { $stepFields = $fields; - $stepFields['TYPE_ID'] = $typeId; + $stepFields['TYPE_ID'] = $addressType; unset($stepFields['ADDRESS_1']); $items[] = $stepFields; } + foreach ($this->addressService->batch->delete($items) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($items), $cnt); - + $this->companyService->delete($companyId); } - + /** - * @testdox Batch update address - * @covers \Bitrix24\SDK\Services\CRM\Address\Service\Batch::update() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch update address')] public function testBatchUpdate(): void { $items = []; - list($companyId, $requisiteId) = $this->addCompanyAndRequisite(); + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); $fields = [ 'TYPE_ID' => 0, 'ENTITY_TYPE_ID' => OwnerType::requisite->value, @@ -179,32 +187,35 @@ public function testBatchUpdate(): void $stepFields['ADDRESS_1'] = $typeId . $stepFields['ADDRESS_1']; $items[] = $stepFields; } - + $cnt = 0; foreach ($this->addressService->batch->add($items) as $item) { $cnt++; } + self::assertEquals(count($items), $cnt); $cnt = 0; $items = []; $newAddress1 = 'Updated address 1'; - foreach ($this->addressTypes as $typeId) { + foreach ($this->addressTypes as $addressType) { $stepFields = $fields; - $stepFields['TYPE_ID'] = $typeId; + $stepFields['TYPE_ID'] = $addressType; $stepFields['ADDRESS_1'] = $newAddress1; $stepFields = ['fields' => $stepFields]; - + $items[] = $stepFields; } + foreach ($this->addressService->batch->update($items) as $cnt => $updateResult) { $cnt++; } + self::assertEquals(count($items), $cnt); - + $this->companyService->delete($companyId); } - + protected function addCompanyAndRequisite(): array { $companyId = $this->companyService->add((new CompanyBuilder())->build())->getId(); $requisiteId = $this->requisiteService->add( @@ -214,7 +225,7 @@ protected function addCompanyAndRequisite(): array { 'Test requisite', (new RequisiteBuilder(OwnerType::company->value, $companyId, $this->presets[0]))->build() )->getId(); - + return [$companyId, $requisiteId]; } } \ No newline at end of file diff --git a/tests/Integration/Services/CRM/Company/Service/BatchTest.php b/tests/Integration/Services/CRM/Company/Service/BatchTest.php index c9e082db..f39e8219 100644 --- a/tests/Integration/Services/CRM/Company/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Company/Service/BatchTest.php @@ -33,17 +33,16 @@ class BatchTest extends TestCase { private ServiceBuilder $sb; + private array $createdCompanies = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } } public function testBatchList(): void @@ -54,6 +53,7 @@ public function testBatchList(): void for ($i = 1; $i <= $newCompaniesCount; $i++) { $companies[] = ['TITLE' => 'TITLE-' . sprintf('Acme Inc - %s', time()), 'UTM_SOURCE' => $utmSource]; } + $cnt = 0; foreach ($this->sb->getCRMScope()->company()->batch->add($companies) as $item) { $this->createdCompanies[] = $item->getId(); @@ -66,6 +66,7 @@ public function testBatchList(): void ) { $addedCompanies[] = $item->ID; } + $this->assertEquals($newCompaniesCount, count($addedCompanies)); } @@ -77,11 +78,13 @@ public function testBatchAdd(): void for ($i = 1; $i <= $newCompaniesCount; $i++) { $companies[] = ['TITLE' => 'TITLE-' . sprintf('Acme Inc - %s', time()), 'UTM_SOURCE' => $utmSource]; } + $newCompanies = []; foreach ($this->sb->getCRMScope()->company()->batch->add($companies) as $item) { $this->createdCompanies[] = $item->getId(); $newCompanies[] = $item->getId(); } + foreach ( $this->sb->getCRMScope()->company()->batch->list([], ['UTM_SOURCE' => $utmSource], ['ID', 'TITLE']) as $item ) { @@ -99,15 +102,18 @@ public function testBatchDelete(): void for ($i = 1; $i <= $newCompaniesCount; $i++) { $companies[] = ['TITLE' => 'TITLE-' . sprintf('Acme Inc - %s', time()), 'UTM_SOURCE' => $utmSource]; } + $newCompanies = []; foreach ($this->sb->getCRMScope()->company()->batch->add($companies) as $item) { $newCompanies[] = $item->getId(); } + $deletedCnt = 0; foreach ($this->sb->getCRMScope()->company()->batch->delete($newCompanies) as $result) { $this->assertTrue($result->isSuccess()); $deletedCnt++; } + $this->assertEquals($newCompaniesCount, $deletedCnt); $this->assertEquals(0, $this->sb->getCRMScope()->company()->countByFilter(['UTM_SOURCE' => $utmSource])); } @@ -120,6 +126,7 @@ public function testBatchUpdate(): void for ($i = 1; $i <= $newCompaniesCount; $i++) { $companies[] = ['TITLE' => 'TITLE-' . sprintf('Acme Inc - %s', time()), 'UTM_SOURCE' => $utmSource]; } + $newCompanies = []; foreach ($this->sb->getCRMScope()->company()->batch->add($companies) as $item) { $this->createdCompanies[] = $item->getId(); diff --git a/tests/Integration/Services/CRM/Company/Service/CompanyContactTest.php b/tests/Integration/Services/CRM/Company/Service/CompanyContactTest.php index 335db892..1638abc6 100644 --- a/tests/Integration/Services/CRM/Company/Service/CompanyContactTest.php +++ b/tests/Integration/Services/CRM/Company/Service/CompanyContactTest.php @@ -40,20 +40,16 @@ class CompanyContactTest extends TestCase private ServiceBuilder $sb; private array $createdCompanies = []; + private array $createdContacts = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } - - foreach ($this->sb->getCRMScope()->contact()->batch->delete($this->createdContacts) as $result) { - } } public function testSet(): void @@ -74,8 +70,8 @@ public function testSet(): void $connectedId = [$contactIdOne, $contactIdTwo]; $connectedContacts = $this->sb->getCRMScope()->companyContact()->get($companyId)->getContactConnections(); - foreach ($connectedContacts as $item) { - $this->assertContains($item->CONTACT_ID, $connectedId); + foreach ($connectedContacts as $connectedContact) { + $this->assertContains($connectedContact->CONTACT_ID, $connectedId); } } @@ -107,8 +103,8 @@ public function testAdd(): void $connectedId = [$contactIdOne, $contactIdTwo]; $connectedContacts = $this->sb->getCRMScope()->companyContact()->get($companyId)->getContactConnections(); - foreach ($connectedContacts as $item) { - $this->assertContains($item->CONTACT_ID, $connectedId); + foreach ($connectedContacts as $connectedContact) { + $this->assertContains($connectedContact->CONTACT_ID, $connectedId); } } diff --git a/tests/Integration/Services/CRM/Company/Service/CompanyDetailsConfigurationTest.php b/tests/Integration/Services/CRM/Company/Service/CompanyDetailsConfigurationTest.php index da9c1ae5..3abb10e8 100644 --- a/tests/Integration/Services/CRM/Company/Service/CompanyDetailsConfigurationTest.php +++ b/tests/Integration/Services/CRM/Company/Service/CompanyDetailsConfigurationTest.php @@ -41,14 +41,15 @@ class CompanyDetailsConfigurationTest extends TestCase private ServiceBuilder $sb; private array $createdCompanies = []; + private array $createdContacts = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } - public function tearDown(): void + protected function tearDown(): void { $this->sb->getCRMScope()->companyDetailsConfiguration()->resetGeneral(); } @@ -142,7 +143,7 @@ public function testGetPersonal(): void $currentUserId = $this->sb->getMainScope()->main()->getCurrentUserProfile()->getUserProfile()->ID; - $cardConfig = $this->sb->getCRMScope()->companyDetailsConfiguration()->getGeneral($currentUserId); + $this->sb->getCRMScope()->companyDetailsConfiguration()->getGeneral(); // todo fix after we get valid cardConfig $this->assertTrue(true); diff --git a/tests/Integration/Services/CRM/Company/Service/CompanyTest.php b/tests/Integration/Services/CRM/Company/Service/CompanyTest.php index 4b43e901..307c2e1e 100644 --- a/tests/Integration/Services/CRM/Company/Service/CompanyTest.php +++ b/tests/Integration/Services/CRM/Company/Service/CompanyTest.php @@ -46,20 +46,19 @@ class CompanyTest extends TestCase use CustomBitrix24Assertions; private ServiceBuilder $sb; + private Faker\Generator $faker; private array $createdCompanies = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $this->faker = Faker\Factory::create(); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } } #[TestDox('method crm.company.fields')] @@ -75,9 +74,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->company()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -120,11 +117,11 @@ public function testAdd(): void $this->createdCompanies[] = $companyId; $this->assertGreaterThan(1, $companyId); - $addedCompany = $this->sb->getCRMScope()->company()->get($companyId)->company(); + $companyItemResult = $this->sb->getCRMScope()->company()->get($companyId)->company(); - $this->assertEquals($companyTitle, $addedCompany->TITLE); - $this->assertEquals($email, $addedCompany->EMAIL[0]->VALUE); - $this->assertEquals($phone, $addedCompany->PHONE[0]->VALUE); + $this->assertEquals($companyTitle, $companyItemResult->TITLE); + $this->assertEquals($email, $companyItemResult->EMAIL[0]->VALUE); + $this->assertEquals($phone, $companyItemResult->PHONE[0]->VALUE); } #[TestDox('method crm.company.get')] @@ -140,8 +137,8 @@ public function testGet(): void $this->createdCompanies[] = $companyId; $this->assertGreaterThan(1, $companyId); - $addedCompany = $this->sb->getCRMScope()->company()->get($companyId)->company(); - $this->assertEquals($companyTitle, $addedCompany->TITLE); + $companyItemResult = $this->sb->getCRMScope()->company()->get($companyId)->company(); + $this->assertEquals($companyTitle, $companyItemResult->TITLE); } #[TestDox('method crm.company.delete')] @@ -171,8 +168,8 @@ public function testList(): void )->getId(); $this->createdCompanies[] = $companyId; - $companies = $this->sb->getCRMScope()->company()->list(); - $this->assertGreaterThan(1, count($companies->getCompanies())); + $companiesResult = $this->sb->getCRMScope()->company()->list(); + $this->assertGreaterThan(1, count($companiesResult->getCompanies())); } #[TestDox('method crm.company.update')] @@ -200,11 +197,13 @@ public function testCountByFilter(): void for ($i = 1; $i <= $newCompaniesCount; $i++) { $companies[] = ['TITLE' => 'TITLE-' . sprintf('Acme Inc - %s', time()), 'UTM_SOURCE' => $utmSource]; } + $cnt = 0; foreach ($this->sb->getCRMScope()->company()->batch->add($companies) as $item) { $this->createdCompanies[] = $item->getId(); $cnt++; } + self::assertEquals(count($companies), $cnt); $this->assertEquals( diff --git a/tests/Integration/Services/CRM/Company/Service/CompanyUserfieldTest.php b/tests/Integration/Services/CRM/Company/Service/CompanyUserfieldTest.php index fd98f6e5..21198923 100644 --- a/tests/Integration/Services/CRM/Company/Service/CompanyUserfieldTest.php +++ b/tests/Integration/Services/CRM/Company/Service/CompanyUserfieldTest.php @@ -40,20 +40,18 @@ class CompanyUserfieldTest extends TestCase private ServiceBuilder $sb; private array $createdCompanies = []; + private array $createdUserfields = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } - - foreach ($this->createdUserfields as $fieldId) { - $this->sb->getCRMScope()->companyUserfield()->delete($fieldId); + foreach ($this->createdUserfields as $createdUserfield) { + $this->sb->getCRMScope()->companyUserfield()->delete($createdUserfield); } } @@ -68,11 +66,11 @@ public function testCompanyUserfieldAdd(array $uf): void { $fieldId = $this->sb->getCRMScope()->companyUserfield()->add($uf)->getId(); $this->createdUserfields[] = $fieldId; - $addedField = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); + $companyUserfieldItemResult = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); - $this->assertTrue(str_contains($addedField->FIELD_NAME, $uf['FIELD_NAME'])); - $this->assertEquals($uf['USER_TYPE_ID'], $addedField->USER_TYPE_ID); - $this->assertEquals($uf['XML_ID'], $addedField->XML_ID); + $this->assertTrue(str_contains($companyUserfieldItemResult->FIELD_NAME, (string) $uf['FIELD_NAME'])); + $this->assertEquals($uf['USER_TYPE_ID'], $companyUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals($uf['XML_ID'], $companyUserfieldItemResult->XML_ID); } #[TestDox('crm.company.userfield.get')] @@ -80,11 +78,11 @@ public function testCompanyUserfieldAdd(array $uf): void public function testCompanyUserfieldGet(array $uf): void { $fieldId = $this->sb->getCRMScope()->companyUserfield()->add($uf)->getId(); - $addedField = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); + $companyUserfieldItemResult = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); - $this->assertTrue(str_contains($addedField->FIELD_NAME, $uf['FIELD_NAME'])); - $this->assertEquals($uf['USER_TYPE_ID'], $addedField->USER_TYPE_ID); - $this->assertEquals($uf['XML_ID'], $addedField->XML_ID); + $this->assertTrue(str_contains($companyUserfieldItemResult->FIELD_NAME, (string) $uf['FIELD_NAME'])); + $this->assertEquals($uf['USER_TYPE_ID'], $companyUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals($uf['XML_ID'], $companyUserfieldItemResult->XML_ID); } #[TestDox('crm.company.userfield.list')] @@ -93,13 +91,13 @@ public function testCompanyUserfieldList(): void $newFields[] = (new SystemUserfieldBuilder())->build(); $newFields[] = (new SystemUserfieldBuilder('integer'))->build(); - foreach ($newFields as $field) { - $addedResult = $this->sb->getCRMScope()->companyUserfield()->add($field); + foreach ($newFields as $newField) { + $addedResult = $this->sb->getCRMScope()->companyUserfield()->add($newField); $this->createdUserfields[] = $addedResult->getId(); } - $fields = $this->sb->getCRMScope()->companyUserfield()->list(); - $this->assertGreaterThanOrEqual(2, $fields->getUserfields()); + $companyUserfieldsResult = $this->sb->getCRMScope()->companyUserfield()->list(); + $this->assertGreaterThanOrEqual(2, $companyUserfieldsResult->getUserfields()); } #[TestDox('crm.company.userfield.delete')] @@ -107,8 +105,8 @@ public function testCompanyUserfieldList(): void public function testCompanyUserfieldDelete(array $uf): void { $fieldId = $this->sb->getCRMScope()->companyUserfield()->add($uf)->getId(); - $addedField = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); - $this->assertTrue(str_contains($addedField->FIELD_NAME, $uf['FIELD_NAME'])); + $companyUserfieldItemResult = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); + $this->assertTrue(str_contains($companyUserfieldItemResult->FIELD_NAME, (string) $uf['FIELD_NAME'])); $this->assertTrue($this->sb->getCRMScope()->companyUserfield()->delete($fieldId)->isSuccess()); @@ -122,13 +120,13 @@ public function testCompanyUserfieldUpdate(array $uf): void { $fieldId = $this->sb->getCRMScope()->companyUserfield()->add($uf)->getId(); $this->createdUserfields[] = $fieldId; - $addedField = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); + $companyUserfieldItemResult = $this->sb->getCRMScope()->companyUserfield()->get($fieldId)->userfieldItem(); - $this->assertTrue(str_contains($addedField->FIELD_NAME, $uf['FIELD_NAME'])); - $this->assertEquals($uf['USER_TYPE_ID'], $addedField->USER_TYPE_ID); - $this->assertEquals($uf['XML_ID'], $addedField->XML_ID); + $this->assertTrue(str_contains($companyUserfieldItemResult->FIELD_NAME, (string) $uf['FIELD_NAME'])); + $this->assertEquals($uf['USER_TYPE_ID'], $companyUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals($uf['XML_ID'], $companyUserfieldItemResult->XML_ID); - $newXmlId = 'new' . $addedField->XML_ID; + $newXmlId = 'new' . $companyUserfieldItemResult->XML_ID; $this->assertTrue( $this->sb->getCRMScope()->companyUserfield()->update( diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactBatchTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactBatchTest.php index af252f53..b63490ae 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactBatchTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactBatchTest.php @@ -26,6 +26,7 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Contact\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Contact\Service\Batch::class)] class ContactBatchTest extends TestCase { private const TEST_SEGMENT_ELEMENTS_COUNT = 400; @@ -35,7 +36,6 @@ class ContactBatchTest extends TestCase /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\Batch::list() */ public function testBatchList(): void { @@ -45,13 +45,13 @@ public function testBatchList(): void foreach ($this->contactService->batch->list([], ['>ID' => '1'], ['ID', 'NAME'], 1) as $item) { $cnt++; } + self::assertGreaterThanOrEqual(1, $cnt); } /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\Batch::add() */ public function testBatchAdd(): void { @@ -59,6 +59,7 @@ public function testBatchAdd(): void for ($i = 1; $i < 60; $i++) { $contacts[] = ['NAME' => 'name-' . $i]; } + $cnt = 0; foreach ($this->contactService->batch->add($contacts) as $item) { $cnt++; @@ -68,9 +69,7 @@ public function testBatchAdd(): void } /** - * @return void * @throws BaseException - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\Batch::update() */ public function testBatchUpdate(): void { @@ -89,12 +88,14 @@ public function testBatchUpdate(): void ] ]; } + $cnt = 0; $contactId = []; foreach ($this->contactService->batch->add($contacts) as $item) { $cnt++; $contactId[] = $item->getId(); } + self::assertEquals(count($contacts), $cnt); // generate update data @@ -113,6 +114,7 @@ public function testBatchUpdate(): void $cnt++; $this->assertTrue($item->isSuccess()); } + self::assertEquals(count($contacts), $cnt); // delete contacts @@ -121,10 +123,11 @@ public function testBatchUpdate(): void $cnt++; $this->assertTrue($item->isSuccess()); } + self::assertEquals(count($contacts), $cnt); } - public function setUp(): void + protected function setUp(): void { $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); } diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactCompanyTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactCompanyTest.php index 7a528a3e..974ced52 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactCompanyTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactCompanyTest.php @@ -44,20 +44,16 @@ class ContactCompanyTest extends TestCase private ServiceBuilder $sb; private array $createdCompanies = []; + private array $createdContacts = []; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } - - foreach ($this->sb->getCRMScope()->contact()->batch->delete($this->createdContacts) as $result) { - } } @@ -86,9 +82,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->contactCompany()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -121,8 +115,8 @@ public function testSet(): void // read and check $companies = $this->sb->getCRMScope()->contactCompany()->get($contactId)->getCompanyConnections(); - foreach ($companies as $item) { - $this->assertContains($item->COMPANY_ID, $newCompanyId); + foreach ($companies as $company) { + $this->assertContains($company->COMPANY_ID, $newCompanyId); } } @@ -161,8 +155,8 @@ public function testAdd(): void // read and check $companies = $this->sb->getCRMScope()->contactCompany()->get($contactId)->getCompanyConnections(); - foreach ($companies as $item) { - $this->assertContains($item->COMPANY_ID, $newCompanyId); + foreach ($companies as $company) { + $this->assertContains($company->COMPANY_ID, $newCompanyId); } } diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactTest.php index a24da1f4..ae95a8b3 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactTest.php @@ -46,6 +46,7 @@ class ContactTest extends TestCase use CustomBitrix24Assertions; private Contact $contactService; + private Faker\Generator $faker; /** @@ -90,9 +91,7 @@ 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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -127,11 +126,11 @@ public function testList(): void */ public function testUpdate(): void { - $contact = $this->contactService->add(['NAME' => 'test']); + $addedItemResult = $this->contactService->add(['NAME' => 'test']); $newName = 'test2'; - self::assertTrue($this->contactService->update($contact->getId(), ['NAME' => $newName], [])->isSuccess()); - self::assertEquals($newName, $this->contactService->get($contact->getId())->contact()->NAME); + self::assertTrue($this->contactService->update($addedItemResult->getId(), ['NAME' => $newName], [])->isSuccess()); + self::assertEquals($newName, $this->contactService->get($addedItemResult->getId())->contact()->NAME); } /** @@ -149,16 +148,12 @@ public function testCountByFilter(): void $contacts[] = ['NAME' => 'name-' . $i]; } - foreach ($this->contactService->batch->add($contacts) as $item) { - } - $totalAfter = $this->contactService->countByFilter(); $this->assertEquals($totalBefore + $newContactsCount, $totalAfter); } /** - * @return void * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -179,7 +174,6 @@ public function testGetEmail(): void } /** - * @return void * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -200,7 +194,6 @@ public function testGetPhone(): void } /** - * @return void * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -221,7 +214,6 @@ public function testGetInstantMessenger(): void } /** - * @return void * @throws Core\Exceptions\TransportException * @throws Core\Exceptions\BaseException */ @@ -241,7 +233,7 @@ public function testGetWebsite(): void ])->getId())->contact()->WEB[0]->VALUE); } - public function setUp(): void + protected function setUp(): void { $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); $this->faker = Faker\Factory::create(); diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldTest.php index 13204f6c..a3a9c781 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldTest.php @@ -18,6 +18,7 @@ use Generator; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Contact\Service\ContactUserfield::class)] class ContactUserfieldTest extends TestCase { protected ContactUserfield $contactUserfieldService; @@ -25,7 +26,7 @@ class ContactUserfieldTest extends TestCase /** * @throws \Exception */ - public function systemUserfieldsDemoDataDataProvider(): Generator + public static function systemUserfieldsDemoDataDataProvider(): Generator { yield 'user type id string' => [ [ @@ -64,61 +65,47 @@ public function systemUserfieldsDemoDataDataProvider(): Generator } /** - * @param array $newUserFieldItem * * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException * @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNameIsTooLongException - * @covers ContactUserfield::add - * @dataProvider systemUserfieldsDemoDataDataProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('systemUserfieldsDemoDataDataProvider')] public function testAdd(array $newUserFieldItem): void { self::assertGreaterThanOrEqual(1, $this->contactUserfieldService->add($newUserFieldItem)->getId()); } - /** - * @param array $newUserFieldItem - * - * @dataProvider systemUserfieldsDemoDataDataProvider - * @covers ContactUserfield::delete - */ + + #[\PHPUnit\Framework\Attributes\DataProvider('systemUserfieldsDemoDataDataProvider')] public function testDelete(array $newUserFieldItem): void { $newUserfieldId = $this->contactUserfieldService->add($newUserFieldItem)->getId(); $this->assertTrue($this->contactUserfieldService->delete($newUserfieldId)->isSuccess()); } - /** - * @param array $newUserFieldItem - * - * @dataProvider systemUserfieldsDemoDataDataProvider - * @covers ContactUserfield::get - */ + + #[\PHPUnit\Framework\Attributes\DataProvider('systemUserfieldsDemoDataDataProvider')] public function testGet(array $newUserFieldItem): void { $newUserfieldId = $this->contactUserfieldService->add($newUserFieldItem)->getId(); - $ufField = $this->contactUserfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($newUserfieldId, $ufField->ID); - $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $ufField->USER_TYPE_ID); - $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $ufField->FIELD_NAME); - $this->assertEquals($newUserFieldItem['XML_ID'], $ufField->XML_ID); + $contactUserfieldItemResult = $this->contactUserfieldService->get($newUserfieldId)->userfieldItem(); + $this->assertEquals($newUserfieldId, $contactUserfieldItemResult->ID); + $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $contactUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $contactUserfieldItemResult->FIELD_NAME); + $this->assertEquals($newUserFieldItem['XML_ID'], $contactUserfieldItemResult->XML_ID); } - /** - * @param array $newUserFieldItem - * - * @dataProvider systemUserfieldsDemoDataDataProvider - * @covers ContactUserfield::update - */ + + #[\PHPUnit\Framework\Attributes\DataProvider('systemUserfieldsDemoDataDataProvider')] public function testUpdate(array $newUserFieldItem): void { $newUserfieldId = $this->contactUserfieldService->add($newUserFieldItem)->getId(); - $ufFieldBefore = $this->contactUserfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($newUserfieldId, $ufFieldBefore->ID); - $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $ufFieldBefore->USER_TYPE_ID); - $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $ufFieldBefore->FIELD_NAME); - $this->assertEquals($newUserFieldItem['XML_ID'], $ufFieldBefore->XML_ID); + $contactUserfieldItemResult = $this->contactUserfieldService->get($newUserfieldId)->userfieldItem(); + $this->assertEquals($newUserfieldId, $contactUserfieldItemResult->ID); + $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $contactUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $contactUserfieldItemResult->FIELD_NAME); + $this->assertEquals($newUserFieldItem['XML_ID'], $contactUserfieldItemResult->XML_ID); $this->assertTrue( $this->contactUserfieldService->update( @@ -130,21 +117,20 @@ public function testUpdate(array $newUserFieldItem): void ); $ufFieldAfter = $this->contactUserfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($ufFieldBefore->EDIT_FORM_LABEL['en'] . 'QQQ', $ufFieldAfter->EDIT_FORM_LABEL['en']); + $this->assertEquals($contactUserfieldItemResult->EDIT_FORM_LABEL['en'] . 'QQQ', $ufFieldAfter->EDIT_FORM_LABEL['en']); } /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\ContactUserfield::list */ public function testList(): void { - $ufFields = $this->contactUserfieldService->list([], []); - $this->assertGreaterThanOrEqual(0, count($ufFields->getUserfields())); + $contactUserfieldsResult = $this->contactUserfieldService->list([], []); + $this->assertGreaterThanOrEqual(0, count($contactUserfieldsResult->getUserfields())); } - public function setUp(): void + protected function setUp(): void { $this->contactUserfieldService = Fabric::getServiceBuilder()->getCRMScope()->contactUserfield(); } diff --git a/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldUseCaseTest.php b/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldUseCaseTest.php index e61f7ae3..2bce1080 100644 --- a/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldUseCaseTest.php +++ b/tests/Integration/Services/CRM/Contact/Service/ContactUserfieldUseCaseTest.php @@ -23,20 +23,21 @@ class ContactUserfieldUseCaseTest extends TestCase { protected Contact $contactService; + protected ContactUserfield $contactUserfieldService; + protected int $contactUserfieldId; /** * @throws BaseException * @throws TransportException - * @covers Contact::add */ public function testOperationsWithUserfieldFromContactItem(): void { // get userfield metadata - $ufMetadata = $this->contactUserfieldService->get($this->contactUserfieldId)->userfieldItem(); - $ufOriginalFieldName = $ufMetadata->getOriginalFieldName(); - $ufFieldName = $ufMetadata->FIELD_NAME; + $contactUserfieldItemResult = $this->contactUserfieldService->get($this->contactUserfieldId)->userfieldItem(); + $ufOriginalFieldName = $contactUserfieldItemResult->getOriginalFieldName(); + $ufFieldName = $contactUserfieldItemResult->FIELD_NAME; // add contact with uf value $fieldNameValue = 'test field value'; @@ -59,8 +60,8 @@ public function testOperationsWithUserfieldFromContactItem(): void ] )->isSuccess() ); - $updatedContact = $this->contactService->get($contact->ID)->contact(); - $this->assertEquals($newUfValue, $updatedContact->getUserfieldByFieldName($ufOriginalFieldName)); + $contactItemResult = $this->contactService->get($contact->ID)->contact(); + $this->assertEquals($newUfValue, $contactItemResult->getUserfieldByFieldName($ufOriginalFieldName)); } /** @@ -69,7 +70,7 @@ public function testOperationsWithUserfieldFromContactItem(): void * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ - public function setUp(): void + protected function setUp(): void { $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); $this->contactUserfieldService = Fabric::getServiceBuilder()->getCRMScope()->contactUserfield(); @@ -94,7 +95,7 @@ public function setUp(): void )->getId(); } - public function tearDown(): void + protected function tearDown(): void { $this->contactUserfieldService->delete($this->contactUserfieldId); } diff --git a/tests/Integration/Services/CRM/Deal/Service/BatchTest.php b/tests/Integration/Services/CRM/Deal/Service/BatchTest.php index 83aba611..6e1a97bb 100644 --- a/tests/Integration/Services/CRM/Deal/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/BatchTest.php @@ -24,16 +24,17 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Deals\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Contact\Service\Batch::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\Batch::class)] class BatchTest extends TestCase { protected Deal $dealService; /** - * @testdox Batch list deals - * @covers \Bitrix24\SDK\Services\CRM\Contact\Service\Batch::list() * @throws BaseException * @throws TransportException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch list deals')] public function testBatchList(): void { $dealId = $this->dealService->add(['TITLE' => 'test deal'])->getId(); @@ -42,69 +43,73 @@ public function testBatchList(): void foreach ($this->dealService->batch->list([], ['ID' => $dealId], ['ID', 'NAME'], 1) as $item) { $cnt++; } + self::assertGreaterThanOrEqual(1, $cnt); $this->dealService->delete($dealId); } /** - * @testdox Batch add deals - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch add deals')] public function testBatchAdd(): void { $deals = []; for ($i = 1; $i < 60; $i++) { $deals[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; $dealId = []; foreach ($this->dealService->batch->add($deals) as $item) { $cnt++; $dealId[] = $item->getId(); } + self::assertEquals(count($deals), $cnt); $cnt = 0; foreach ($this->dealService->batch->delete($dealId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($deals), $cnt); } /** - * @testdox Batch delete deals - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete deals')] public function testBatchDelete(): void { $deals = []; for ($i = 1; $i < 60; $i++) { $deals[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; $dealId = []; foreach ($this->dealService->batch->add($deals) as $item) { $cnt++; $dealId[] = $item->getId(); } + self::assertEquals(count($deals), $cnt); $cnt = 0; foreach ($this->dealService->batch->delete($dealId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($deals), $cnt); } /** - * @testdox Batch delete deals - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::update() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Exception */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete deals')] public function testBatchUpdate(): void { // add deals @@ -112,12 +117,14 @@ public function testBatchUpdate(): void for ($i = 1; $i < 60; $i++) { $deals[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; $dealId = []; foreach ($this->dealService->batch->add($deals) as $item) { $cnt++; $dealId[] = $item->getId(); } + self::assertEquals(count($deals), $cnt); // read deals and prepare update information @@ -148,7 +155,7 @@ public function testBatchUpdate(): void $this->assertEquals($resultDeals, $updateResult); } - public function setUp(): void + protected function setUp(): void { $this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); } diff --git a/tests/Integration/Services/CRM/Deal/Service/DealCategoryStageTest.php b/tests/Integration/Services/CRM/Deal/Service/DealCategoryStageTest.php index cbe5aa81..96ef44a0 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealCategoryStageTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealCategoryStageTest.php @@ -29,24 +29,24 @@ class DealCategoryStageTest extends TestCase { protected DealCategoryStage $dealCategoryStage; + protected DealCategory $dealCategory; /** - * @covers DealCategoryStage::list() * @throws BaseException * @throws TransportException */ public function testList(): void { - $newCategoryId = (int)$this->dealCategory->add(['NAME' => 'php unit test'])->getId(); - $res = $this->dealCategoryStage->list($newCategoryId); - $this::assertGreaterThan(1, count($res->getDealCategoryStages())); + $newCategoryId = $this->dealCategory->add(['NAME' => 'php unit test'])->getId(); + $dealCategoryStagesResult = $this->dealCategoryStage->list($newCategoryId); + $this::assertGreaterThan(1, count($dealCategoryStagesResult->getDealCategoryStages())); } /** * @throws InvalidArgumentException */ - public function setUp(): void + protected function setUp(): void { $this->dealCategoryStage = Fabric::getServiceBuilder()->getCRMScope()->dealCategoryStage(); $this->dealCategory = Fabric::getServiceBuilder()->getCRMScope()->dealCategory(); diff --git a/tests/Integration/Services/CRM/Deal/Service/DealCategoryTest.php b/tests/Integration/Services/CRM/Deal/Service/DealCategoryTest.php index 1e5aea71..0336ca1a 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealCategoryTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealCategoryTest.php @@ -24,12 +24,12 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Deals\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::class)] class DealCategoryTest extends TestCase { protected DealCategory $dealCategory; /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::add * * @throws BaseException * @throws TransportException @@ -52,7 +52,6 @@ public function testAdd(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::delete * @throws BaseException * @throws TransportException */ @@ -70,7 +69,6 @@ public function testDelete(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::fields * @throws BaseException * @throws TransportException */ @@ -80,7 +78,6 @@ public function testFields(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::getDefaultCategorySettings * @throws BaseException * @throws TransportException */ @@ -90,7 +87,6 @@ public function testDealCategoryDefaultGet(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::setDefaultCategorySettings * @throws BaseException * @throws TransportException */ @@ -103,7 +99,6 @@ public function testDealCategoryDefaultSet(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::get * @throws BaseException * @throws TransportException */ @@ -115,26 +110,24 @@ public function testDealCategoryGet(): void ]; $newCategoryId = $this->dealCategory->add($newCategory)->getId(); - $category = $this->dealCategory->get($newCategoryId); + $dealCategoryResult = $this->dealCategory->get($newCategoryId); - $this::assertEquals($newCategory['NAME'], $category->getDealCategoryFields()->NAME); - $this::assertEquals($newCategory['SORT'], $category->getDealCategoryFields()->SORT); + $this::assertEquals($newCategory['NAME'], $dealCategoryResult->getDealCategoryFields()->NAME); + $this::assertEquals($newCategory['SORT'], $dealCategoryResult->getDealCategoryFields()->SORT); } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::list * * @throws BaseException * @throws TransportException */ public function testList(): void { - $res = $this->dealCategory->list([], [], [], 0); - $this::assertGreaterThanOrEqual(1, count($res->getDealCategories())); + $dealCategoriesResult = $this->dealCategory->list([], [], [], 0); + $this::assertGreaterThanOrEqual(1, count($dealCategoriesResult->getDealCategories())); } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::getStatus * @throws BaseException * @throws TransportException */ @@ -145,12 +138,11 @@ public function testDealCategoryStatus(): void 'SORT' => 300, ]; $newCategoryId = $this->dealCategory->add($newCategory)->getId(); - $status = $this->dealCategory->getStatus($newCategoryId); - $this::assertGreaterThan(1, strlen($status->getDealCategoryTypeId())); + $dealCategoryStatusResult = $this->dealCategory->getStatus($newCategoryId); + $this::assertGreaterThan(1, strlen($dealCategoryStatusResult->getDealCategoryTypeId())); } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealCategory::update * @throws BaseException * @throws TransportException */ @@ -165,7 +157,7 @@ public function testUpdate(): void $this::assertEquals('updated', $this->dealCategory->get($newCategoryId)->getDealCategoryFields()->NAME); } - public function setUp(): void + protected function setUp(): void { $this->dealCategory = Fabric::getServiceBuilder()->getCRMScope()->dealCategory(); } diff --git a/tests/Integration/Services/CRM/Deal/Service/DealContactTest.php b/tests/Integration/Services/CRM/Deal/Service/DealContactTest.php index 3c6da9a7..99561e54 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealContactTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealContactTest.php @@ -26,14 +26,16 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Deals\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::class)] class DealContactTest extends TestCase { protected Deal $dealService; + protected Contact $contactService; + private DealContact $dealContactService; /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::add * @throws BaseException * @throws TransportException */ @@ -51,7 +53,6 @@ public function testAddWithPrimary(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::add * @throws BaseException * @throws TransportException */ @@ -70,7 +71,6 @@ public function testAddWithSecondary(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::itemsGet * @throws BaseException * @throws TransportException */ @@ -99,7 +99,6 @@ public function testItemsGet(): void /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::itemsDelete * @throws BaseException * @throws TransportException */ @@ -128,7 +127,6 @@ public function testItemsDelete(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::itemsSet * @throws BaseException * @throws TransportException */ @@ -163,7 +161,6 @@ public function testItemsSet(): void } /** - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealContact::delete * @throws BaseException * @throws TransportException */ @@ -189,7 +186,7 @@ public function testDelete(): void $this::assertCount(1, $this->dealContactService->itemsGet($dealId)->getDealContacts()); } - public function setUp(): void + protected function setUp(): void { $this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); $this->dealContactService = Fabric::getServiceBuilder()->getCRMScope()->dealContact(); diff --git a/tests/Integration/Services/CRM/Deal/Service/DealProductRowsTest.php b/tests/Integration/Services/CRM/Deal/Service/DealProductRowsTest.php index a5b73daa..f1aa8dbd 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealProductRowsTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealProductRowsTest.php @@ -29,11 +29,15 @@ use PHPUnit\Framework\TestCase; use Typhoon\Reflection\TyphoonReflector; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows::class)] class DealProductRowsTest extends TestCase { private Deal $dealService; + private DealProductRows $dealProductRowsService; + private DecimalMoneyFormatter $decimalMoneyFormatter; + private TyphoonReflector $typhoonReflector; public function testAllSystemPropertiesAnnotated(): void @@ -51,9 +55,9 @@ public function testAllSystemPropertiesAnnotated(): void // get response from server with actual keys $propListFromApi = array_keys($this->dealProductRowsService->get($dealId)->getCoreResponse()->getResponseData()->getResult()['result']['rows'][0]); // parse keys from phpdoc annotation - $props = $this->typhoonReflector->reflectClass(DealProductRowItemResult::class)->properties(); + $collection = $this->typhoonReflector->reflectClass(DealProductRowItemResult::class)->properties(); $propsFromAnnotations = []; - foreach ($props as $meta) { + foreach ($collection as $meta) { if ($meta->isAnnotated() && !$meta->isNative()) { $propsFromAnnotations[] = $meta->id->name; } @@ -69,7 +73,6 @@ public function testAllSystemPropertiesAnnotated(): void /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows::set */ public function testSet(): void { @@ -90,9 +93,9 @@ public function testSet(): void ] )->isSuccess() ); - $productRows = $this->dealProductRowsService->get($dealId); - $this->assertCount(1, $productRows->getProductRows()); - $productRow = $productRows->getProductRows()[0]; + $dealProductRowItemsResult = $this->dealProductRowsService->get($dealId); + $this->assertCount(1, $dealProductRowItemsResult->getProductRows()); + $productRow = $dealProductRowItemsResult->getProductRows()[0]; $this->assertEquals($price, $productRow->PRICE); $this->assertEquals(DiscountType::monetary, $productRow->DISCOUNT_TYPE_ID); $this->assertEquals($discount, $productRow->DISCOUNT_SUM); @@ -118,16 +121,16 @@ public function testGet(): void ] )->isSuccess() ); - $productRows = $this->dealProductRowsService->get($dealId); - $this->assertCount(1, $productRows->getProductRows()); - $productRow = $productRows->getProductRows()[0]; + $dealProductRowItemsResult = $this->dealProductRowsService->get($dealId); + $this->assertCount(1, $dealProductRowItemsResult->getProductRows()); + $productRow = $dealProductRowItemsResult->getProductRows()[0]; $this->assertEquals($price, $productRow->PRICE); $this->assertEquals(DiscountType::percentage, $productRow->DISCOUNT_TYPE_ID); $this->assertEquals($discount, $productRow->DISCOUNT_SUM); $this->assertEquals(Percentage::zero(), $productRow->DISCOUNT_RATE); } - public function setUp(): void + protected function setUp(): void { $this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); $this->dealProductRowsService = Fabric::getServiceBuilder()->getCRMScope()->dealProductRows(); diff --git a/tests/Integration/Services/CRM/Deal/Service/DealTest.php b/tests/Integration/Services/CRM/Deal/Service/DealTest.php index 35c1bbcd..364a4d54 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealTest.php @@ -27,6 +27,7 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Deals\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\Deal::class)] class DealTest extends TestCase { use CustomBitrix24Assertions; @@ -41,7 +42,6 @@ public function testAllSystemFieldsAnnotated(): void /** * @throws BaseException * @throws TransportException - * @covers Deal::add */ public function testAdd(): void { @@ -51,7 +51,6 @@ public function testAdd(): void /** * @throws BaseException * @throws TransportException - * @covers Deal::delete */ public function testDelete(): void { @@ -59,7 +58,6 @@ public function testDelete(): void } /** - * @covers Deal::fields * @throws BaseException * @throws TransportException */ @@ -71,7 +69,6 @@ public function testFields(): void /** * @throws BaseException * @throws TransportException - * @covers Deal::get */ public function testGet(): void { @@ -84,7 +81,6 @@ public function testGet(): void /** * @throws BaseException * @throws TransportException - * @covers Deal::list */ public function testList(): void { @@ -94,17 +90,16 @@ public function testList(): void public function testUpdate(): void { - $deal = $this->dealService->add(['TITLE' => 'test']); + $addedItemResult = $this->dealService->add(['TITLE' => 'test']); $newTitle = 'test2'; - self::assertTrue($this->dealService->update($deal->getId(), ['TITLE' => $newTitle], [])->isSuccess()); - self::assertEquals($newTitle, $this->dealService->get($deal->getId())->deal()->TITLE); + self::assertTrue($this->dealService->update($addedItemResult->getId(), ['TITLE' => $newTitle], [])->isSuccess()); + self::assertEquals($newTitle, $this->dealService->get($addedItemResult->getId())->deal()->TITLE); } /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Deal::countByFilter */ public function testCountByFilter(): void { @@ -115,10 +110,12 @@ public function testCountByFilter(): void for ($i = 1; $i <= $newDealsCount; $i++) { $deals[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; foreach ($this->dealService->batch->add($deals) as $item) { $cnt++; } + self::assertEquals(count($deals), $cnt); $after = $this->dealService->countByFilter(); @@ -126,7 +123,7 @@ public function testCountByFilter(): void $this->assertEquals($before + $newDealsCount, $after); } - public function setUp(): void + protected function setUp(): void { $this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); } diff --git a/tests/Integration/Services/CRM/Deal/Service/DealUserfieldTest.php b/tests/Integration/Services/CRM/Deal/Service/DealUserfieldTest.php index 37224839..5e86e380 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealUserfieldTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealUserfieldTest.php @@ -64,22 +64,22 @@ public function testDelete(array $newUserFieldItem): void public function testGet(array $newUserFieldItem): void { $newUserfieldId = $this->userfieldService->add($newUserFieldItem)->getId(); - $ufField = $this->userfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($newUserfieldId, $ufField->ID); - $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $ufField->USER_TYPE_ID); - $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $ufField->FIELD_NAME); - $this->assertEquals($newUserFieldItem['XML_ID'], $ufField->XML_ID); + $dealUserfieldItemResult = $this->userfieldService->get($newUserfieldId)->userfieldItem(); + $this->assertEquals($newUserfieldId, $dealUserfieldItemResult->ID); + $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $dealUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $dealUserfieldItemResult->FIELD_NAME); + $this->assertEquals($newUserFieldItem['XML_ID'], $dealUserfieldItemResult->XML_ID); } #[DataProvider('systemUserfieldsDemoDataDataProvider')] public function testUpdate(array $newUserFieldItem): void { $newUserfieldId = $this->userfieldService->add($newUserFieldItem)->getId(); - $ufFieldBefore = $this->userfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($newUserfieldId, $ufFieldBefore->ID); - $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $ufFieldBefore->USER_TYPE_ID); - $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $ufFieldBefore->FIELD_NAME); - $this->assertEquals($newUserFieldItem['XML_ID'], $ufFieldBefore->XML_ID); + $dealUserfieldItemResult = $this->userfieldService->get($newUserfieldId)->userfieldItem(); + $this->assertEquals($newUserfieldId, $dealUserfieldItemResult->ID); + $this->assertEquals($newUserFieldItem['USER_TYPE_ID'], $dealUserfieldItemResult->USER_TYPE_ID); + $this->assertEquals('UF_CRM_' . $newUserFieldItem['FIELD_NAME'], $dealUserfieldItemResult->FIELD_NAME); + $this->assertEquals($newUserFieldItem['XML_ID'], $dealUserfieldItemResult->XML_ID); $this->assertTrue( $this->userfieldService->update( @@ -91,16 +91,16 @@ public function testUpdate(array $newUserFieldItem): void ); $ufFieldAfter = $this->userfieldService->get($newUserfieldId)->userfieldItem(); - $this->assertEquals($ufFieldBefore->EDIT_FORM_LABEL['en'] . 'QQQ', $ufFieldAfter->EDIT_FORM_LABEL['en']); + $this->assertEquals($dealUserfieldItemResult->EDIT_FORM_LABEL['en'] . 'QQQ', $ufFieldAfter->EDIT_FORM_LABEL['en']); } public function testList(): void { - $ufFields = $this->userfieldService->list([], []); - $this->assertGreaterThanOrEqual(0, count($ufFields->getUserfields())); + $dealUserfieldsResult = $this->userfieldService->list([], []); + $this->assertGreaterThanOrEqual(0, count($dealUserfieldsResult->getUserfields())); } - public function setUp(): void + protected function setUp(): void { $this->userfieldService = Fabric::getServiceBuilder()->getCRMScope()->dealUserfield(); } diff --git a/tests/Integration/Services/CRM/Deal/Service/DealUserfieldUseCaseTest.php b/tests/Integration/Services/CRM/Deal/Service/DealUserfieldUseCaseTest.php index 4e90aa58..03984bde 100644 --- a/tests/Integration/Services/CRM/Deal/Service/DealUserfieldUseCaseTest.php +++ b/tests/Integration/Services/CRM/Deal/Service/DealUserfieldUseCaseTest.php @@ -20,23 +20,25 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\Deal::class)] class DealUserfieldUseCaseTest extends TestCase { protected Deal $dealService; + protected DealUserfield $dealUserfieldService; + protected int $dealUserfieldId; /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Deal::add */ public function testOperationsWithUserfieldFromDealItem(): void { // get userfield metadata - $ufMetadata = $this->dealUserfieldService->get($this->dealUserfieldId)->userfieldItem(); - $ufOriginalFieldName = $ufMetadata->getOriginalFieldName(); - $ufFieldName = $ufMetadata->FIELD_NAME; + $dealUserfieldItemResult = $this->dealUserfieldService->get($this->dealUserfieldId)->userfieldItem(); + $ufOriginalFieldName = $dealUserfieldItemResult->getOriginalFieldName(); + $ufFieldName = $dealUserfieldItemResult->FIELD_NAME; // add deal with uf value $fieldNameValue = 'test field value'; @@ -59,8 +61,8 @@ public function testOperationsWithUserfieldFromDealItem(): void ] )->isSuccess() ); - $updatedDeal = $this->dealService->get($deal->ID)->deal(); - $this->assertEquals($newUfValue, $updatedDeal->getUserfieldByFieldName($ufOriginalFieldName)); + $dealItemResult = $this->dealService->get($deal->ID)->deal(); + $this->assertEquals($newUfValue, $dealItemResult->getUserfieldByFieldName($ufOriginalFieldName)); } /** @@ -69,7 +71,7 @@ public function testOperationsWithUserfieldFromDealItem(): void * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ - public function setUp(): void + protected function setUp(): void { $this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal(); $this->dealUserfieldService = Fabric::getServiceBuilder()->getCRMScope()->dealUserfield(); @@ -94,7 +96,7 @@ public function setUp(): void )->getId(); } - public function tearDown(): void + protected function tearDown(): void { $this->dealUserfieldService->delete($this->dealUserfieldId); } diff --git a/tests/Integration/Services/CRM/Duplicates/Service/DuplicateTest.php b/tests/Integration/Services/CRM/Duplicates/Service/DuplicateTest.php index 18282c1f..93a87ca4 100644 --- a/tests/Integration/Services/CRM/Duplicates/Service/DuplicateTest.php +++ b/tests/Integration/Services/CRM/Duplicates/Service/DuplicateTest.php @@ -20,35 +20,33 @@ use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate::class)] class DuplicateTest extends TestCase { protected Contact $contactService; + protected Duplicate $duplicate; /** - * @return void * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate::findByEmail */ public function testDuplicatesByEmailNotFound(): void { - $res = $this->duplicate->findByEmail([sprintf('%s@gmail.com', time())]); - $this->assertFalse($res->hasDuplicateContacts()); - $this->assertFalse($res->hasOneContact()); - $this->assertCount(0, $res->getContactsId()); + $duplicateResult = $this->duplicate->findByEmail([sprintf('%s@gmail.com', time())]); + $this->assertFalse($duplicateResult->hasDuplicateContacts()); + $this->assertFalse($duplicateResult->hasOneContact()); + $this->assertCount(0, $duplicateResult->getContactsId()); } /** - * @return void * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate::findByEmail */ public function testDuplicatesByEmailOneItemFound(): void { $email = sprintf('%s@gmail.com', time()); - $b24ContactId = $this->contactService->add([ + $this->contactService->add([ 'NAME' => 'Test', 'LAST_NAME' => 'Test', 'EMAIL' => [ @@ -59,28 +57,26 @@ public function testDuplicatesByEmailOneItemFound(): void ] ])->getId(); - $res = $this->duplicate->findByEmail([$email]); - $this->assertFalse($res->hasDuplicateContacts()); - $this->assertTrue($res->hasOneContact()); - $this->assertCount(1, $res->getContactsId()); + $duplicateResult = $this->duplicate->findByEmail([$email]); + $this->assertFalse($duplicateResult->hasDuplicateContacts()); + $this->assertTrue($duplicateResult->hasOneContact()); + $this->assertCount(1, $duplicateResult->getContactsId()); } /** - * @return void * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate::findByPhone */ public function testDuplicatesByPhoneNotFound(): void { - $res = $this->duplicate->findByPhone([sprintf('+1%s', time())]); - $this->assertFalse($res->hasDuplicateContacts()); - $this->assertFalse($res->hasOneContact()); - $this->assertCount(0, $res->getContactsId()); + $duplicateResult = $this->duplicate->findByPhone([sprintf('+1%s', time())]); + $this->assertFalse($duplicateResult->hasDuplicateContacts()); + $this->assertFalse($duplicateResult->hasOneContact()); + $this->assertCount(0, $duplicateResult->getContactsId()); } - public function setUp(): void + protected function setUp(): void { $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); $this->duplicate = Fabric::getServiceBuilder()->getCRMScope()->duplicate(); diff --git a/tests/Integration/Services/CRM/Enum/Service/EnumTest.php b/tests/Integration/Services/CRM/Enum/Service/EnumTest.php index 0f21ca76..59acf968 100644 --- a/tests/Integration/Services/CRM/Enum/Service/EnumTest.php +++ b/tests/Integration/Services/CRM/Enum/Service/EnumTest.php @@ -42,56 +42,57 @@ public function testOwnerType(): void public function testActivityStatus(): void { - foreach ($this->enumService->activityStatus()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->activityStatus()->getItems() as $activityStatusItemResult) { + $this->assertEquals($activityStatusItemResult->ID, $activityStatusItemResult->ENUM->value); } } public function testAddressType(): void { - foreach ($this->enumService->addressType()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->addressType()->getItems() as $addressTypeFieldItemResult) { + $this->assertEquals($addressTypeFieldItemResult->ID, $addressTypeFieldItemResult->ENUM->value); } } + public function testActivityNotifyType(): void { - foreach ($this->enumService->activityNotifyType()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->activityNotifyType()->getItems() as $activityNotifyTypeItemResult) { + $this->assertEquals($activityNotifyTypeItemResult->ID, $activityNotifyTypeItemResult->ENUM->value); } } public function testActivityPriority(): void { - foreach ($this->enumService->activityPriority()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->activityPriority()->getItems() as $activityPriorityTypeItemResult) { + $this->assertEquals($activityPriorityTypeItemResult->ID, $activityPriorityTypeItemResult->ENUM->value); } } public function testActivityDirection(): void { - foreach ($this->enumService->activityDirection()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->activityDirection()->getItems() as $activityDirectionItemResult) { + $this->assertEquals($activityDirectionItemResult->ID, $activityDirectionItemResult->ENUM->value); } } public function testActivityType(): void { - foreach ($this->enumService->activityType()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->activityType()->getItems() as $activityTypeItemResult) { + $this->assertEquals($activityTypeItemResult->ID, $activityTypeItemResult->ENUM->value); } } public function testSettingsMode(): void { - foreach ($this->enumService->settingsMode()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->settingsMode()->getItems() as $contentTypeItemResult) { + $this->assertEquals($contentTypeItemResult->ID, $contentTypeItemResult->ENUM->value); } } public function testContentType(): void { - foreach ($this->enumService->contentType()->getItems() as $item) { - $this->assertEquals($item->ID, $item->ENUM->value); + foreach ($this->enumService->contentType()->getItems() as $contentTypeItemResult) { + $this->assertEquals($contentTypeItemResult->ID, $contentTypeItemResult->ENUM->value); } } @@ -105,7 +106,7 @@ public function testFields(): void $this->assertGreaterThan(1, count($this->enumService->fields()->getFieldsDescription())); } - public function setUp(): void + protected function setUp(): void { $this->enumService = Fabric::getServiceBuilder()->getCRMScope()->enum(); } diff --git a/tests/Integration/Services/CRM/Lead/Service/BatchTest.php b/tests/Integration/Services/CRM/Lead/Service/BatchTest.php index 23bfd35c..1ba7c716 100644 --- a/tests/Integration/Services/CRM/Lead/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Lead/Service/BatchTest.php @@ -24,16 +24,17 @@ * * @package Bitrix24\SDK\Tests\Integration\Services\CRM\Lead\Service */ +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Lead\Service\Batch::class)] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\Batch::class)] class BatchTest extends TestCase { protected Lead $leadService; /** - * @testdox Batch list leads - * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::list() * @throws BaseException * @throws TransportException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch list leads')] public function testBatchList(): void { $itemId = $this->leadService->add(['TITLE' => 'test lead'])->getId(); @@ -42,64 +43,69 @@ public function testBatchList(): void foreach ($this->leadService->batch->list([], ['ID' => $itemId], ['ID', 'NAME'], 1) as $item) { $cnt++; } + self::assertGreaterThanOrEqual(1, $cnt); $this->leadService->delete($itemId); } /** - * @testdox Batch add lead - * @covers \Bitrix24\SDK\Services\CRM\Lead\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch add lead')] public function testBatchAdd(): void { $items = []; for ($i = 1; $i < 60; $i++) { $items[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; $itemId = []; foreach ($this->leadService->batch->add($items) as $item) { $cnt++; $itemId[] = $item->getId(); } + self::assertEquals(count($items), $cnt); $cnt = 0; foreach ($this->leadService->batch->delete($itemId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($items), $cnt); } /** - * @testdox Batch delete deals - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Batch::add() * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete deals')] public function testBatchDelete(): void { $deals = []; for ($i = 1; $i < 60; $i++) { $deals[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; $dealId = []; foreach ($this->leadService->batch->add($deals) as $item) { $cnt++; $dealId[] = $item->getId(); } + self::assertEquals(count($deals), $cnt); $cnt = 0; foreach ($this->leadService->batch->delete($dealId) as $cnt => $deleteResult) { $cnt++; } + self::assertEquals(count($deals), $cnt); } - public function setUp(): void + protected function setUp(): void { $this->leadService = Fabric::getServiceBuilder()->getCRMScope()->lead(); } diff --git a/tests/Integration/Services/CRM/Lead/Service/LeadTest.php b/tests/Integration/Services/CRM/Lead/Service/LeadTest.php index 2c356d7a..684a33c8 100644 --- a/tests/Integration/Services/CRM/Lead/Service/LeadTest.php +++ b/tests/Integration/Services/CRM/Lead/Service/LeadTest.php @@ -36,6 +36,7 @@ #[CoversMethod(Lead::class,'list')] #[CoversMethod(Lead::class,'fields')] #[CoversMethod(Lead::class,'update')] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Deal\Service\Deal::class)] class LeadTest extends TestCase { use CustomBitrix24Assertions; @@ -51,9 +52,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation():void { $allFields = $this->leadService->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -72,7 +71,6 @@ public function testAdd(): void /** * @throws BaseException * @throws TransportException - * @covers Lead::delete */ public function testDelete(): void { @@ -80,7 +78,6 @@ public function testDelete(): void } /** - * @covers Lead::fields * @throws BaseException * @throws TransportException */ @@ -92,7 +89,6 @@ public function testFields(): void /** * @throws BaseException * @throws TransportException - * @covers Lead::get */ public function testGet(): void { @@ -105,7 +101,6 @@ public function testGet(): void /** * @throws BaseException * @throws TransportException - * @covers Lead::list */ public function testList(): void { @@ -116,21 +111,19 @@ public function testList(): void /** * @throws BaseException * @throws TransportException - * @covers Lead::update */ public function testUpdate(): void { - $deal = $this->leadService->add(['TITLE' => 'test lead']); + $addedItemResult = $this->leadService->add(['TITLE' => 'test lead']); $newTitle = 'test2'; - self::assertTrue($this->leadService->update($deal->getId(), ['TITLE' => $newTitle], [])->isSuccess()); - self::assertEquals($newTitle, $this->leadService->get($deal->getId())->lead()->TITLE); + self::assertTrue($this->leadService->update($addedItemResult->getId(), ['TITLE' => $newTitle], [])->isSuccess()); + self::assertEquals($newTitle, $this->leadService->get($addedItemResult->getId())->lead()->TITLE); } /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException - * @covers \Bitrix24\SDK\Services\CRM\Deal\Service\Deal::countByFilter */ public function testCountByFilter(): void { @@ -141,10 +134,12 @@ public function testCountByFilter(): void for ($i = 1; $i <= $newItemsCount; $i++) { $items[] = ['TITLE' => 'TITLE-' . $i]; } + $cnt = 0; foreach ($this->leadService->batch->add($items) as $item) { $cnt++; } + self::assertEquals(count($items), $cnt); $after = $this->leadService->countByFilter(); @@ -152,7 +147,7 @@ public function testCountByFilter(): void $this->assertEquals($before + $newItemsCount, $after); } - public function setUp(): void + protected function setUp(): void { $this->leadService = Fabric::getServiceBuilder()->getCRMScope()->lead(); } diff --git a/tests/Integration/Services/CRM/Products/Service/ProductsTest.php b/tests/Integration/Services/CRM/Products/Service/ProductsTest.php index 91c548fe..c75de7b2 100644 --- a/tests/Integration/Services/CRM/Products/Service/ProductsTest.php +++ b/tests/Integration/Services/CRM/Products/Service/ProductsTest.php @@ -33,6 +33,7 @@ #[CoversMethod(Product::class,'fields')] #[CoversMethod(Product::class,'update')] #[CoversMethod(Product::class,'countByFilter')] +#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Services\CRM\Product\Service\Product::class)] class ProductsTest extends TestCase { use CustomBitrix24Assertions; @@ -51,9 +52,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->productService->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -113,7 +112,6 @@ public function testFields(): void /** * @throws BaseException * @throws TransportException - * @covers \Bitrix24\SDK\Services\CRM\Product\Service\Product::list */ public function testList(): void { @@ -127,11 +125,11 @@ public function testList(): void */ public function testUpdate(): void { - $product = $this->productService->add(['NAME' => 'test']); + $addedItemResult = $this->productService->add(['NAME' => 'test']); $newName = 'test2'; - self::assertTrue($this->productService->update($product->getId(), ['NAME' => $newName])->isSuccess()); - self::assertEquals($newName, $this->productService->get($product->getId())->product()->NAME); + self::assertTrue($this->productService->update($addedItemResult->getId(), ['NAME' => $newName])->isSuccess()); + self::assertEquals($newName, $this->productService->get($addedItemResult->getId())->product()->NAME); } /** @@ -146,6 +144,7 @@ public function testBatchList(): void foreach ($this->productService->batch->list([], ['>ID' => '1'], ['ID', 'NAME'], 1) as $item) { $cnt++; } + self::assertGreaterThanOrEqual(1, $cnt); } @@ -155,6 +154,7 @@ public function testBatchAdd(): void for ($i = 1; $i < 60; $i++) { $products[] = ['NAME' => 'NAME-' . $i]; } + $cnt = 0; foreach ($this->productService->batch->add($products) as $item) { $cnt++; @@ -175,6 +175,7 @@ public function testCountByFilter(): void for ($i = 1; $i <= $newProductsCount; $i++) { $products[] = ['NAME' => 'NAME-' . $i]; } + $cnt = 0; foreach ($this->productService->batch->add($products) as $item) { $cnt++; @@ -186,7 +187,7 @@ public function testCountByFilter(): void $this->assertEquals($productsCountBefore + $newProductsCount, $productsCountAfter); } - public function setUp(): void + protected function setUp(): void { $this->productService = Fabric::getServiceBuilder()->getCRMScope()->product(); } diff --git a/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php b/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php index 28ebe38b..f4fc06c5 100644 --- a/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php +++ b/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php @@ -46,47 +46,43 @@ class RequisitePresetTest extends TestCase use CustomBitrix24Assertions; protected ServiceBuilder $sb; + private array $createdCompanies = []; + private int $requisitePresetId; + private int $entityTypeRequisiteId; + private int $countryId; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $this->requisitePresetId = current( array_filter( $this->sb->getCRMScope()->requisitePreset()->list()->getRequisitePresets(), - function ($item) { - return str_contains($item->XML_ID, 'COMPANY#'); - } + fn($item): bool => str_contains($item->XML_ID, 'COMPANY#') ) )->ID; $this->entityTypeRequisiteId = current( array_filter( $this->sb->getCRMScope()->enum()->ownerType()->getItems(), - function ($item) { - return $item->SYMBOL_CODE === 'REQUISITE'; - } + fn($item): bool => $item->SYMBOL_CODE === 'REQUISITE' ) )->ID; $this->countryId = current( array_column( array_filter( $this->sb->getCRMScope()->requisitePreset()->countries()->getCountries(), - function ($item) { - return $item->CODE === 'US'; - } + fn($item): bool => $item->CODE === 'US' ), 'ID' ) ); } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } } public function testFields(): void @@ -106,9 +102,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->requisitePreset()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation($systemFields, RequisitePresetItemResult::class); } @@ -136,8 +130,8 @@ public function testAdd(): void 'ACTIVE' => 'Y', ] )->getId(); - $addedItem = $this->sb->getCRMScope()->requisitePreset()->get($tplId)->requisitePreset(); - $this->assertEquals($name, $addedItem->NAME); + $requisitePresetItemResult = $this->sb->getCRMScope()->requisitePreset()->get($tplId)->requisitePreset(); + $this->assertEquals($name, $requisitePresetItemResult->NAME); $this->assertTrue($this->sb->getCRMScope()->requisitePreset()->delete($tplId)->isSuccess()); } @@ -156,7 +150,7 @@ public function testDelete(): void $this->assertTrue($this->sb->getCRMScope()->requisitePreset()->delete($tplId)->isSuccess()); $this->expectException(ItemNotFoundException::class); - $addedReq = $this->sb->getCRMScope()->requisitePreset()->get($tplId)->requisite(); + $this->sb->getCRMScope()->requisitePreset()->get($tplId)->requisite(); } public function testUpdate(): void diff --git a/tests/Integration/Services/CRM/Requisites/Service/RequisiteTest.php b/tests/Integration/Services/CRM/Requisites/Service/RequisiteTest.php index 2596b06c..f7a6e5fc 100644 --- a/tests/Integration/Services/CRM/Requisites/Service/RequisiteTest.php +++ b/tests/Integration/Services/CRM/Requisites/Service/RequisiteTest.php @@ -42,38 +42,34 @@ class RequisiteTest extends TestCase use CustomBitrix24Assertions; protected ServiceBuilder $sb; + private array $createdCompanies = []; + private array $createdRequisites = []; + private int $requisitePresetId; + private int $entityTypeIdCompany; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $this->requisitePresetId = current( array_filter( $this->sb->getCRMScope()->requisitePreset()->list()->getRequisitePresets(), - function ($item) { - return str_contains($item->XML_ID, 'COMPANY#'); - } + fn($item): bool => str_contains($item->XML_ID, 'COMPANY#') ) )->ID; $this->entityTypeIdCompany = current( array_filter( $this->sb->getCRMScope()->enum()->ownerType()->getItems(), - function ($item) { - return $item->SYMBOL_CODE === 'COMPANY'; - } + fn($item): bool => $item->SYMBOL_CODE === 'COMPANY' ) )->ID; } - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->sb->getCRMScope()->requisite()->batch->delete($this->createdRequisites) as $result) { - } - foreach ($this->sb->getCRMScope()->company()->batch->delete($this->createdCompanies) as $result) { - } } public function testFields(): void @@ -93,9 +89,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->requisite()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation($systemFields, RequisiteItemResult::class); } @@ -116,11 +110,11 @@ public function testAdd(): void )->getId(); $this->createdRequisites[] = $reqId; - $addedReq = $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); + $requisiteItemResult = $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); - $this->assertEquals($reqName, $addedReq->NAME); - $this->assertEquals($this->entityTypeIdCompany, $addedReq->ENTITY_TYPE_ID); - $this->assertEquals($this->requisitePresetId, $addedReq->PRESET_ID); + $this->assertEquals($reqName, $requisiteItemResult->NAME); + $this->assertEquals($this->entityTypeIdCompany, $requisiteItemResult->ENTITY_TYPE_ID); + $this->assertEquals($this->requisitePresetId, $requisiteItemResult->PRESET_ID); } public function testDelete(): void @@ -141,7 +135,7 @@ public function testDelete(): void $this->assertTrue($this->sb->getCRMScope()->requisite()->delete($reqId)->isSuccess()); $this->expectException(ItemNotFoundException::class); - $addedReq = $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); + $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); } public function testList(): void @@ -185,11 +179,11 @@ public function testUpdate(): void )->getId(); $this->createdRequisites[] = $reqId; - $addedReq = $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); + $requisiteItemResult = $this->sb->getCRMScope()->requisite()->get($reqId)->requisite(); - $this->assertEquals($reqName, $addedReq->NAME); - $this->assertEquals($this->entityTypeIdCompany, $addedReq->ENTITY_TYPE_ID); - $this->assertEquals($this->requisitePresetId, $addedReq->PRESET_ID); + $this->assertEquals($reqName, $requisiteItemResult->NAME); + $this->assertEquals($this->entityTypeIdCompany, $requisiteItemResult->ENTITY_TYPE_ID); + $this->assertEquals($this->requisitePresetId, $requisiteItemResult->PRESET_ID); $newName = 'new name'; $this->assertTrue($this->sb->getCRMScope()->requisite()->update($reqId, ['NAME' => $newName])->isSuccess()); diff --git a/tests/Integration/Services/CRM/Userfield/Service/UserfieldTest.php b/tests/Integration/Services/CRM/Userfield/Service/UserfieldTest.php index 2cd3c0fa..0c08afbb 100644 --- a/tests/Integration/Services/CRM/Userfield/Service/UserfieldTest.php +++ b/tests/Integration/Services/CRM/Userfield/Service/UserfieldTest.php @@ -60,9 +60,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->userfield()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -85,8 +83,8 @@ public function testEnumerationFields(): void */ public function testSettingsFields(): void { - foreach ($this->sb->getCRMScope()->userfield()->types()->getTypes() as $typeItem) { - self::assertIsArray($this->sb->getCRMScope()->userfield()->settingsFields($typeItem->ID)->getFieldsDescription()); + foreach ($this->sb->getCRMScope()->userfield()->types()->getTypes() as $userfieldTypeItemResult) { + self::assertIsArray($this->sb->getCRMScope()->userfield()->settingsFields($userfieldTypeItemResult->ID)->getFieldsDescription()); } } @@ -96,11 +94,11 @@ public function testSettingsFields(): void */ public function testTypes(): void { - $ufTypes = $this->sb->getCRMScope()->userfield()->types(); - $this->assertGreaterThan(10, $ufTypes->getTypes()); + $userfieldTypesResult = $this->sb->getCRMScope()->userfield()->types(); + $this->assertGreaterThan(10, $userfieldTypesResult->getTypes()); } - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } diff --git a/tests/Integration/Services/CRM/VatRates/Service/VatTest.php b/tests/Integration/Services/CRM/VatRates/Service/VatTest.php index 1accadc5..3cdfca59 100644 --- a/tests/Integration/Services/CRM/VatRates/Service/VatTest.php +++ b/tests/Integration/Services/CRM/VatRates/Service/VatTest.php @@ -39,16 +39,17 @@ class VatTest extends TestCase use CustomBitrix24Assertions; private ServiceBuilder $sb; + private array $addedVatRates = []; - public function tearDown(): void + protected function tearDown(): void { - foreach ($this->addedVatRates as $rateId) { - $this->sb->getCRMScope()->vat()->delete($rateId); + foreach ($this->addedVatRates as $addedVatRate) { + $this->sb->getCRMScope()->vat()->delete($addedVatRate); } } - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); } @@ -75,9 +76,7 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void { $allFields = $this->sb->getCRMScope()->vat()->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); + $systemFields = array_filter($allFields, static fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( $systemFields, @@ -88,19 +87,19 @@ public function testAllSystemFieldsHasValidTypeAnnotation(): void public function testAddAndGet(): void { $name = sprintf('test vat name %s', time()); - $rate = new Percentage((string)random_int(1, 99)); + $percentage = new Percentage((string)random_int(1, 99)); $sort = random_int(1, 500); $isActive = (bool)random_int(0, 1); - $newVatRateId = $this->sb->getCRMScope()->vat()->add($name, $rate, $sort, $isActive)->getId(); + $newVatRateId = $this->sb->getCRMScope()->vat()->add($name, $percentage, $sort, $isActive)->getId(); $this->addedVatRates[] = $newVatRateId; - $addedRate = $this->sb->getCRMScope()->vat()->get($newVatRateId)->getRate(); + $vatRateItemResult = $this->sb->getCRMScope()->vat()->get($newVatRateId)->getRate(); - $this->assertEquals($name, $addedRate->NAME); - $this->assertTrue($rate->equals($addedRate->RATE)); - $this->assertEquals($sort, $addedRate->C_SORT); - $this->assertEquals($isActive, $addedRate->ACTIVE); + $this->assertEquals($name, $vatRateItemResult->NAME); + $this->assertTrue($percentage->equals($vatRateItemResult->RATE)); + $this->assertEquals($sort, $vatRateItemResult->C_SORT); + $this->assertEquals($isActive, $vatRateItemResult->ACTIVE); } public function testDelete(): void @@ -124,8 +123,8 @@ public function testUpdateWithoutParameters(): void public function testUpdate(): void { $title = sprintf('test vat name %s', time()); - $rate = new Percentage((string)random_int(20, 30)); - $newVatRateId = $this->sb->getCRMScope()->vat()->add($title, $rate)->getId(); + $percentage = new Percentage((string)random_int(20, 30)); + $newVatRateId = $this->sb->getCRMScope()->vat()->add($title, $percentage)->getId(); $this->addedVatRates[] = $newVatRateId; $newTitle = 'new' . $title; @@ -136,8 +135,8 @@ public function testUpdate(): void )->isSuccess() ); - $updated = $this->sb->getCRMScope()->vat()->get($newVatRateId)->getRate(); - $this->assertEquals($newTitle, $updated->NAME); + $vatRateItemResult = $this->sb->getCRMScope()->vat()->get($newVatRateId)->getRate(); + $this->assertEquals($newTitle, $vatRateItemResult->NAME); } public function testList(): void From f1deec3d5f92a43f5e4c88e358958f5ddcd5b73c Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Mon, 2 Jun 2025 09:55:32 +0400 Subject: [PATCH 10/11] run linters --- phpstan.neon.dist | 3 +-- rector.php | 7 ++----- src/Services/CRM/Address/Service/Address.php | 22 +++----------------- src/Services/CRM/Address/Service/Batch.php | 12 ++--------- 4 files changed, 8 insertions(+), 36 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index de035e06..33086344 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,8 +11,7 @@ parameters: - tests/Integration/Services/IMOpenLines - tests/Integration/Services/Main - tests/Integration/Services/Placement - - tests/Integration/Services/CRM - - tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php + - tests/Integration/Services/CRM/Address bootstrapFiles: - tests/bootstrap.php diff --git a/rector.php b/rector.php index b0c4fb1a..90bcf0f6 100644 --- a/rector.php +++ b/rector.php @@ -30,15 +30,12 @@ __DIR__ . '/tests/Integration/Services/IM', __DIR__ . '/src/Services/IMOpenLines', __DIR__ . '/tests/Integration/Services/IMOpenLines', - __DIR__ . '/tests/Integration/Services/CRM', - __DIR__ . '/src/Services/CRM/Automation', - __DIR__ . '/tests/Integration/Services/CRM/Automation', + __DIR__ . '/src/Services/CRM/Address', + __DIR__ . '/tests/Integration/Services/CRM/Address', __DIR__ . '/src/Services/Main', __DIR__ . '/tests/Integration/Services/Main', __DIR__ . '/src/Services/Placement', __DIR__ . '/tests/Integration/Services/Placement', - __DIR__ . '/src/Services/CRM/Deal', - __DIR__ . '/tests/Integration/Services/CRM/Deal/Service', __DIR__ . '/tests/Unit/', ]) ->withCache(cacheDirectory: __DIR__ . '.cache/rector') diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php index 038919ee..15fb7576 100644 --- a/src/Services/CRM/Address/Service/Address.php +++ b/src/Services/CRM/Address/Service/Address.php @@ -31,19 +31,12 @@ #[ApiServiceMetadata(new Scope(['crm']))] class Address extends AbstractService { - public Batch $batch; - /** * Address constructor. - * - * @param Batch $batch - * @param CoreInterface $core - * @param LoggerInterface $log */ - public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $log) + public function __construct(public Batch $batch, CoreInterface $core, LoggerInterface $logger) { - parent::__construct($core, $log); - $this->batch = $batch; + parent::__construct($core, $logger); } /** @@ -66,7 +59,6 @@ public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $ * LOC_ADDR_ID?: int, * } $fields * - * @return AddedItemResult * @throws BaseException * @throws TransportException */ @@ -92,11 +84,7 @@ public function add(array $fields): AddedItemResult * * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-delete.html * - * @param int $typeId - * @param int $entityTypeId - * @param int $entityId * - * @return DeletedItemResult * @throws BaseException * @throws TransportException */ @@ -126,7 +114,6 @@ public function delete(int $typeId, int $entityTypeId, int $entityId): DeletedIt * * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-fields.html * - * @return FieldsResult * @throws BaseException * @throws TransportException */ @@ -152,7 +139,6 @@ public function fields(): FieldsResult * * @throws BaseException * @throws TransportException - * @return AddressesResult */ #[ApiEndpointMetadata( 'crm.address.list', @@ -194,7 +180,6 @@ public function list(array $order, array $filter, array $select, int $startItem * LOC_ADDR_ID?: int, * } $fields * - * @return UpdatedItemResult * @throws BaseException * @throws TransportException */ @@ -217,7 +202,7 @@ public function update(array $fields): UpdatedItemResult /** * Count Addresses by filter - * + * * Meanwhile this method works with an error * because of a bug in bx24 rest-api. * Issue: https://github.com/bitrix24/b24phpsdk/issues/144 @@ -239,7 +224,6 @@ public function update(array $fields): UpdatedItemResult * ANCHOR_ID?: int, * } $filter * - * @return int * @throws \Bitrix24\SDK\Core\Exceptions\BaseException * @throws \Bitrix24\SDK\Core\Exceptions\TransportException */ diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php index ba71c88a..2ec84630 100644 --- a/src/Services/CRM/Address/Service/Batch.php +++ b/src/Services/CRM/Address/Service/Batch.php @@ -28,19 +28,11 @@ #[ApiBatchServiceMetadata(new Scope(['crm']))] class Batch { - protected BatchOperationsInterface $batch; - protected LoggerInterface $log; - /** * Batch constructor. - * - * @param BatchOperationsInterface $batch - * @param LoggerInterface $log */ - public function __construct(BatchOperationsInterface $batch, LoggerInterface $log) + public function __construct(protected BatchOperationsInterface $batch, protected LoggerInterface $log) { - $this->batch = $batch; - $this->log = $log; } /** @@ -80,7 +72,6 @@ public function __construct(BatchOperationsInterface $batch, LoggerInterface $lo * ANCHOR_ID?: int, * } $filter * @param array $select = ['TYPE_ID','ENTITY_TYPE_ID','ENTITY_ID','ADDRESS_1','ADDRESS_2','CITY','POSTAL_CODE','REGION','PROVINCE','COUNTRY','COUNTRY_CODE','LOC_ADDR_ID','ANCHOR_TYPE_ID','ANCHOR_ID'] - * @param int|null $limit * * @return Generator * @throws BaseException @@ -140,6 +131,7 @@ public function add(array $addresses): Generator 'fields' => $address, ]; } + foreach ($this->batch->addEntityItems('crm.address.add', $items) as $key => $item) { yield $key => new AddedItemBatchResult($item); } From ed4bf85fbe6e1dbb330e955fbb6adfb495179604 Mon Sep 17 00:00:00 2001 From: Vadim Soluyanov Date: Wed, 25 Jun 2025 10:24:27 +0400 Subject: [PATCH 11/11] delete list-method from Service/Batch.php --- CHANGELOG.md | 14 ++--- Makefile | 4 +- src/Services/CRM/Address/Service/Batch.php | 62 ------------------- .../CRM/Address/Service/BatchTest.php | 26 -------- .../Services/CRM/Lead/Service/BatchTest.php | 1 + 5 files changed, 10 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 266aa0e4..f24b7af6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,13 @@ - `get` get localizations - `fields` get localization fields - `delete` delete currency, with batch calls support +- Added service `Services\CRM\Address\Service\Address` with support methods, + see [add crm.address REST methods](https://github.com/bitrix24/b24phpsdk/issues/138): + - `list` get item list + - `add` add new item, with batch calls support + - `delete` delete item, with batch calls support + - `update` update item, with batch calls support +- Added enum `Services\CRM\Enum\OwnerType` ### Fixed @@ -106,13 +113,6 @@ work in progress ### Added -- Added service `Services\CRM\Address\Service\Address` with support methods, - see [add crm.address REST methods](https://github.com/bitrix24/b24phpsdk/issues/138): - - `list` get item list, with batch calls support - - `add` add new item, with batch calls support - - `delete` delete item, with batch calls support - - `update` update item, with batch calls support -- Added enum `Services\CRM\Enum\OwnerType` - Added **PHP 8.4** [support](https://github.com/bitrix24/b24phpsdk/issues/120) 🚀 - Added method `Bitrix24\SDK\Services\Main\Service::guardValidateCurrentAuthToken` for validate current auth token with api-call `app.info` on vendor OAUTH server. diff --git a/Makefile b/Makefile index 7f2191e9..1c75dfa1 100644 --- a/Makefile +++ b/Makefile @@ -183,8 +183,8 @@ test-integration-scope-ai-admin: test-integration-scope-crm: docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm -.PHONY: test-integration-scope-crm-address -test-integration-scope-crm-address: +.PHONY: integration_tests_scope_crm_address +integration_tests_scope_crm_address: docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_address .PHONY: integration_tests_lead_userfield diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php index 2ec84630..544db060 100644 --- a/src/Services/CRM/Address/Service/Batch.php +++ b/src/Services/CRM/Address/Service/Batch.php @@ -35,68 +35,6 @@ public function __construct(protected BatchOperationsInterface $batch, protected { } - /** - * Batch list method for Addresses - * - * @param array{ - * TYPE_ID?: int, - * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: int, - * ADDRESS_1?: string, - * ADDRESS_2?: string, - * CITY?: string, - * POSTAL_CODE?: string, - * REGION?: string, - * PROVINCE?: string, - * COUNTRY?: string, - * COUNTRY_CODE?: string, - * LOC_ADDR_ID?: int, - * ANCHOR_TYPE_ID?: int, - * ANCHOR_ID?: int, - * } $order - * - * @param array{ - * TYPE_ID?: int, - * ENTITY_TYPE_ID?: int, - * ENTITY_ID?: int, - * ADDRESS_1?: string, - * ADDRESS_2?: string, - * CITY?: string, - * POSTAL_CODE?: string, - * REGION?: string, - * PROVINCE?: string, - * COUNTRY?: string, - * COUNTRY_CODE?: string, - * LOC_ADDR_ID?: int, - * ANCHOR_TYPE_ID?: int, - * ANCHOR_ID?: int, - * } $filter - * @param array $select = ['TYPE_ID','ENTITY_TYPE_ID','ENTITY_ID','ADDRESS_1','ADDRESS_2','CITY','POSTAL_CODE','REGION','PROVINCE','COUNTRY','COUNTRY_CODE','LOC_ADDR_ID','ANCHOR_TYPE_ID','ANCHOR_ID'] - * - * @return Generator - * @throws BaseException - */ - #[ApiBatchMethodMetadata( - 'crm.address.list', - 'https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-list.html', - 'Batch list method for addresses' - )] - public function list(array $order, array $filter, array $select, ?int $limit = null): Generator - { - $this->log->debug( - 'batchList', - [ - 'order' => $order, - 'filter' => $filter, - 'select' => $select, - 'limit' => $limit, - ] - ); - foreach ($this->batch->getTraversableList('crm.address.list', $order, $filter, $select, $limit) as $key => $value) { - yield $key => new AddressItemResult($value); - } - } - /** * Batch adding addresses * diff --git a/tests/Integration/Services/CRM/Address/Service/BatchTest.php b/tests/Integration/Services/CRM/Address/Service/BatchTest.php index 2c7770ad..e14891e9 100644 --- a/tests/Integration/Services/CRM/Address/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Address/Service/BatchTest.php @@ -63,32 +63,6 @@ protected function setUp(): void } } - /** - * @throws BaseException - * @throws TransportException - */ - #[\PHPUnit\Framework\Attributes\TestDox('Batch list addresses')] - public function testBatchList(): void - { - [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); - $fields = [ - 'TYPE_ID' => $this->addressTypes[1], - 'ENTITY_TYPE_ID' => OwnerType::requisite->value, - 'ENTITY_ID' => $requisiteId, - 'ADDRESS_1' => '123, Test str.' - ]; - $this->addressService->add($fields); - $cnt = 0; - $list = $this->addressService->batch->list([], ['TYPE_ID' => $this->addressTypes[1]], ['TYPE_ID'], 1); - foreach ($list as $item) { - $cnt++; - } - - self::assertGreaterThanOrEqual(1, $cnt); - - $this->companyService->delete($companyId); - } - /** * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ diff --git a/tests/Integration/Services/CRM/Lead/Service/BatchTest.php b/tests/Integration/Services/CRM/Lead/Service/BatchTest.php index a1ffd88d..c4404010 100644 --- a/tests/Integration/Services/CRM/Lead/Service/BatchTest.php +++ b/tests/Integration/Services/CRM/Lead/Service/BatchTest.php @@ -93,6 +93,7 @@ public function testBatchDelete(): void $cnt++; $dealId[] = $item->getId(); } + self::assertEquals(count($leads), $cnt); $cnt = 0;