init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Test\Unit\Model\Shipment;
|
||||
|
||||
use Esun\LingxingErp\Model\Shipment\FulfillmentNormalizer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FulfillmentNormalizerTest extends TestCase
|
||||
{
|
||||
public function testMultipleOutboundOrdersRemainIndependentShipments(): void
|
||||
{
|
||||
$result = (new FulfillmentNormalizer())->normalize([
|
||||
'order_number' => 'ERP1',
|
||||
'wo_number' => 'WO1',
|
||||
'wid' => 46133,
|
||||
'tracking_no' => 'TRACK1',
|
||||
'product_info' => [['sku' => 'SKU1', 'count' => 2]],
|
||||
]);
|
||||
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame('WO1', $result[0]['external_key']);
|
||||
self::assertSame([['erp_sku' => 'SKU1', 'quantity' => 2.0]], $result[0]['products']);
|
||||
self::assertSame('TRACK1', $result[0]['tracks'][0]['number']);
|
||||
self::assertSame(46133, $result[0]['wid']);
|
||||
}
|
||||
|
||||
public function testPackagesSplitOnlyWhenEveryPackageHasItemQuantities(): void
|
||||
{
|
||||
$result = (new FulfillmentNormalizer())->normalize([
|
||||
'order_number' => 'ERP1',
|
||||
'wo_number' => 'WO1',
|
||||
'package_delivered_data' => [
|
||||
['package_no' => 'P1', 'tracking_no' => 'T1', 'product_info' => [['sku' => 'A', 'count' => 1]]],
|
||||
['package_no' => 'P2', 'tracking_no' => 'T2', 'product_info' => [['sku' => 'B', 'count' => 1]]],
|
||||
],
|
||||
]);
|
||||
|
||||
self::assertCount(2, $result);
|
||||
self::assertSame('WO1|P1', $result[0]['external_key']);
|
||||
self::assertSame('WO1|P2', $result[1]['external_key']);
|
||||
}
|
||||
|
||||
public function testPackagesWithoutItemQuantitiesBecomeOneShipmentWithMultipleTracks(): void
|
||||
{
|
||||
$result = (new FulfillmentNormalizer())->normalize([
|
||||
'order_number' => 'ERP1',
|
||||
'wo_number' => 'WO1',
|
||||
'product_info' => [['sku' => 'A', 'count' => 2]],
|
||||
'package_delivered_data' => [
|
||||
['package_no' => 'P1', 'tracking_no' => 'T1'],
|
||||
['package_no' => 'P2', 'tracking_no' => 'T2'],
|
||||
],
|
||||
]);
|
||||
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame(['T1', 'T2'], array_column($result[0]['tracks'], 'number'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Test\Unit\Model\Shipment;
|
||||
|
||||
use Esun\LingxingErp\Model\Config;
|
||||
use Esun\LingxingErp\Model\Shipment\ShipmentImporter;
|
||||
use Esun\LingxingErp\Model\Sku\ProductErpSkuRepository;
|
||||
use Esun\LingxingErp\Model\Sync\OrderSyncRepository;
|
||||
use Esun\LingxingErp\Model\Warehouse\WarehouseRepository;
|
||||
use Magento\Sales\Api\Data\ShipmentCreationArgumentsExtensionInterfaceFactory;
|
||||
use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterfaceFactory;
|
||||
use Magento\Sales\Api\Data\ShipmentItemCreationInterfaceFactory;
|
||||
use Magento\Sales\Api\Data\ShipmentTrackCreationInterfaceFactory;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Api\ShipOrderInterface;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ShipmentImporterTest extends TestCase
|
||||
{
|
||||
public function testErpSkuIsResolvedToMagentoOrderItemSkuWithinWebsite(): void
|
||||
{
|
||||
$productErpSkuRepository = $this->createMock(ProductErpSkuRepository::class);
|
||||
$productErpSkuRepository->expects(self::once())
|
||||
->method('findMskusByErpSku')
|
||||
->with(3, 'ERP-001')
|
||||
->willReturn(['MAGENTO-001']);
|
||||
$importer = $this->createImporter($productErpSkuRepository);
|
||||
$item = $this->createOrderItem('MAGENTO-001', 17, 2.0);
|
||||
|
||||
$method = new \ReflectionMethod($importer, 'allocateQuantities');
|
||||
$result = $method->invoke($importer, [$item], [['erp_sku' => 'ERP-001', 'quantity' => 2]], 3);
|
||||
|
||||
self::assertSame([17 => 2.0], $result);
|
||||
}
|
||||
|
||||
public function testSharedErpSkuIsAllocatedAcrossMagentoItemsInOrderItemOrder(): void
|
||||
{
|
||||
$productErpSkuRepository = $this->createMock(ProductErpSkuRepository::class);
|
||||
$productErpSkuRepository->expects(self::once())
|
||||
->method('findMskusByErpSku')
|
||||
->with(3, 'ERP-SHARED')
|
||||
->willReturn(['MAGENTO-B', 'MAGENTO-A']);
|
||||
$importer = $this->createImporter($productErpSkuRepository);
|
||||
$first = $this->createOrderItem('MAGENTO-A', 17, 1.0);
|
||||
$second = $this->createOrderItem('MAGENTO-B', 18, 2.0);
|
||||
|
||||
$method = new \ReflectionMethod($importer, 'allocateQuantities');
|
||||
$result = $method->invoke(
|
||||
$importer,
|
||||
// Input order is intentionally reversed; allocation must follow the Magento order item IDs.
|
||||
[$second, $first],
|
||||
[['erp_sku' => 'ERP-SHARED', 'quantity' => 2]],
|
||||
3
|
||||
);
|
||||
|
||||
self::assertSame([17 => 1.0, 18 => 1.0], $result);
|
||||
}
|
||||
|
||||
private function createImporter(ProductErpSkuRepository $productErpSkuRepository): ShipmentImporter
|
||||
{
|
||||
return new ShipmentImporter(
|
||||
$this->createMock(OrderSyncRepository::class),
|
||||
$this->createMock(OrderRepositoryInterface::class),
|
||||
$this->createMock(ShipmentItemCreationInterfaceFactory::class),
|
||||
$this->createMock(ShipmentTrackCreationInterfaceFactory::class),
|
||||
$this->createMock(ShipOrderInterface::class),
|
||||
$this->createMock(Config::class),
|
||||
$productErpSkuRepository,
|
||||
$this->createMock(StoreManagerInterface::class),
|
||||
$this->createMock(WarehouseRepository::class),
|
||||
$this->createMock(ShipmentCreationArgumentsInterfaceFactory::class),
|
||||
$this->createMock(ShipmentCreationArgumentsExtensionInterfaceFactory::class)
|
||||
);
|
||||
}
|
||||
|
||||
private function createOrderItem(string $sku, int $itemId, float $qtyToShip): Item
|
||||
{
|
||||
$item = $this->createMock(Item::class);
|
||||
$item->method('getIsVirtual')->willReturn(false);
|
||||
$item->method('getQtyToShip')->willReturn($qtyToShip);
|
||||
$item->method('getSku')->willReturn($sku);
|
||||
$item->method('getItemId')->willReturn($itemId);
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Test\Unit\Model\Shipment;
|
||||
|
||||
use Esun\LingxingErp\Model\Api\Client;
|
||||
use Esun\LingxingErp\Model\Config;
|
||||
use Esun\LingxingErp\Model\Shipment\FulfillmentNormalizer;
|
||||
use Esun\LingxingErp\Model\Shipment\ShipmentPuller;
|
||||
use Esun\LingxingErp\Model\Sync\LogWriter;
|
||||
use Esun\LingxingErp\Model\Sync\OrderSyncRepository;
|
||||
use Esun\LingxingErp\Model\Sync\ShipmentSyncRepository;
|
||||
use Magento\Framework\FlagManager;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ShipmentPullerTest extends TestCase
|
||||
{
|
||||
public function testLimitsRemoteRequestToTrackablePlatformOrderNumbers(): void
|
||||
{
|
||||
$config = $this->createMock(Config::class);
|
||||
$config->method('getShipmentPageSize')->willReturn(200);
|
||||
$config->method('getShipmentMaxPages')->willReturn(1);
|
||||
$orderSyncRepository = $this->createMock(OrderSyncRepository::class);
|
||||
$orderSyncRepository->method('getTrackablePlatformOrderNos')->willReturn(['100000001', '100000002']);
|
||||
|
||||
$client = $this->createMock(Client::class);
|
||||
$client->expects(self::once())->method('post')->with(
|
||||
'/erp/sc/routing/wms/order/wmsOrderList',
|
||||
self::callback(static fn(array $request): bool =>
|
||||
$request['platform_order_no_arr'] === ['100000001', '100000002']
|
||||
&& !isset($request['sid_arr']))
|
||||
)->willReturn(['code' => 0, 'data' => [], 'request_id' => 'request-id']);
|
||||
|
||||
$timezone = $this->createMock(TimezoneInterface::class);
|
||||
$timezone->method('date')->willReturn(new \DateTime('2026-08-26 12:00:00'));
|
||||
$flagManager = $this->createMock(FlagManager::class);
|
||||
$flagManager->method('getFlagData')->willReturn(null);
|
||||
|
||||
$puller = new ShipmentPuller(
|
||||
$client,
|
||||
$config,
|
||||
$timezone,
|
||||
$flagManager,
|
||||
$this->createMock(FulfillmentNormalizer::class),
|
||||
$orderSyncRepository,
|
||||
$this->createMock(ShipmentSyncRepository::class),
|
||||
$this->createMock(LogWriter::class)
|
||||
);
|
||||
$puller->pull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user