Files
2026-09-15 10:35:56 +08:00

52 lines
2.0 KiB
PHP

<?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'));
}
}