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

39 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\LingxingErp\Test\Unit\Model\Warehouse;
use Esun\LingxingErp\Model\Warehouse\WarehouseFetcher;
use Esun\LingxingErp\Model\Warehouse\WarehouseRepository;
use Esun\LingxingErp\Model\Warehouse\WarehouseSynchronizer;
use Magento\Framework\Lock\LockManagerInterface;
use PHPUnit\Framework\TestCase;
class WarehouseSynchronizerTest extends TestCase
{
public function testCachesEveryFetchedTypeThreeWarehouseWithoutCreatingSources(): void
{
$fetcher = $this->createMock(WarehouseFetcher::class);
$fetcher->method('fetchAll')->willReturn([
['wid' => 10, 'name' => 'US Stock', 'type' => 3],
['wid' => 20, 'name' => 'UK Stock', 'type' => 3],
['wid' => 30, 'name' => 'Unused Warehouse', 'type' => 3],
]);
$repository = $this->createMock(WarehouseRepository::class);
$repository->expects(self::exactly(3))->method('saveMetadata');
$lockManager = $this->createMock(LockManagerInterface::class);
$lockManager->method('lock')->willReturn(true);
$lockManager->expects(self::once())->method('unlock');
$result = (new WarehouseSynchronizer(
$fetcher,
$repository,
$lockManager
))->synchronize();
self::assertSame(['warehouses' => 3], $result);
}
}