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

Verify the installed_paths after save #97

Merged
merged 1 commit into from Jan 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/Plugin.php
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);
}
Potherca marked this conversation as resolved.
Show resolved Hide resolved

return $exitCode;
}

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