diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
index 6e5393c3..15e131ad 100644
--- a/.php-cs-fixer.php
+++ b/.php-cs-fixer.php
@@ -29,6 +29,7 @@
->in(__DIR__ . '/src/Services/SonetGroup/')
->in(__DIR__ . '/src/Services/IMOpenLines/')
->in(__DIR__ . '/src/Services/Landing/')
+ ->in(__DIR__ . '/src/Services/Catalog/')
->name('*.php')
->exclude(['vendor', 'storage', 'docker', 'docs']) // Exclude directories
->ignoreDotFiles(true)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4bc3b52..ef584ce2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@
### Added
+- Added service `Services\Catalog\StoreProduct` with support methods,
+ see [catalog.storeproduct.* methods](https://apidocs.bitrix24.com/api-reference/catalog/store-product/index.html) ([#584](https://github.com/bitrix24/b24phpsdk/issues/584)):
+ - `get` returns product stock information by record identifier
+ - `list` returns a list of product stock records by filter
+ - `getFields` returns the description of product stock fields
- Added service `Services\Landing\Site\Service\Site` with support methods,
see [landing.site.* methods](https://github.com/bitrix24/b24phpsdk/issues/267):
- `add` adds a site
diff --git a/Makefile b/Makefile
index c2fc4a9a..2bfb8170 100644
--- a/Makefile
+++ b/Makefile
@@ -492,6 +492,10 @@ test-integration-landing-role:
test-integration-landing-repowidget:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_landing_repowidget
+.PHONY: test-integration-catalog-store-product
+test-integration-catalog-store-product:
+ docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_catalog_store_product
+
# work dev environment
.PHONY: php-dev-server-up
php-dev-server-up:
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d0187ae5..a7ef29fb 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -262,6 +262,9 @@
./tests/Integration/Services/Landing/RepoWidget/
+
+ ./tests/Integration/Services/Catalog/StoreProduct/
+
diff --git a/src/Services/Catalog/Catalog/Result/CatalogItemResult.php b/src/Services/Catalog/Catalog/Result/CatalogItemResult.php
index e62fc7cb..189852bb 100644
--- a/src/Services/Catalog/Catalog/Result/CatalogItemResult.php
+++ b/src/Services/Catalog/Catalog/Result/CatalogItemResult.php
@@ -29,4 +29,4 @@
*/
class CatalogItemResult extends AbstractCatalogItem
{
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Catalog/Result/CatalogResult.php b/src/Services/Catalog/Catalog/Result/CatalogResult.php
index aa468aa8..c5222f11 100644
--- a/src/Services/Catalog/Catalog/Result/CatalogResult.php
+++ b/src/Services/Catalog/Catalog/Result/CatalogResult.php
@@ -21,4 +21,4 @@ public function catalog(): CatalogItemResult
{
return new CatalogItemResult($this->getCoreResponse()->getResponseData()->getResult()['catalog']);
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Catalog/Result/CatalogsResult.php b/src/Services/Catalog/Catalog/Result/CatalogsResult.php
index add5f259..f721c3bb 100644
--- a/src/Services/Catalog/Catalog/Result/CatalogsResult.php
+++ b/src/Services/Catalog/Catalog/Result/CatalogsResult.php
@@ -32,4 +32,4 @@ public function getCatalogs(): array
return $res;
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Catalog/Service/Catalog.php b/src/Services/Catalog/Catalog/Service/Catalog.php
index d9cb55fe..0da76ea3 100644
--- a/src/Services/Catalog/Catalog/Service/Catalog.php
+++ b/src/Services/Catalog/Catalog/Service/Catalog.php
@@ -82,4 +82,4 @@ public function fields(): FieldsResult
{
return new FieldsResult($this->core->call('catalog.catalog.getFields'));
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/CatalogServiceBuilder.php b/src/Services/Catalog/CatalogServiceBuilder.php
index 57c91b88..7eab29fb 100644
--- a/src/Services/Catalog/CatalogServiceBuilder.php
+++ b/src/Services/Catalog/CatalogServiceBuilder.php
@@ -17,6 +17,7 @@
use Bitrix24\SDK\Core\Credentials\Scope;
use Bitrix24\SDK\Services\AbstractServiceBuilder;
use Bitrix24\SDK\Services\Catalog;
+
#[ApiServiceBuilderMetadata(new Scope(['catalog']))]
class CatalogServiceBuilder extends AbstractServiceBuilder
{
@@ -44,4 +45,16 @@ public function catalog(): Catalog\Catalog\Service\Catalog
return $this->serviceCache[__METHOD__];
}
-}
\ No newline at end of file
+
+ public function storeProduct(): Catalog\StoreProduct\Service\StoreProduct
+ {
+ if (!isset($this->serviceCache[__METHOD__])) {
+ $this->serviceCache[__METHOD__] = new Catalog\StoreProduct\Service\StoreProduct(
+ $this->core,
+ $this->log
+ );
+ }
+
+ return $this->serviceCache[__METHOD__];
+ }
+}
diff --git a/src/Services/Catalog/Common/ProductType.php b/src/Services/Catalog/Common/ProductType.php
index 0bf8ef09..ad568a47 100644
--- a/src/Services/Catalog/Common/ProductType.php
+++ b/src/Services/Catalog/Common/ProductType.php
@@ -20,4 +20,4 @@ enum ProductType: int
case SKU = 3;
case productOffer = 4;
case genericOffer = 5;
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Common/Result/AbstractCatalogItem.php b/src/Services/Catalog/Common/Result/AbstractCatalogItem.php
index e2929d73..9761daed 100644
--- a/src/Services/Catalog/Common/Result/AbstractCatalogItem.php
+++ b/src/Services/Catalog/Common/Result/AbstractCatalogItem.php
@@ -109,4 +109,4 @@ protected function getKeyWithUserfieldByFieldName(string $fieldName)
return $this->$fieldName;
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Product/Result/ProductItemResult.php b/src/Services/Catalog/Product/Result/ProductItemResult.php
index c576d9b7..58c80851 100644
--- a/src/Services/Catalog/Product/Result/ProductItemResult.php
+++ b/src/Services/Catalog/Product/Result/ProductItemResult.php
@@ -52,4 +52,4 @@
*/
class ProductItemResult extends AbstractCatalogItem
{
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Product/Result/ProductResult.php b/src/Services/Catalog/Product/Result/ProductResult.php
index 2751fda8..fc83fa8c 100644
--- a/src/Services/Catalog/Product/Result/ProductResult.php
+++ b/src/Services/Catalog/Product/Result/ProductResult.php
@@ -26,4 +26,4 @@ public function product(): ProductItemResult
return new ProductItemResult($this->getCoreResponse()->getResponseData()->getResult()['product']);
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Product/Result/ProductsResult.php b/src/Services/Catalog/Product/Result/ProductsResult.php
index aa644fa3..268d6d8f 100644
--- a/src/Services/Catalog/Product/Result/ProductsResult.php
+++ b/src/Services/Catalog/Product/Result/ProductsResult.php
@@ -31,4 +31,4 @@ public function getProducts(): array
return $res;
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Product/Service/Batch.php b/src/Services/Catalog/Product/Service/Batch.php
index 45dddcb7..42970546 100644
--- a/src/Services/Catalog/Product/Service/Batch.php
+++ b/src/Services/Catalog/Product/Service/Batch.php
@@ -25,7 +25,7 @@
{
public function __construct(
protected BatchOperationsInterface $batch,
- protected LoggerInterface $log)
- {
+ protected LoggerInterface $log
+ ) {
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/Product/Service/Product.php b/src/Services/Catalog/Product/Service/Product.php
index 730fd7c9..d37d34f6 100644
--- a/src/Services/Catalog/Product/Service/Product.php
+++ b/src/Services/Catalog/Product/Service/Product.php
@@ -25,7 +25,6 @@
use Bitrix24\SDK\Services\Catalog\Common\ProductType;
use Bitrix24\SDK\Services\Catalog\Product\Result\ProductResult;
use Bitrix24\SDK\Services\Catalog\Product\Result\ProductsResult;
-
use Psr\Log\LoggerInterface;
#[ApiServiceMetadata(new Scope(['catalog']))]
@@ -35,8 +34,7 @@ public function __construct(
public Batch $batch,
CoreInterface $core,
LoggerInterface $logger
- )
- {
+ ) {
parent::__construct($core, $logger);
}
@@ -71,7 +69,9 @@ public function get(int $productId): ProductResult
)]
public function add(array $productFields): ProductResult
{
- return new ProductResult($this->core->call('catalog.product.add', [
+ return new ProductResult($this->core->call(
+ 'catalog.product.add',
+ [
'fields' => $productFields
]
));
@@ -140,4 +140,4 @@ public function fieldsByFilter(int $iblockId, ProductType $productType, ?array $
return new FieldsResult($this->core->call('catalog.product.getFieldsByFilter', ['filter' => $filter]));
}
-}
\ No newline at end of file
+}
diff --git a/src/Services/Catalog/StoreProduct/Result/StoreProductFieldsResult.php b/src/Services/Catalog/StoreProduct/Result/StoreProductFieldsResult.php
new file mode 100644
index 00000000..7e1cb9a6
--- /dev/null
+++ b/src/Services/Catalog/StoreProduct/Result/StoreProductFieldsResult.php
@@ -0,0 +1,29 @@
+
+ *
+ * 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\Catalog\StoreProduct\Result;
+
+use Bitrix24\SDK\Core\Exceptions\BaseException;
+use Bitrix24\SDK\Core\Result\AbstractResult;
+
+class StoreProductFieldsResult extends AbstractResult
+{
+ /**
+ * @return array>
+ * @throws BaseException
+ */
+ public function getFieldsDescription(): array
+ {
+ return $this->getCoreResponse()->getResponseData()->getResult()['storeProduct'];
+ }
+}
diff --git a/src/Services/Catalog/StoreProduct/Result/StoreProductItemResult.php b/src/Services/Catalog/StoreProduct/Result/StoreProductItemResult.php
new file mode 100644
index 00000000..0be77f68
--- /dev/null
+++ b/src/Services/Catalog/StoreProduct/Result/StoreProductItemResult.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\Catalog\StoreProduct\Result;
+
+use Bitrix24\SDK\Core\Result\AbstractItem;
+
+/**
+ * @property-read int $id
+ * @property-read int $productId
+ * @property-read int $storeId
+ * @property-read float $amount
+ * @property-read float|null $quantityReserved
+ */
+class StoreProductItemResult extends AbstractItem
+{
+}
diff --git a/src/Services/Catalog/StoreProduct/Result/StoreProductResult.php b/src/Services/Catalog/StoreProduct/Result/StoreProductResult.php
new file mode 100644
index 00000000..aa25f818
--- /dev/null
+++ b/src/Services/Catalog/StoreProduct/Result/StoreProductResult.php
@@ -0,0 +1,26 @@
+
+ *
+ * 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\Catalog\StoreProduct\Result;
+
+use Bitrix24\SDK\Core\Result\AbstractResult;
+
+class StoreProductResult extends AbstractResult
+{
+ public function storeProduct(): StoreProductItemResult
+ {
+ return new StoreProductItemResult(
+ $this->getCoreResponse()->getResponseData()->getResult()['storeProduct']
+ );
+ }
+}
diff --git a/src/Services/Catalog/StoreProduct/Result/StoreProductsResult.php b/src/Services/Catalog/StoreProduct/Result/StoreProductsResult.php
new file mode 100644
index 00000000..6d2ec270
--- /dev/null
+++ b/src/Services/Catalog/StoreProduct/Result/StoreProductsResult.php
@@ -0,0 +1,42 @@
+
+ *
+ * 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\Catalog\StoreProduct\Result;
+
+use Bitrix24\SDK\Core\Exceptions\BaseException;
+use Bitrix24\SDK\Core\Result\AbstractResult;
+
+class StoreProductsResult extends AbstractResult
+{
+ /**
+ * @return StoreProductItemResult[]
+ * @throws BaseException
+ */
+ public function getStoreProducts(): array
+ {
+ $res = [];
+ foreach ($this->getCoreResponse()->getResponseData()->getResult()['storeProducts'] as $item) {
+ $res[] = new StoreProductItemResult($item);
+ }
+
+ return $res;
+ }
+
+ /**
+ * @throws BaseException
+ */
+ public function getTotal(): int
+ {
+ return $this->getCoreResponse()->getResponseData()->getPagination()->getTotal() ?? 0;
+ }
+}
diff --git a/src/Services/Catalog/StoreProduct/Service/StoreProduct.php b/src/Services/Catalog/StoreProduct/Service/StoreProduct.php
new file mode 100644
index 00000000..129320b5
--- /dev/null
+++ b/src/Services/Catalog/StoreProduct/Service/StoreProduct.php
@@ -0,0 +1,92 @@
+
+ *
+ * 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\Catalog\StoreProduct\Service;
+
+use Bitrix24\SDK\Attributes\ApiEndpointMetadata;
+use Bitrix24\SDK\Attributes\ApiServiceMetadata;
+use Bitrix24\SDK\Core\Credentials\Scope;
+use Bitrix24\SDK\Core\Exceptions\BaseException;
+use Bitrix24\SDK\Core\Exceptions\TransportException;
+use Bitrix24\SDK\Services\AbstractService;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Result\StoreProductFieldsResult;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Result\StoreProductResult;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Result\StoreProductsResult;
+
+#[ApiServiceMetadata(new Scope(['catalog']))]
+class StoreProduct extends AbstractService
+{
+ /**
+ * Returns information about product stock by record identifier.
+ *
+ * @link https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-get.html
+ *
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[ApiEndpointMetadata(
+ 'catalog.storeproduct.get',
+ 'https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-get.html',
+ 'Returns information about product stock by record identifier.'
+ )]
+ public function get(int $id): StoreProductResult
+ {
+ $this->guardPositiveId($id);
+
+ return new StoreProductResult($this->core->call('catalog.storeproduct.get', ['id' => $id]));
+ }
+
+ /**
+ * Returns a list of product stock records by filter.
+ *
+ * @link https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-list.html
+ *
+ * @param string[] $select
+ * @param array $filter
+ * @param array $order
+ *
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[ApiEndpointMetadata(
+ 'catalog.storeproduct.list',
+ 'https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-list.html',
+ 'Returns a list of product stock records by filter.'
+ )]
+ public function list(array $select = [], array $filter = [], array $order = []): StoreProductsResult
+ {
+ return new StoreProductsResult($this->core->call('catalog.storeproduct.list', [
+ 'select' => $select,
+ 'filter' => $filter,
+ 'order' => $order,
+ ]));
+ }
+
+ /**
+ * Returns the fields of product stock records.
+ *
+ * @link https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-get-fields.html
+ *
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[ApiEndpointMetadata(
+ 'catalog.storeproduct.getFields',
+ 'https://apidocs.bitrix24.com/api-reference/catalog/store-product/catalog-store-product-get-fields.html',
+ 'Returns the fields of product stock records.'
+ )]
+ public function getFields(): StoreProductFieldsResult
+ {
+ return new StoreProductFieldsResult($this->core->call('catalog.storeproduct.getFields'));
+ }
+}
diff --git a/tests/Integration/Services/Catalog/StoreProduct/Result/StoreProductItemResultTest.php b/tests/Integration/Services/Catalog/StoreProduct/Result/StoreProductItemResultTest.php
new file mode 100644
index 00000000..68f7f9bb
--- /dev/null
+++ b/tests/Integration/Services/Catalog/StoreProduct/Result/StoreProductItemResultTest.php
@@ -0,0 +1,56 @@
+
+ *
+ * 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\Catalog\StoreProduct\Result;
+
+use Bitrix24\SDK\Core\Exceptions\BaseException;
+use Bitrix24\SDK\Core\Exceptions\TransportException;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Result\StoreProductItemResult;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Service\StoreProduct;
+use Bitrix24\SDK\Tests\CustomAssertions\CustomBitrix24Assertions;
+use Bitrix24\SDK\Tests\Integration\Fabric;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\Test;
+use PHPUnit\Framework\Attributes\TestDox;
+use PHPUnit\Framework\TestCase;
+
+#[CoversClass(StoreProductItemResult::class)]
+class StoreProductItemResultTest extends TestCase
+{
+ use CustomBitrix24Assertions;
+
+ private StoreProduct $storeProductService;
+
+ /**
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[Test]
+ #[TestDox('all fields in StoreProductItemResult are annotated in phpdoc and match with raw api response')]
+ public function testAllFieldsAreAnnotated(): void
+ {
+ $rawItem = $this->storeProductService->list()->getCoreResponse()
+ ->getResponseData()->getResult()['storeProducts'][0];
+
+ $this->assertBitrix24AllResultItemFieldsAnnotated(
+ array_keys($rawItem),
+ StoreProductItemResult::class
+ );
+ }
+
+ #[\Override]
+ protected function setUp(): void
+ {
+ $this->storeProductService = Fabric::getServiceBuilder()->getCatalogScope()->storeProduct();
+ }
+}
diff --git a/tests/Integration/Services/Catalog/StoreProduct/Service/StoreProductTest.php b/tests/Integration/Services/Catalog/StoreProduct/Service/StoreProductTest.php
new file mode 100644
index 00000000..d10144a5
--- /dev/null
+++ b/tests/Integration/Services/Catalog/StoreProduct/Service/StoreProductTest.php
@@ -0,0 +1,98 @@
+
+ *
+ * For the full copyright and license information, please view the MIT-LICENSE.txt
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace Bitrix24\SDK\Tests\Integration\Services\Catalog\StoreProduct\Service;
+
+use Bitrix24\SDK\Core\Exceptions\BaseException;
+use Bitrix24\SDK\Core\Exceptions\TransportException;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Service\StoreProduct;
+use Bitrix24\SDK\Tests\Integration\Fabric;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\TestDox;
+use PHPUnit\Framework\TestCase;
+
+#[CoversClass(StoreProduct::class)]
+class StoreProductTest extends TestCase
+{
+ private StoreProduct $storeProductService;
+
+ /**
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[TestDox('test StoreProduct::list finds existing storeProduct records')]
+ public function testList(): void
+ {
+ $items = $this->storeProductService->list()->getStoreProducts();
+ $this->assertNotEmpty($items, 'integration portal must have at least one product with stock');
+ $this->assertGreaterThan(0, $this->storeProductService->list()->getTotal());
+ }
+
+ /**
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[TestDox('test StoreProduct::list with select, filter and order')]
+ public function testListWithSelectFilterOrder(): void
+ {
+ $anyItem = $this->storeProductService->list()->getStoreProducts()[0];
+
+ $items = $this->storeProductService->list(
+ ['id', 'productId', 'storeId', 'amount'],
+ ['productId' => $anyItem->productId],
+ ['id' => 'ASC']
+ )->getStoreProducts();
+
+ $this->assertNotEmpty($items);
+ foreach ($items as $item) {
+ $this->assertEquals($anyItem->productId, $item->productId);
+ }
+ }
+
+ /**
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[TestDox('test StoreProduct::get returns the same record as list')]
+ public function testGet(): void
+ {
+ $listItem = $this->storeProductService->list()->getStoreProducts()[0];
+ $storeProductItemResult = $this->storeProductService->get($listItem->id)->storeProduct();
+
+ $this->assertEquals($listItem->id, $storeProductItemResult->id);
+ $this->assertEquals($listItem->productId, $storeProductItemResult->productId);
+ $this->assertEquals($listItem->storeId, $storeProductItemResult->storeId);
+ }
+
+ /**
+ * @throws BaseException
+ * @throws TransportException
+ */
+ #[TestDox('test StoreProduct::getFields')]
+ public function testGetFields(): void
+ {
+ $fields = $this->storeProductService->getFields()->getFieldsDescription();
+
+ $this->assertArrayHasKey('id', $fields);
+ $this->assertArrayHasKey('productId', $fields);
+ $this->assertArrayHasKey('storeId', $fields);
+ $this->assertArrayHasKey('amount', $fields);
+ $this->assertArrayHasKey('quantityReserved', $fields);
+ }
+
+ #[\Override]
+ protected function setUp(): void
+ {
+ $this->storeProductService = Fabric::getServiceBuilder()->getCatalogScope()->storeProduct();
+ }
+}
diff --git a/tests/Unit/Services/Catalog/StoreProduct/Service/StoreProductTest.php b/tests/Unit/Services/Catalog/StoreProduct/Service/StoreProductTest.php
new file mode 100644
index 00000000..5ac8b630
--- /dev/null
+++ b/tests/Unit/Services/Catalog/StoreProduct/Service/StoreProductTest.php
@@ -0,0 +1,97 @@
+
+ *
+ * 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\Catalog\StoreProduct\Service;
+
+use Bitrix24\SDK\Core\Contracts\CoreInterface;
+use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
+use Bitrix24\SDK\Core\Response\Response;
+use Bitrix24\SDK\Services\Catalog\StoreProduct\Service\StoreProduct;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\Test;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\NullLogger;
+
+#[CoversClass(StoreProduct::class)]
+class StoreProductTest extends TestCase
+{
+ #[Test]
+ public function getThrowsOnNonPositiveId(): void
+ {
+ $core = $this->createMock(CoreInterface::class);
+ $core->expects($this->never())->method('call');
+
+ $this->expectException(InvalidArgumentException::class);
+ (new StoreProduct($core, new NullLogger()))->get(0);
+ }
+
+ #[Test]
+ public function getCallsCoreWithId(): void
+ {
+ $core = $this->createMock(CoreInterface::class);
+ $core->expects($this->once())
+ ->method('call')
+ ->with('catalog.storeproduct.get', ['id' => 13])
+ ->willReturn($this->createStub(Response::class));
+
+ (new StoreProduct($core, new NullLogger()))->get(13);
+ }
+
+ #[Test]
+ public function listCallsCoreWithSelectFilterOrder(): void
+ {
+ $core = $this->createMock(CoreInterface::class);
+ $core->expects($this->once())
+ ->method('call')
+ ->with('catalog.storeproduct.list', [
+ 'select' => ['id', 'productId', 'storeId', 'amount'],
+ 'filter' => ['productId' => 6973],
+ 'order' => ['id' => 'ASC'],
+ ])
+ ->willReturn($this->createStub(Response::class));
+
+ (new StoreProduct($core, new NullLogger()))->list(
+ ['id', 'productId', 'storeId', 'amount'],
+ ['productId' => 6973],
+ ['id' => 'ASC']
+ );
+ }
+
+ #[Test]
+ public function listCallsCoreWithDefaultEmptyArguments(): void
+ {
+ $core = $this->createMock(CoreInterface::class);
+ $core->expects($this->once())
+ ->method('call')
+ ->with('catalog.storeproduct.list', [
+ 'select' => [],
+ 'filter' => [],
+ 'order' => [],
+ ])
+ ->willReturn($this->createStub(Response::class));
+
+ (new StoreProduct($core, new NullLogger()))->list();
+ }
+
+ #[Test]
+ public function getFieldsCallsCoreWithoutArguments(): void
+ {
+ $core = $this->createMock(CoreInterface::class);
+ $core->expects($this->once())
+ ->method('call')
+ ->with('catalog.storeproduct.getFields')
+ ->willReturn($this->createStub(Response::class));
+
+ (new StoreProduct($core, new NullLogger()))->getFields();
+ }
+}