Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
|
57.14% |
4 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| TestRunConfirmation | |
100.00% |
17 / 17 |
|
100.00% |
10 / 10 |
|
57.14% |
4 / 7 |
|
100.00% |
3 / 3 |
15.38 | |
100.00% |
1 / 1 |
| confirm | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
5 | |||
| showWarning | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| inputIsInteractive | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
|
25.00% |
1 / 4 |
|
100.00% |
1 / 1 |
6.80 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Quma\Migrations; |
| 6 | |
| 7 | final class TestRunConfirmation |
| 8 | { |
| 9 | public function confirm(bool $yes): bool |
| 10 | { |
| 11 | $this->showWarning(); |
| 12 | |
| 13 | if ($yes) { |
| 14 | return true; |
| 15 | } |
| 16 | |
| 17 | if (!$this->inputIsInteractive()) { |
| 18 | echo "\nUse --yes to confirm test-run execution in non-interactive shells.\n"; |
| 19 | |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | // Interactive readline() needs a real TTY; non-interactive safety behavior is covered above. |
| 24 | // @codeCoverageIgnoreStart |
| 25 | $answer = readline('Continue? [y/N] '); |
| 26 | |
| 27 | if (!is_string($answer) || !in_array(strtolower(trim($answer)), ['y', 'yes'], true)) { |
| 28 | echo "Aborted.\n"; |
| 29 | |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | return true; |
| 34 | |
| 35 | // @codeCoverageIgnoreEnd |
| 36 | } |
| 37 | |
| 38 | private function showWarning(): void |
| 39 | { |
| 40 | echo |
| 41 | "\n\033[1;31mWarning\033[0m: --test-run executes migrations before rolling the database transaction back.\n" |
| 42 | ; |
| 43 | echo "SQL migrations are sent to the database.\n"; |
| 44 | echo "TPQL migrations are rendered, so PHP template code runs.\n"; |
| 45 | echo "PHP migrations are required and executed.\n"; |
| 46 | echo "Rollback only covers database changes in the transaction.\n"; |
| 47 | echo |
| 48 | "File writes, HTTP calls, queues, emails, logs, cache writes, and other external side effects are not undone.\n" |
| 49 | ; |
| 50 | } |
| 51 | |
| 52 | private function inputIsInteractive(): bool |
| 53 | { |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 55 | } |
| 56 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 9 | public function confirm(bool $yes): bool |
| 10 | { |
| 11 | $this->showWarning(); |
| 12 | |
| 13 | if ($yes) { |
| 14 | return true; |
| 9 | public function confirm(bool $yes): bool |
| 10 | { |
| 11 | $this->showWarning(); |
| 12 | |
| 13 | if ($yes) { |
| 17 | if (!$this->inputIsInteractive()) { |
| 18 | echo "\nUse --yes to confirm test-run execution in non-interactive shells.\n"; |
| 19 | |
| 20 | return false; |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 55 | } |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 55 | } |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 55 | } |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 54 | return defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); |
| 55 | } |
| 41 | "\n\033[1;31mWarning\033[0m: --test-run executes migrations before rolling the database transaction back.\n" |
| 42 | ; |
| 43 | echo "SQL migrations are sent to the database.\n"; |
| 44 | echo "TPQL migrations are rendered, so PHP template code runs.\n"; |
| 45 | echo "PHP migrations are required and executed.\n"; |
| 46 | echo "Rollback only covers database changes in the transaction.\n"; |
| 47 | echo |
| 48 | "File writes, HTTP calls, queues, emails, logs, cache writes, and other external side effects are not undone.\n" |
| 49 | ; |
| 50 | } |