diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index a560e05f..ef49ce2f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -6,6 +6,7 @@ $finder = Finder::create() ->in(__DIR__ . '/src/Infrastructure/Console/Commands/') + ->in(__DIR__ . '/src/Services/CRM/Address/') ->in(__DIR__ . '/src/Services/CRM/Item/Service/') ->in(__DIR__ . '/src/Services/CRM/Contact/') ->in(__DIR__ . '/src/Services/CRM/Quote/') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2412070b..fb903cec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,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` - Developer experience: added make command `lint-all` for run all code linters step by step, [see details](https://github.com/bitrix24/b24phpsdk/issues/183) ### Fixed @@ -173,8 +180,8 @@ work in progress 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 c8e10504..28ef81ed 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,14 @@ 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 +test-integration-scope-crm: + docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm + +.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_scope_crm_deal_details integration_tests_scope_crm_deal_details: diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 91a1d9fc..87d2a095 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/Address - tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php - tests/Integration/Services/CRM/Lead/Service/LeadContactTest.php - tests/Integration/Services/CRM/Item/Service/ItemDetailsConfigurationTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fe662908..6c5c2c80 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -43,6 +43,12 @@ ./tests/Integration/Services/AI/ + + ./tests/Integration/Services/CRM/ + + + ./tests/Integration/Services/CRM/Address/ + ./tests/Integration/Services/CRM/Deal/Service/DealDetailsConfigurationTest.php diff --git a/rector.php b/rector.php index 73231a4b..58bb6267 100644 --- a/rector.php +++ b/rector.php @@ -30,8 +30,8 @@ __DIR__ . '/tests/Integration/Services/IM', __DIR__ . '/src/Services/IMOpenLines', __DIR__ . '/tests/Integration/Services/IMOpenLines', - __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', diff --git a/src/Core/Batch.php b/src/Core/Batch.php index bf3e4f08..beffd15f 100644 --- a/src/Core/Batch.php +++ b/src/Core/Batch.php @@ -125,11 +125,13 @@ public function deleteEntityItems( 'additionalParameters' => $additionalParameters, ] ); + + $useFieldsInsteadOfId = $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 = $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,17 @@ 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/AddressItemResult.php b/src/Services/CRM/Address/Result/AddressItemResult.php new file mode 100644 index 00000000..3d9d21c7 --- /dev/null +++ b/src/Services/CRM/Address/Result/AddressItemResult.php @@ -0,0 +1,38 @@ + + * + * 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; + +/** + * Class AddressItemResult + * + * @property-read int $TYPE_ID + * @property-read int $ENTITY_TYPE_ID + * @property-read int $ENTITY_ID + * @property-read string|null $ADDRESS_1 + * @property-read string|null $ADDRESS_2 + * @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 +{ +} diff --git a/src/Services/CRM/Address/Result/AddressResult.php b/src/Services/CRM/Address/Result/AddressResult.php new file mode 100644 index 00000000..8209de49 --- /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 AddressResult + * + * @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()); + } +} diff --git a/src/Services/CRM/Address/Result/AddressesResult.php b/src/Services/CRM/Address/Result/AddressesResult.php new file mode 100644 index 00000000..7ea3c8f3 --- /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 AddressesResult + * + * @package Bitrix24\SDK\Services\CRM\Address\Result + */ +class AddressesResult extends AbstractResult +{ + /** + * @return AddressItemResult[] + * @throws BaseException + */ + public function getAddresses(): array + { + $items = []; + foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) { + $items[] = new AddressItemResult($item); + } + + return $items; + } +} diff --git a/src/Services/CRM/Address/Service/Address.php b/src/Services/CRM/Address/Service/Address.php new file mode 100644 index 00000000..15fb7576 --- /dev/null +++ b/src/Services/CRM/Address/Service/Address.php @@ -0,0 +1,234 @@ + + * + * 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 +{ + /** + * Address constructor. + */ + public function __construct(public Batch $batch, CoreInterface $core, LoggerInterface $logger) + { + parent::__construct($core, $logger); + } + + /** + * 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?: 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, + * } $fields + * + * @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 + * + * + * @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(int $typeId, int $entityTypeId, int $entityId): DeletedItemResult + { + return new DeletedItemResult( + $this->core->call( + 'crm.address.delete', + [ + 'fields' => [ + 'TYPE_ID' => $typeId, + 'ENTITY_TYPE_ID' => $entityTypeId, + 'ENTITY_ID' => $entityId, + ], + ] + ) + ); + } + + /** + * Returns the description of the address fields. + * + * @link https://apidocs.bitrix24.com/api-reference/crm/requisites/addresses/crm-address-fields.html + * + * @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 + */ + #[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?: 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, + * } $fields + * + * @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 + * + * 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, + * 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 + * + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + * @throws \Bitrix24\SDK\Core\Exceptions\TransportException + */ + public function countByFilter(array $filter = []): int + { + return $this->list([], $filter, ['TYPE_ID'], 1)->getCoreResponse()->getResponseData()->getPagination()->getTotal(); + } +} diff --git a/src/Services/CRM/Address/Service/Batch.php b/src/Services/CRM/Address/Service/Batch.php new file mode 100644 index 00000000..544db060 --- /dev/null +++ b/src/Services/CRM/Address/Service/Batch.php @@ -0,0 +1,137 @@ + + * + * 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 Bitrix24\SDK\Core\Result\UpdatedItemBatchResult; +use Generator; +use Psr\Log\LoggerInterface; + +#[ApiBatchServiceMetadata(new Scope(['crm']))] +class Batch +{ + /** + * Batch constructor. + */ + public function __construct(protected BatchOperationsInterface $batch, protected LoggerInterface $log) + { + } + + /** + * 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); + } + } + + /** + * 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); + } + } + +} diff --git a/src/Services/CRM/CRMServiceBuilder.php b/src/Services/CRM/CRMServiceBuilder.php index 9b71a27e..854c28e0 100644 --- a/src/Services/CRM/CRMServiceBuilder.php +++ b/src/Services/CRM/CRMServiceBuilder.php @@ -490,6 +490,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 { diff --git a/src/Services/CRM/Enum/OwnerType.php b/src/Services/CRM/Enum/OwnerType.php new file mode 100644 index 00000000..a773ed62 --- /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 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 new file mode 100644 index 00000000..97842698 --- /dev/null +++ b/tests/Integration/Services/CRM/Address/Service/AddressTest.php @@ -0,0 +1,260 @@ + + * + * 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\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; + +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')] +#[\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 = []; + + 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 $addressTypeFieldItemResult) { + $this->presets[] = $addressTypeFieldItemResult->ID; + } + + $enum = $this->sb->getCRMScope()->enum(); + foreach ($enum->addressType()->getItems() as $addressTypeFieldItemResult) { + $this->addressTypes[] = $addressTypeFieldItemResult->ID; + } + } + + 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 fn($code): bool => in_array($code, $systemFieldsCodes, true), ARRAY_FILTER_USE_KEY); + + $this->assertBitrix24AllResultItemFieldsHasValidTypeAnnotation( + $systemFields, + AddressItemResult::class); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testAdd(): 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.' + ]; + self::assertEquals( + 1, + $this->addressService->add($fields)->getCoreResponse()->getResponseData()->getResult()[0] + ); + + $this->companyService->delete($companyId); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testDelete(): void + { + [$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)->getCoreResponse()->getResponseData()->getResult(); + self::assertTrue( + $this->addressService->delete( + $fields['TYPE_ID'], + $fields['ENTITY_TYPE_ID'], + $fields['ENTITY_ID'] + )->isSuccess() + ); + $this->companyService->delete($companyId); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testFields(): void + { + self::assertIsArray($this->addressService->fields()->getFieldsDescription()); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testList(): void + { + [$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); + } + + /** + * @throws BaseException + * @throws TransportException + */ + public function testUpdate(): void + { + [$companyId, $requisiteId] = $this->addCompanyAndRequisite(); + $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($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 + */ + /* + // restApi bug. Issue: https://github.com/bitrix24/b24phpsdk/issues/144 + public function testCountByFilter(): void + { + $before = $this->addressService->countByFilter(); + + [$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 = []; + foreach ($this->addressTypes as $addressType) { + $stepFields = $fields; + $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( + $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 new file mode 100644 index 00000000..e14891e9 --- /dev/null +++ b/tests/Integration/Services/CRM/Address/Service/BatchTest.php @@ -0,0 +1,205 @@ + + * + * 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\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\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 = []; + + 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 $addressTypeFieldItemResult) { + $this->presets[] = $addressTypeFieldItemResult->ID; + } + + $enum = Fabric::getServiceBuilder()->getCRMScope()->enum(); + foreach ($enum->addressType()->getItems() as $addressTypeFieldItemResult) { + $this->addressTypes[] = $addressTypeFieldItemResult->ID; + } + } + + /** + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch add address')] + public function testBatchAdd(): void + { + [$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 $addressType) { + $stepFields = $fields; + $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); + } + + /** + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch delete address')] + public function testBatchDelete(): void + { + $items = []; + [$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->addressService->batch->add($items) as $item) { + $cnt++; + } + + self::assertEquals(count($items), $cnt); + + $cnt = 0; + $items = []; + foreach ($this->addressTypes as $addressType) { + $stepFields = $fields; + $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); + } + + /** + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + #[\PHPUnit\Framework\Attributes\TestDox('Batch update address')] + public function testBatchUpdate(): void + { + $items = []; + [$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->addressService->batch->add($items) as $item) { + $cnt++; + } + + self::assertEquals(count($items), $cnt); + + $cnt = 0; + $items = []; + $newAddress1 = 'Updated address 1'; + foreach ($this->addressTypes as $addressType) { + $stepFields = $fields; + $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( + $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/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/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/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 f98f8ead..7c046e5a 100644 --- a/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php +++ b/tests/Integration/Services/CRM/Requisites/Service/RequisitePresetTest.php @@ -46,38 +46,33 @@ class RequisitePresetTest extends TestCase use CustomBitrix24Assertions; protected ServiceBuilder $sb; + private array $createdCompanies = []; private int $entityTypeRequisiteId; private int $countryId; - public function setUp(): void + protected function setUp(): void { $this->sb = Fabric::getServiceBuilder(); $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 @@ -97,9 +92,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); } @@ -127,8 +120,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()); } @@ -147,7 +140,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)->requisitePreset(); + $this->sb->getCRMScope()->requisitePreset()->get($tplId)->requisitePreset(); } 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 a6b549b5..e4e87dc3 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