calls[] = compact('scope', 'parameters'); $this->value = $resolver(); return 'fresh'; } }; $caches = new class($cache) extends UpstreamQueryCacheFactory { public string $requestedSource = ''; public function __construct(private readonly UpstreamQueryCache $cache) { } public function forSource(string $source): UpstreamQueryCache { $this->requestedSource = $source; return $this->cache; } }; $information = new class extends UpstreamBusinessInformation { public array $calls = []; public function __construct() { } public function snapshot(string $scope, array $parameters): array { $this->calls[] = compact('scope', 'parameters'); return ['scope' => $scope, 'parameters' => $parameters]; } }; $refresher = new OperationsReplicaSnapshotRefresher($caches, $information); $this->assertSame('operations_replica', $refresher->sourceKey()); $this->assertSame('fresh', $refresher->refresh(compact('scope', 'parameters'))); $this->assertSame('operations_replica', $caches->requestedSource); $this->assertSame([compact('scope', 'parameters')], $cache->calls); $this->assertSame([compact('scope', 'parameters')], $information->calls); $this->assertSame(['scope' => $scope, 'parameters' => $parameters], $cache->value); } public static function snapshotScopes(): array { return [ 'company' => ['company-information.read', ['page' => 2, 'perPage' => 50]], 'store' => ['store-information.read', ['page' => 1, 'perPage' => 25]], 'trademark' => ['trademark-information.read', ['page' => 3, 'perPage' => 100]], ]; } public function test_unknown_business_snapshot_scope_is_rejected_before_connecting_to_an_upstream(): void { /** @var UpstreamBusinessInformation $information */ $information = (new ReflectionClass(UpstreamBusinessInformation::class))->newInstanceWithoutConstructor(); $this->expectException(InvalidArgumentException::class); $information->snapshot('unknown.scope', []); } }