This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Esun\LingxingErp\Test\Unit\Model\Sku;
use Esun\LingxingErp\Model\Api\Client;
use Esun\LingxingErp\Model\Sku\PairFetcher;
use Esun\LingxingErp\Model\Sync\LogWriter;
use PHPUnit\Framework\TestCase;
class PairFetcherTest extends TestCase
{
public function testFetchesAllPagesWithWebsiteStoreFilters(): void
{
$client = $this->createMock(Client::class);
$client->expects(self::exactly(2))->method('post')->willReturnCallback(
static function (string $path, array $request): array {
self::assertSame('/pb/mp/listing/v2/getPairList', $path);
self::assertSame(['10009'], $request['platform_codes']);
self::assertSame(['STORE-1'], $request['store_ids']);
self::assertSame(['M1', 'M2', 'M3'], $request['msku']);
self::assertSame(2, $request['length']);
if ($request['offset'] === 0) {
return ['code' => 0, 'request_id' => 'R1', 'data' => ['list' => [
['msku' => 'M1', 'sku' => 'E1'],
['msku' => 'M2', 'sku' => 'E2'],
]]];
}
self::assertSame(2, $request['offset']);
return ['code' => 0, 'request_id' => 'R2', 'data' => ['list' => [
['msku' => 'M3', 'sku' => 'E3'],
]]];
}
);
$logWriter = $this->createMock(LogWriter::class);
$logWriter->expects(self::exactly(2))->method('write')->with(self::callback(
static fn(array $data): bool => $data['operation'] === 'sku_pair_lookup'
&& $data['status'] === 'success'
&& isset($data['request_payload'], $data['response_payload'])
));
$result = (new PairFetcher($client, $logWriter))->fetchAll(
10009,
'STORE-1',
['M1', 'M2', 'M3'],
2
);
self::assertSame(['M1', 'M2', 'M3'], array_column($result, 'msku'));
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Esun\LingxingErp\Test\Unit\Model\Sku;
use Esun\LingxingErp\Model\Sku\ProductErpSkuRepository;
use Magento\Catalog\Model\ResourceModel\Product\Action as ProductActionResource;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\TestCase;
class ProductErpSkuRepositoryTest extends TestCase
{
public function testMultipleMskusMayShareOneErpSkuInWebsiteStoreMapping(): void
{
$repository = new ProductErpSkuRepository(
$this->createMock(ResourceConnection::class),
$this->createMock(ProductActionResource::class),
$this->createMock(StoreManagerInterface::class),
$this->createMock(EavConfig::class),
$this->createMock(MetadataPool::class)
);
$method = new \ReflectionMethod($repository, 'normalizeAndValidate');
$result = $method->invoke($repository, 10009, 'STORE-1', [
['platform_code' => 10009, 'store_id' => 'STORE-1', 'msku' => 'MAGENTO-A', 'sku' => 'ERP-1'],
['platform_code' => 10009, 'store_id' => 'STORE-1', 'msku' => 'MAGENTO-B', 'sku' => 'ERP-1'],
]);
self::assertSame(['MAGENTO-A' => 'ERP-1', 'MAGENTO-B' => 'ERP-1'], $result);
}
}