Skip to content

Commit

Permalink
DT-1141: Fixes #3980: pre-commit validation doesn't catch code standa…
Browse files Browse the repository at this point in the history
…rds errors. (#3981)

* DT-1141: Fixes #3980: pre-commit validation doesn't catch code standards errors.

* Fixed automated test.
  • Loading branch information
danepowell committed Jan 16, 2020
1 parent 947ee58 commit 70363c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Robo/Commands/Internal/GitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function preCommitHook($changed_files) {
$collection->addCode(
function () use ($changed_files) {
return $this->invokeCommands([
'tests:phpcs:sniff:modified',
'tests:phpcs:sniff:staged',
'tests:twig:lint:files' => ['file_list' => $changed_files],
'tests:yaml:lint:files' => ['file_list' => $changed_files],
]);
Expand Down
20 changes: 20 additions & 0 deletions src/Robo/Commands/Tests/PhpcsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public function sniffModified() {
return $exit_code;
}

/**
* Executes PHPCS against staged files in repo.
*
* This command will execute PHP Codesniffer against staged files
* if those files are a subset of the phpcs.filesets filesets.
*
* @command tests:phpcs:sniff:staged
* @aliases tpss
*
* @return int
* Exit code.
*/
public function sniffStaged() {
$this->say("Sniffing staged files in repo...");
$arguments = "--filter=GitStaged";
$exit_code = $this->doSniff($arguments);

return $exit_code;
}

/**
* Executes PHP Code Sniffer using specified options/arguments.
*
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/src/SetupGitHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function testGitPreCommitHook() {
$process = new Process("./.git/hooks/pre-commit", $this->sandboxInstance);
$process->run();
$output = $process->getOutput();
// @todo Assert only changed files are validated.
$this->assertContains('tests:phpcs:sniff:modified', $output);
$this->assertContains('tests:phpcs:sniff:staged', $output);
$this->assertContains('tests:yaml:lint:files', $output);
$this->assertContains('tests:twig:lint:files', $output);
}
Expand Down

0 comments on commit 70363c1

Please sign in to comment.