packages/ztd-query-core/tests/Fake/FakeSchemaReflector.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Fake;
6
7use ZtdQuery\Platform\SchemaReflector;
8
9/**
10 * Fake SchemaReflector backed by an in-memory store.
11 */
12final class FakeSchemaReflector implements SchemaReflector
13{
14 /**
15 * @var array<string, string>
16 */
17 private array $schemas;
18
19 /**
20 * @param array<string, string> $schemas Table name => CREATE TABLE SQL.
21 */
22 public function __construct(array $schemas = [])
23 {
24 $this->schemas = $schemas;
25 }
26
27 /**
28 * Adds table.
29 *
30 * @param string $tableName
31 * @param string $createSql
32 */
33 public function addTable(string $tableName, string $createSql): void
34 {
35 $this->schemas[$tableName] = $createSql;
36 }
37
38 /**
39 * Answers create statement.
40 *
41 * @param string $tableName
42 * @return ?string
43 */
44 public function getCreateStatement(string $tableName): ?string
45 {
46 return $this->schemas[$tableName] ?? null;
47 }
48
49 /**
50 * Reflect all.
51 *
52 */
53 public function reflectAll(): array
54 {
55 return $this->schemas;
56 }
57}
58