Skip to content

Commit

Permalink
Merge pull request #97 from Dealerdirect/feature/add-save-success-ver…
Browse files Browse the repository at this point in the history
…ification

Verify the `installed_paths` after save
  • Loading branch information
Potherca authored Jan 19, 2020
2 parents f8729d0 + 5277f67 commit 6589501
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private function loadInstalledPaths()
if (preg_match($regex, $output, $match) === 1) {
$phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $match[0]);
$phpcsInstalledPaths = trim($phpcsInstalledPaths);

if ($phpcsInstalledPaths !== '') {
$this->installedPaths = explode(',', $phpcsInstalledPaths);
}
Expand Down Expand Up @@ -278,6 +278,9 @@ private function saveInstalledPaths()
);

$exitCode = $this->processExecutor->execute($command, $configResult, $phpcsPath);
if ($exitCode === 0) {
$exitCode = $this->verifySaveSuccess();
}

if ($exitCode === 0) {
$this->io->write($configMessage);
Expand All @@ -292,6 +295,40 @@ private function saveInstalledPaths()
return $exitCode;
}

/**
* Verify that the paths which were expected to be saved, have been.
*
* @return int Exit code. 0 for success, 1 for failure.
*/
private function verifySaveSuccess()
{
$exitCode = 1;
$expectedPaths = $this->installedPaths;

// Request the currently set installed paths after the save.
$this->loadInstalledPaths();

$registeredPaths = array_intersect($this->installedPaths, $expectedPaths);
$registeredCount = count($registeredPaths);
$expectedCount = count($expectedPaths);

if ($expectedCount === $registeredCount) {
$exitCode = 0;
}

if ($exitCode === 1 && $this->io->isVerbose()) {
$verificationMessage = sprintf(
"Paths to external standards found by the plugin: <info>%s</info>\n"
. 'Actual paths registered with PHPCS: <info>%s</info>',
implode(', ', $expectedPaths),
implode(', ', $this->installedPaths)
);
$this->io->write($verificationMessage);
}

return $exitCode;
}

/**
* Get the path to the current PHP version being used.
*
Expand Down

0 comments on commit 6589501

Please sign in to comment.