CaiWuXiTong/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php
WuYongJie 87c1ea80bf 修复本地经营信息直读分页参数丢失 (#10)
## 任务占用与边界

- 任务名称:修复本地经营信息直读分页参数丢失
- 实际开发者:WuYongJie
- 目标结果:公司、店铺、商标信息页面在本地直读模式下不再因分页参数丢失返回 500。
- 实际修改路径:\`app/Business/UpstreamBusinessInformation.php\`;\`tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php\`
- 上游 \`source_key\` / \`scope\`:\`operations_replica\`;\`company-information.read\`、\`store-information.read\`、\`trademark-information.read\`
- 明确不修改:上游连接资料、查询范围、共享快照刷新器、数据库迁移、生产配置、页面视觉和部署。

## 开工与合并前碰撞检查

- [x] 已在开工和合并前分别执行 \`scripts/codex-task-preflight.ps1\`
- [x] 已检查最新 \`origin/main\` 与全部远程任务分支
- [x] 无目标路径或公共契约重叠;历史共享库验证分支仅涉及其他测试文件

## 实际改动

- 将三个本地页面 resolver 中只写在 \`compact()\` 字符串里的分页变量,改为显式数组参数,使 PHP 箭头函数正确捕获 \`$page\`、\`$perPage\`。
- 新增回归测试:实际执行三个页面的 resolver,并断言固定快照收到正确分页参数。
- 无新增 scope、接口、权限、表结构、查询字段或缓存策略。

## 验证证据

- [x] PHP 语法检查:两个改动文件通过。
- [x] 相关单元测试:19 passed,57 assertions。
- [x] 受影响管理页面功能测试:4 passed,270 assertions。
- [x] 对比 \`origin/main...任务分支\` 已逐文件复查:仅 2 个目标文件,+88 / -3;无敏感文件或无关改动。
- [x] 同类扫描:三个错误 resolver 已全部改为显式参数;保留的 \`compact('page', 'perPage')\` 位于普通闭包中,变量已通过 \`use\` 正确捕获。

## 风险与回滚

- [x] 不涉及金额、权限、审批、数据库迁移、生产配置、数据修复或部署。
- [x] 未提交 \`.env\`、密码、Token、私钥、真实财务数据、生产日志或构建产物。
- [x] 无前端改动,\`DESIGN.md\` 不适用。
- 回滚方式:回退本次 Squash 合并提交即可;不会影响生产共享快照路径,因为生产不启用本地直读模式。

## 合并前复查

- [x] PR 已移除 \`WIP:\`,测试与自审已补齐。
- [x] 当前任务 Codex 已按完整 diff 自审,通过后执行 Squash merge、核验远程 \`main\` 并清理任务分支。

Reviewed-on: http://git.1080p.hk/WuYongJie/CaiWuXiTong/pulls/10
2026-08-04 19:22:48 +08:00

77 lines
2.4 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use App\Business\UpstreamBusinessInformation;
use Closure;
use Modules\EcommerceFinance\Services\UpstreamQueryCache;
use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory;
use Tests\TestCase;
class UpstreamBusinessInformationTest extends TestCase
{
/**
* @dataProvider businessInformationPages
*/
public function test_local_direct_page_resolver_passes_pagination_to_its_fixed_snapshot(
string $section,
string $page,
string $scope,
): void {
$cache = new class extends UpstreamQueryCache {
public array $calls = [];
public function __construct()
{
}
public function remember(string $scope, array $parameters, Closure $resolver): mixed
{
$this->calls[] = compact('scope', 'parameters');
return $resolver();
}
};
$caches = new class($cache) extends UpstreamQueryCacheFactory {
public function __construct(private readonly UpstreamQueryCache $cache)
{
}
public function forSource(string $source): UpstreamQueryCache
{
return $this->cache;
}
};
$information = new class($caches) extends UpstreamBusinessInformation {
public array $snapshots = [];
public function snapshot(string $scope, array $parameters): array
{
$this->snapshots[] = compact('scope', 'parameters');
return ['data' => [], 'total' => 0];
}
};
$this->app['request']->merge(['page' => 3]);
$paginator = $information->paginate($section, $page, 25);
$expected = ['scope' => $scope, 'parameters' => ['page' => 3, 'perPage' => 25]];
$this->assertSame(3, $paginator->currentPage());
$this->assertSame($expected, $cache->calls[0]);
$this->assertSame($expected, $information->snapshots[0]);
}
public static function businessInformationPages(): array
{
return [
'company' => ['company-management', 'basic-information', 'company-information.read'],
'store' => ['store-management', 'basic-information', 'store-information.read'],
'trademark' => ['trademark-management', 'information', 'trademark-information.read'],
];
}
}