Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Bootstrap | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| within | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createDatabase | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| releaseDatabase | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| runJobs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Testing; |
| 6 | |
| 7 | use Celema\Quma\Connection; |
| 8 | use Celema\Quma\Database as QumaDatabase; |
| 9 | use Closure; |
| 10 | use Cosray\App; |
| 11 | use Cosray\Bootstrap as CmsBootstrap; |
| 12 | use Cosray\Config; |
| 13 | use 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 | */ |
| 21 | final 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 | } |