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

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Fake;
6
7use ZtdQuery\Config\ZtdConfig;
8use ZtdQuery\ResultSelectRunner;
9use ZtdQuery\Schema\TableDefinitionRegistry;
10use ZtdQuery\Session;
11use ZtdQuery\Shadow\ShadowStore;
12
13/**
14 * Builds sessions over fakes, for tests that are about the session itself.
15 *
16 * A session takes five things before it will answer anything, and a test
17 * asking what one of its methods does has no interest in four of them.
18 */
19final class SessionUnderTest
20{
21    /**
22     * Answers a session over an empty shadow.
23     *
24     * @return Session The session
25     */
26    public static function plain(): Session
27    {
28        return self::over(new ShadowStore());
29    }
30
31    /**
32     * Answers a session over a shadow the caller has already filled.
33     *
34     * @param ShadowStore $store Shadow the session writes into
35     *
36     * @return Session The session
37     */
38    public static function over(ShadowStore $store): Session
39    {
40        $registry = new TableDefinitionRegistry();
41
42        return new Session(
43            new FakeSqlRewriter($store, $registry),
44            $store,
45            new ResultSelectRunner(),
46            ZtdConfig::default(),
47            new FakeConnection(),
48            registry: $registry,
49        );
50    }
51}
52