Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
8 / 8
80.00% covered (warning)
80.00%
4 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TestRunConfirmation
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
8 / 8
80.00% covered (warning)
80.00%
4 / 5
100.00% covered (success)
100.00%
3 / 3
7.39
100.00% covered (success)
100.00%
1 / 1
 confirm
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
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
 inputIsInteractive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
2.50
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 (!$this->inputIsInteractive()) {
20            $io->echoln("\nUse --yes to confirm test-run execution in non-interactive shells.");
21
22            return false;
23        }
24
25        // Interactive prompting needs a real TTY; non-interactive safety behavior is covered above.
26        // @codeCoverageIgnoreStart
27        if (!$io->confirm('Continue?')) {
28            $io->echoln('Aborted.');
29
30            return false;
31        }
32
33        return true;
34
35        // @codeCoverageIgnoreEnd
36    }
37
38    private function showWarning(Io $io): void
39    {
40        $io->echoln(
41            "\n<bright-red>Warning</bright-red>: --test-run executes migrations before rolling the database transaction back.",
42        );
43        $io->echoln('SQL migrations are sent to the database.');
44        $io->echoln('TPQL migrations are rendered, so PHP template code runs.');
45        $io->echoln('PHP migrations are required and executed.');
46        $io->echoln('Rollback only covers database changes in the transaction.');
47        $io->echoln(
48            'File writes, HTTP calls, queues, emails, logs, cache writes, and other external side effects are not undone.',
49        );
50    }
51
52    private function inputIsInteractive(): bool
53    {
54        return defined('STDIN') && stream_isatty(STDIN);
55    }
56}