packages/ztd-query-core/tests/Fake/FakePlatform.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 * Minimal database semantics for core tests, without session construction.
20 */
21final class FakePlatform implements Platform
22{
23 /**
24 * Retain the catalog source for reflection.
25 */
26 public function __construct(private readonly FakeSchemaReflector $reflector = new FakeSchemaReflector())
27 {
28 }
29
30 /**
31 * {@inheritDoc}
32 */
33 public function reflectSchema(ConnectionInterface $connection): TableDefinitionRegistry
34 {
35 $registry = new TableDefinitionRegistry();
36 $parser = new FakeSchemaParser();
37 foreach ($this->reflector->reflectAll() as $name => $sql) {
38 $definition = $parser->parse($sql);
39 if ($definition !== null) {
40 $registry->register($name, $definition);
41 }
42 }
43 return $registry;
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public function reflectViews(ConnectionInterface $connection): ViewDefinitionSet
50 {
51 return new ViewDefinitionSet();
52 }
53
54 /**
55 * {@inheritDoc}
56 */
57 public function createRewriter(ShadowStore $store, TableDefinitionRegistry $registry, ViewDefinitionSet $views): SqlRewriter
58 {
59 return new FakeSqlRewriter($store, $registry);
60 }
61
62 /**
63 * {@inheritDoc}
64 */
65 public function copySupport(): ?CopySupport
66 {
67 return null;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 public function parameterBindingCompiler(): ?ParameterBindingCompiler
74 {
75 return null;
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 public function resultColumnTypeResolver(): ResultColumnTypeResolver
82 {
83 return new MissingResultColumnTypeResolver();
84 }
85}
86