-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/Functional/EditorConfig/CommandNoInteractionModeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types = 1); | ||
namespace Armin\EditorconfigCli\Tests\Functional\EditorConfig; | ||
|
||
use Armin\EditorconfigCli\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class CommandNoInteractionModeTest extends AbstractTestCase | ||
{ | ||
protected $editorConfig = <<<TXT | ||
root = true | ||
[*] | ||
insert_final_newline = true | ||
TXT; | ||
|
||
protected $files = [ | ||
'invalid.txt' => <<<TXT | ||
Missing new line in this file. | ||
TXT, | ||
]; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
// Create 500 valid text files | ||
for ($i = 1; $i <= 500; $i++) { | ||
file_put_contents($this->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()); | ||
} | ||
} |