修复本地经营信息直读分页参数丢失 #10
@ -68,7 +68,10 @@ class UpstreamBusinessInformation
|
||||
'company-information.read',
|
||||
$page,
|
||||
$perPage,
|
||||
fn () => $this->snapshot('company-information.read', compact('page', 'perPage')),
|
||||
fn () => $this->snapshot('company-information.read', [
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -109,7 +112,10 @@ SQL);
|
||||
'store-information.read',
|
||||
$page,
|
||||
$perPage,
|
||||
fn () => $this->snapshot('store-information.read', compact('page', 'perPage')),
|
||||
fn () => $this->snapshot('store-information.read', [
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@ -154,7 +160,10 @@ SQL);
|
||||
'trademark-information.read',
|
||||
$page,
|
||||
$perPage,
|
||||
fn () => $this->snapshot('trademark-information.read', compact('page', 'perPage')),
|
||||
fn () => $this->snapshot('trademark-information.read', [
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
<?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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user