From 56b4957808578ad150b07771f5e6bbe3fd5757a5 Mon Sep 17 00:00:00 2001 From: mesilov Date: Sat, 1 Aug 2026 03:17:36 +0600 Subject: [PATCH] Fix lead batch item result type --- CHANGELOG.md | 2 + phpunit.xml.dist | 1 + src/Services/CRM/Lead/Service/Batch.php | 6 +- .../Services/CRM/Lead/Service/BatchTest.php | 62 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/Services/CRM/Lead/Service/BatchTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ad7bc8b..21d0a618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ ### Fixed +- Fixed `Services\CRM\Lead\Service\Batch::list()` returning `DealItemResult` + instead of `LeadItemResult` items ([#470](https://github.com/bitrix24/b24phpsdk/pull/470)) - Fixed batch operations for `Services\Catalog\Product` using the wrong-case `ID` key instead of the lowercase `id` key expected by `catalog.product.list` and `catalog.product.delete`: added `Services\Catalog\Product\Batch` overriding `determineKeyId()` and `deleteEntityItems()`, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d8ee8acd..d82c120e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -471,6 +471,7 @@ ./tests/Integration/Services/Sign/B2e/MySafeTail/Service/ ./tests/Integration/Services/Sign/B2e/MySafeTail/Result/ + ./tests/Integration/Services/IMBot/ diff --git a/src/Services/CRM/Lead/Service/Batch.php b/src/Services/CRM/Lead/Service/Batch.php index 7bea200c..9371904e 100644 --- a/src/Services/CRM/Lead/Service/Batch.php +++ b/src/Services/CRM/Lead/Service/Batch.php @@ -20,7 +20,7 @@ use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Result\AddedItemBatchResult; use Bitrix24\SDK\Core\Result\DeletedItemBatchResult; -use Bitrix24\SDK\Services\CRM\Deal\Result\DealItemResult; +use Bitrix24\SDK\Services\CRM\Lead\Result\LeadItemResult; use Generator; use Psr\Log\LoggerInterface; @@ -126,7 +126,7 @@ public function __construct(protected BatchOperationsInterface $batch, protected * } $filter * @param array $select = ['ID','TITLE','TYPE_ID','CATEGORY_ID','STAGE_ID','STAGE_SEMANTIC_ID','IS_NEW','IS_RECURRING','IS_RETURN_CUSTOMER','IS_REPEATED_APPROACH','PROBABILITY','CURRENCY_ID','OPPORTUNITY','IS_MANUAL_OPPORTUNITY','TAX_VALUE','COMPANY_ID','CONTACT_ID','CONTACT_IDS','QUOTE_ID','BEGINDATE','CLOSEDATE','OPENED','CLOSED','COMMENTS','ASSIGNED_BY_ID','CREATED_BY_ID','MODIFY_BY_ID','DATE_CREATE','DATE_MODIFY','SOURCE_ID','SOURCE_DESCRIPTION','LEAD_ID','ADDITIONAL_INFO','LOCATION_ID','ORIGINATOR_ID','ORIGIN_ID','UTM_SOURCE','UTM_MEDIUM','UTM_CAMPAIGN','UTM_CONTENT','UTM_TERM'] * - * @return Generator + * @return Generator * @throws BaseException */ #[ApiBatchMethodMetadata( @@ -146,7 +146,7 @@ public function list(array $order, array $filter, array $select, ?int $limit = n ] ); foreach ($this->batch->getTraversableList('crm.lead.list', $order, $filter, $select, $limit) as $key => $value) { - yield $key => new DealItemResult($value); + yield $key => new LeadItemResult($value); } } diff --git a/tests/Unit/Services/CRM/Lead/Service/BatchTest.php b/tests/Unit/Services/CRM/Lead/Service/BatchTest.php new file mode 100644 index 00000000..fbe5f61d --- /dev/null +++ b/tests/Unit/Services/CRM/Lead/Service/BatchTest.php @@ -0,0 +1,62 @@ + + * + * 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\Unit\Services\CRM\Lead\Service; + +use Bitrix24\SDK\Core\Contracts\BatchOperationsInterface; +use Bitrix24\SDK\Services\CRM\Lead\Result\LeadItemResult; +use Bitrix24\SDK\Services\CRM\Lead\Service\Batch; +use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; +use PHPUnit\Framework\TestCase; +use Psr\Log\NullLogger; + +#[CoversClass(Batch::class)] +class BatchTest extends TestCase +{ + #[Test] + #[TestDox('list() yields LeadItemResult items')] + public function testListYieldsLeadItemResults(): void + { + $batchOperations = $this->createMock(BatchOperationsInterface::class); + $batchOperations->expects($this->once()) + ->method('getTraversableList') + ->with('crm.lead.list', ['ID' => 'ASC'], ['ID' => 42], ['ID', 'TITLE'], 1) + ->willReturn($this->yieldValues([ + ['ID' => 42, 'TITLE' => 'Test lead'], + ])); + + $items = iterator_to_array( + (new Batch($batchOperations, new NullLogger()))->list( + ['ID' => 'ASC'], + ['ID' => 42], + ['ID', 'TITLE'], + 1 + ) + ); + + $this->assertContainsOnlyInstancesOf(LeadItemResult::class, $items); + } + + /** + * @param list> $values + */ + private function yieldValues(array $values): Generator + { + foreach ($values as $key => $value) { + yield $key => $value; + } + } +}