packages/ztd-query-core/tests/Fake/StubPlatform.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Fake;
6
7use ZtdQuery\Connection\ConnectionInterface;
8use ZtdQuery\Platform;
9use ZtdQuery\Platform\CopySupport;
10use ZtdQuery\Platform\MissingResultColumnTypeResolver;
11use ZtdQuery\Platform\ParameterBindingCompiler;
12use ZtdQuery\Platform\ResultColumnTypeResolver;
13use ZtdQuery\Rewrite\SqlRewriter;
14use ZtdQuery\Schema\TableDefinitionRegistry;
15use ZtdQuery\Schema\ViewDefinitionSet;
16use ZtdQuery\Shadow\ShadowStore;
17
18/**
19 * Supplies controlled dialect services and exposes the state allocated by core.
20 */
21final class StubPlatform implements Platform
22{
23    /**
24     * The virtual row store allocated by the executor, exposed for assertions.
25     */
26    public ShadowStore $store;
27
28    /**
29     * Retain the supplied services and optionally expose the core-owned row store.
30     * @param-out ShadowStore $store
31     */
32    public function __construct(
33        private readonly SqlRewriter $rewriter,
34        private readonly ?CopySupport $copy = null,
35        private readonly ?ParameterBindingCompiler $compiler = null,
36        private readonly ResultColumnTypeResolver $resolver = new MissingResultColumnTypeResolver(),
37        ?ShadowStore &$store = null,
38    ) {
39        $store ??= new ShadowStore();
40        $this->store = &$store;
41    }
42
43    /**
44     * {@inheritDoc}
45     */
46    public function reflectSchema(ConnectionInterface $connection): TableDefinitionRegistry
47    {
48        return new TableDefinitionRegistry();
49    }
50
51    /**
52     * {@inheritDoc}
53     */
54    public function reflectViews(ConnectionInterface $connection): ViewDefinitionSet
55    {
56        return new ViewDefinitionSet();
57    }
58
59    /**
60     * {@inheritDoc}
61     */
62    public function createRewriter(ShadowStore $store, TableDefinitionRegistry $registry, ViewDefinitionSet $views): SqlRewriter
63    {
64        $this->store = $store;
65        return $this->rewriter;
66    }
67
68    /**
69     * {@inheritDoc}
70     */
71    public function copySupport(): ?CopySupport
72    {
73        return $this->copy;
74    }
75
76    /**
77     * {@inheritDoc}
78     */
79    public function parameterBindingCompiler(): ?ParameterBindingCompiler
80    {
81        return $this->compiler;
82    }
83
84    /**
85     * {@inheritDoc}
86     */
87    public function resultColumnTypeResolver(): ResultColumnTypeResolver
88    {
89        return $this->resolver;
90    }
91}
92