Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Bootstrap
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 within
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createDatabase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 releaseDatabase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 runJobs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Testing;
6
7use Celema\Quma\Connection;
8use Celema\Quma\Database as QumaDatabase;
9use Closure;
10use Cosray\App;
11use Cosray\Bootstrap as CmsBootstrap;
12use Cosray\Config;
13use Override;
14
15/**
16 * The bootstrap of an app that a test case builds: the app's database joins
17 * the test's transaction, and requests run no jobs after their response.
18 *
19 * @internal
20 */
21final class Bootstrap extends CmsBootstrap
22{
23    /**
24     * Every app created by $create is built for a test.
25     *
26     * @template T
27     *
28     * @param Closure(): T $create
29     * @return T
30     */
31    public static function within(Closure $create): mixed
32    {
33        return App::createdWith(static fn(Config $config): self => new self($config), $create);
34    }
35
36    #[Override]
37    protected function createDatabase(Connection $connection): QumaDatabase
38    {
39        return new Database($connection);
40    }
41
42    /** The connection outlives the request, with the test's transaction open. */
43    #[Override]
44    protected function releaseDatabase(): void
45    {
46        $this->db->reset();
47    }
48
49    /** Jobs stay queued, so a test reads what a request queued. */
50    #[Override]
51    protected function runJobs(): void {}
52}