81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Closure;
|
|
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
|
|
use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository;
|
|
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
|
|
use Modules\EcommerceFinance\Repositories\SupplierPayableRepository;
|
|
use Modules\EcommerceFinance\Services\JianSunQueryCache;
|
|
use Modules\EcommerceFinance\Services\JianSunSnapshotRefresher;
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
|
|
class JianSunSnapshotRefresherTest extends TestCase
|
|
{
|
|
public function test_pinduoduo_flow_filter_is_preserved_during_background_refresh(): void
|
|
{
|
|
$cache = new class extends JianSunQueryCache {
|
|
public mixed $value = null;
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function refresh(string $scope, array $parameters, Closure $resolver): string
|
|
{
|
|
$this->value = $resolver();
|
|
|
|
return 'fresh';
|
|
}
|
|
};
|
|
|
|
$pinduoduo = new class extends PinduoduoSpreadBillRepository {
|
|
public array $arguments = [];
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function paginate(
|
|
?string $storeName = null,
|
|
?string $fromDate = null,
|
|
?string $toDate = null,
|
|
?string $flowType = null,
|
|
int $page = 1,
|
|
int $pageSize = 25
|
|
): array {
|
|
$this->arguments = func_get_args();
|
|
|
|
return ['rows' => [], 'total' => 0];
|
|
}
|
|
};
|
|
|
|
$edgeBanding = (new ReflectionClass(EdgeBandingRepository::class))->newInstanceWithoutConstructor();
|
|
$goods = (new ReflectionClass(GoodsReconciliationRepository::class))->newInstanceWithoutConstructor();
|
|
$supplier = (new ReflectionClass(SupplierPayableRepository::class))->newInstanceWithoutConstructor();
|
|
$refresher = new JianSunSnapshotRefresher($cache, $edgeBanding, $goods, $pinduoduo, $supplier);
|
|
|
|
$status = $refresher->refresh([
|
|
'scope' => 'pinduoduo-bills.list',
|
|
'parameters' => [
|
|
'filters' => [
|
|
'store_name' => '测试店铺',
|
|
'from' => '2026-07-01',
|
|
'to' => '2026-07-23',
|
|
'flow_type' => 'expense',
|
|
],
|
|
'page' => 3,
|
|
'limit' => 50,
|
|
],
|
|
]);
|
|
|
|
$this->assertSame('fresh', $status);
|
|
$this->assertSame(
|
|
['测试店铺', '2026-07-01', '2026-07-23', 'expense', 3, 50],
|
|
$pinduoduo->arguments
|
|
);
|
|
}
|
|
}
|