init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\LingxingErp\Test\Unit\Model\Warehouse;
|
||||
|
||||
use Esun\LingxingErp\Model\Api\Client;
|
||||
use Esun\LingxingErp\Model\Api\Endpoint;
|
||||
use Esun\LingxingErp\Model\Sync\LogWriter;
|
||||
use Esun\LingxingErp\Model\Warehouse\WarehouseFetcher;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class WarehouseFetcherTest extends TestCase
|
||||
{
|
||||
public function testFetchesOnlyTypeThreeWarehouses(): void
|
||||
{
|
||||
$client = $this->createMock(Client::class);
|
||||
$client->expects(self::once())
|
||||
->method('post')
|
||||
->willReturnCallback(function (string $path, array $request): array {
|
||||
self::assertSame(Endpoint::WAREHOUSE_LIST, $path);
|
||||
self::assertSame(3, $request['type']);
|
||||
self::assertSame('0,1', $request['is_delete']);
|
||||
return [
|
||||
'code' => 0,
|
||||
'data' => [[
|
||||
'wid' => 200,
|
||||
'name' => 'Warehouse ' . $request['type'],
|
||||
'type' => $request['type'],
|
||||
]],
|
||||
'total' => 1,
|
||||
];
|
||||
});
|
||||
$logWriter = $this->createMock(LogWriter::class);
|
||||
$logWriter->expects(self::once())->method('write');
|
||||
|
||||
$result = (new WarehouseFetcher($client, $logWriter))->fetchAll();
|
||||
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame([200], array_column($result, 'wid'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user