Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git Workflow: do not use just the filename, but full path in reporting #105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions PhpcsChanged/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ function runGitWorkflowForFile(string $gitFile, CliOptions $options, ShellOperat
$phpcsStandard = $options->phpcsStandard;
$warningSeverity = $options->warningSeverity;
$errorSeverity = $options->errorSeverity;
$fileName = $shell->getFileNameFromPath($gitFile);

try {
if (! $shell->isReadable($gitFile)) {
Expand All @@ -356,7 +355,7 @@ function runGitWorkflowForFile(string $gitFile, CliOptions $options, ShellOperat
}
}

$modifiedFilePhpcsMessages = PhpcsMessages::fromPhpcsJson($modifiedFilePhpcsOutput, $fileName);
$modifiedFilePhpcsMessages = PhpcsMessages::fromPhpcsJson($modifiedFilePhpcsOutput, $gitFile);
$hasNewPhpcsMessages = count($modifiedFilePhpcsMessages->getMessages()) > 0;

$unifiedDiff = '';
Expand Down Expand Up @@ -398,7 +397,7 @@ function runGitWorkflowForFile(string $gitFile, CliOptions $options, ShellOperat
}

$debug('processing data...');
return getNewPhpcsMessages($unifiedDiff, PhpcsMessages::fromPhpcsJson($unmodifiedFilePhpcsOutput, $fileName), $modifiedFilePhpcsMessages);
return getNewPhpcsMessages($unifiedDiff, PhpcsMessages::fromPhpcsJson($unmodifiedFilePhpcsOutput, $gitFile), $modifiedFilePhpcsMessages);
}

function reportMessagesAndExit(PhpcsMessages $messages, CliOptions $options, ShellOperator $shell): void {
Expand Down
26 changes: 26 additions & 0 deletions tests/GitWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,32 @@ public function testFullGitWorkflowForMultipleFilesStaged() {
$this->assertEquals($expected->getMessages(), $messages->getMessages());
}

public function testFullGitWorkflowForMultipleFilesStagedWithClashingFilenames() {
$gitFiles = ['foobar.php', 'baz/foobar.php'];
$options = CliOptions::fromArray(['no-cache-git-root' => false, 'git-staged' => false, 'files' => $gitFiles]);
$shell = new TestShell($options, $gitFiles);
$shell->registerExecutable('git');
$shell->registerExecutable('phpcs');
$fixture = $this->fixture->getAddedLineDiff('foobar.php', 'use Foobar;');
$shell->registerCommand("git diff --staged --no-prefix 'foobar.php'", $fixture);
$fixture = $this->fixture->getAddedLineDiff('baz/foobar.php', 'use Baz;');
$shell->registerCommand("git diff --staged --no-prefix 'baz/foobar.php'", $fixture);
$shell->registerCommand("git status --porcelain 'foobar.php'", $this->fixture->getNewFileInfo('foobar.php'));
$shell->registerCommand("git status --porcelain 'baz/foobar.php'", $this->fixture->getNewFileInfo('baz/foobar.php'));
$shell->registerCommand("git ls-files --full-name 'foobar.php'", "files/foobar.php");
$shell->registerCommand("git ls-files --full-name 'baz/foobar.php'", "files/baz/foobar.php");
$shell->registerCommand("git show :0:'files/foobar.php'", $this->phpcs->getResults('foobar.php', [20], 'Found unused symbol Foobar.')->toPhpcsJson());
$shell->registerCommand("git show :0:'files/baz/foobar.php'", $this->phpcs->getResults('baz/foobar.php', [20], 'Found unused symbol Baz.')->toPhpcsJson());
$shell->registerCommand("git rev-parse --show-toplevel", 'run-from-git-root');
$cache = new CacheManager( new TestCache() );
$expected = PhpcsMessages::merge([
$this->phpcs->getResults('foobar.php', [20], 'Found unused symbol Foobar.'),
$this->phpcs->getResults('baz/foobar.php', [20], 'Found unused symbol Baz.'),
]);
$messages = runGitWorkflow($options, $shell, $cache, '\PhpcsChangedTests\Debug');
$this->assertEquals($expected->getMessages(), $messages->getMessages());
}

public function testFullGitWorkflowForUnchangedFileWithPhpcsMessages() {
$gitFile = 'foobar.php';
$options = CliOptions::fromArray(['no-cache-git-root' => false, 'git-staged' => false, 'files' => [$gitFile]]);
Expand Down
Loading