Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TestRunConfirmation
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 confirm
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
 showWarning
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
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 Celema\Quma\Migrations;
6
7use Celema\Console\Io;
8
9final class TestRunConfirmation
10{
11    public function confirm(Io $io, bool $yes): bool
12    {
13        $this->showWarning($io);
14
15        if ($yes) {
16            return true;
17        }
18
19        if (!$io->interactive()) {
20            $io->line("\nUse --yes to confirm test-run execution in non-interactive shells.");
21
22            return false;
23        }
24
25        if (!$io->confirm('Continue?')) {
26            $io->line('Aborted.');
27
28            return false;
29        }
30
31        return true;
32    }
33
34    private function showWarning(Io $io): void
35    {
36        $io->line(
37            "\n<bright-red>Warning</bright-red>: --test-run executes migrations before rolling the database transaction back.",
38        );
39        $io->line('SQL migrations are sent to the database.');
40        $io->line('TPQL migrations are rendered, so PHP template code runs.');
41        $io->line('PHP migrations are required and executed.');
42        $io->line('Rollback only covers database changes in the transaction.');
43        $io->line(
44            'File writes, HTTP calls, queues, emails, logs, cache writes, and other external side effects are not undone.',
45        );
46    }
47}