From e233b47a4c492624b37bbe8aa440ba7ff30995da Mon Sep 17 00:00:00 2001 From: Armin Vieweg Date: Sat, 28 Oct 2023 15:30:44 +0200 Subject: [PATCH] [TEST] Add functional test to ensure working -n (--no-interactive) mode EditorConfigCLI will ask the user to continue, if more than 500 files are found. This needs to get confirmed interactively. When --no-interaction (-n) is given, this check should get bypassed. Then, all files no matter how much, will get processed. Closes: #20 --- README.md | 2 +- src/Application.php | 2 - .../CommandNoInteractionModeTest.php | 64 +++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/Functional/EditorConfig/CommandNoInteractionModeTest.php diff --git a/README.md b/README.md index a1d2c86..d95ae27 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ The ``ec`` binary supports the following options: | ``--compact`` | ``-c`` | Only shows only files with issues, not the issues itself. | | ``--uncovered`` | ``-u`` | Lists all files which are not covered by .editorconfig. | | ``--verbose`` | ``-v`` | Shows additional informations, like detailed info about internal time tracking and which binary files have been skipped. | -| ``--no-interaction`` | ``-n`` | Do not ask for confirmation, if more than 500 files found. | +| ``--no-interaction`` | ``-n`` | Do not ask for confirmation, if more than 500 files found and continue scanning. | | ``--no-error-on-exit`` | | By default ``ec`` returns code 2 when issues occurred. With this option set return code is always 0. | **Tip:** The "usage" section on ``ec``'s help page shows some examples. diff --git a/src/Application.php b/src/Application.php index b506705..cc6ce83 100644 --- a/src/Application.php +++ b/src/Application.php @@ -179,11 +179,9 @@ protected function executing(Input $input, Output $output): int } if ($count > 500 && !$input->getOption('no-interaction') && !$io->confirm('Continue?', false)) { - // @codeCoverageIgnoreStart $io->writeln('Canceled.'); return $returnValue; // Early return - // @codeCoverageIgnoreEnd } if (!empty($this->scanner->getSkippingRules())) { diff --git a/tests/Functional/EditorConfig/CommandNoInteractionModeTest.php b/tests/Functional/EditorConfig/CommandNoInteractionModeTest.php new file mode 100644 index 0000000..fb93d08 --- /dev/null +++ b/tests/Functional/EditorConfig/CommandNoInteractionModeTest.php @@ -0,0 +1,64 @@ + <<workspacePath . '/' . 'valid' . $i . '.txt', 'Test file no. ' . $i . PHP_EOL); + } + } + + public function testAskForConfirmation(): void + { + $command = new Application(); + $command->setAutoExit(false); + $commandTester = new CommandTester($command); + $commandTester->setInputs(['n']); + $commandTester->execute(['-d' => $this->workspacePath]); + self::assertStringContainsString('Found 501 files to scan.', $commandTester->getDisplay()); + self::assertStringContainsString('Canceled.', $commandTester->getDisplay()); + + $commandTester = new CommandTester($command); + $commandTester->setInputs(['yes']); + $commandTester->execute(['-d' => $this->workspacePath]); + self::assertSame(2, $commandTester->getStatusCode()); + self::assertStringContainsString('Found 1 issue in 1 file', $commandTester->getDisplay()); + } + + public function testSkipAskingForConfirmationInNoInteractionMode(): void + { + $command = new Application(); + $command->setAutoExit(false); + $commandTester = new CommandTester($command); + $commandTester->execute(['-d' => $this->workspacePath, '-n' => true]); + self::assertStringContainsString('Found 501 files to scan.', $commandTester->getDisplay()); + self::assertSame(2, $commandTester->getStatusCode()); + self::assertStringContainsString('Found 1 issue in 1 file', $commandTester->getDisplay()); + + $commandTester = new CommandTester($command); + $commandTester->execute(['-d' => $this->workspacePath, '--no-interaction' => true]); + self::assertStringContainsString('Found 501 files to scan.', $commandTester->getDisplay()); + self::assertSame(2, $commandTester->getStatusCode()); + self::assertStringContainsString('Found 1 issue in 1 file', $commandTester->getDisplay()); + } +}