-
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.
[FEATURE] Detect and output warning when files being staged in Git ar…
…e physically missing
- Loading branch information
Showing
6 changed files
with
126 additions
and
2 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
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Armin\EditorconfigCli\EditorConfig\Rules; | ||
|
||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
class FileUnavailableException extends \Exception | ||
{ | ||
private SplFileInfo $unavailableFile; | ||
|
||
public function getUnavailableFile(): SplFileInfo | ||
{ | ||
return $this->unavailableFile; | ||
} | ||
|
||
public function setUnavailableFile(SplFileInfo $unavailableFile): self | ||
{ | ||
$this->unavailableFile = $unavailableFile; | ||
|
||
return $this; | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
tests/Functional/EditorConfig/CommandGitUnavailableFilesTest.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,58 @@ | ||
<?php declare(strict_types = 1); | ||
namespace Armin\EditorconfigCli\Tests\Functional\EditorConfig; | ||
|
||
use Armin\EditorconfigCli\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class CommandGitUnavailableFilesTest extends AbstractTestCase | ||
{ | ||
private const GIT_BINARY = 'git'; | ||
|
||
protected $editorConfig = <<<TXT | ||
root = true | ||
[*] | ||
insert_final_newline = true | ||
TXT; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->workspacePath = sys_get_temp_dir() . '/current_editorconfig_cli_test'; | ||
|
||
parent::setUp(); | ||
|
||
// Copy test files | ||
copy(__DIR__ . '/../../Fixtures/image.jpg', $this->workspacePath . '/' . 'image.jpg'); | ||
copy(__DIR__ . '/../../Fixtures/document.pdf', $this->workspacePath . '/' . 'document.pdf'); | ||
copy(__DIR__ . '/../../Fixtures/kreis-weiß.svg', $this->workspacePath . '/' . 'kreis-weiß.svg'); | ||
|
||
// Set up Git repository for testing | ||
exec('cd ' . $this->workspacePath . ' && ' . self::GIT_BINARY . ' init', $result, $returnCode); | ||
if ($returnCode !== 0) { | ||
throw new \RuntimeException('Unable to create test git repository!'); | ||
} | ||
|
||
// Add files to git stage | ||
exec('cd ' . $this->workspacePath . ' && ' . self::GIT_BINARY . ' add image.jpg'); | ||
exec('cd ' . $this->workspacePath . ' && ' . self::GIT_BINARY . ' add document.pdf'); | ||
exec('cd ' . $this->workspacePath . ' && ' . self::GIT_BINARY . ' add kreis-weiß.svg'); | ||
|
||
// Remove files physically | ||
exec('rm -f ' . $this->workspacePath . '/image.jpg'); | ||
exec('rm -f ' . $this->workspacePath . '/document.pdf'); | ||
} | ||
|
||
public function testUnavailableFiles() | ||
{ | ||
$command = new Application(); | ||
$command->setAutoExit(false); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute(['-d' => $this->workspacePath, '--no-progress' => true, '--git-only' => true]); | ||
|
||
self::assertSame(1, $commandTester->getStatusCode()); | ||
self::assertStringContainsString('[WARNING] Found 2 unavailable files not being scanned!', $commandTester->getDisplay()); | ||
self::assertStringContainsString('* ' . $this->workspacePath . '/document.pdf', $commandTester->getDisplay()); | ||
self::assertStringContainsString('* ' . $this->workspacePath . '/image.jpg', $commandTester->getDisplay()); | ||
} | ||
} |