Let CommandExecutor::findBinary throw an exception when the binary is missing.
This commit is contained in:
parent
0b0589557f
commit
63dfab20aa
|
@ -263,12 +263,14 @@ class Builder implements LoggerAwareInterface
|
|||
|
||||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param $binary
|
||||
* @param string $binary
|
||||
* @param bool $quiet
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function findBinary($binary)
|
||||
public function findBinary($binary, $quiet = false)
|
||||
{
|
||||
return $this->commandExecutor->findBinary($binary, $this->buildPath);
|
||||
return $this->commandExecutor->findBinary($binary, $quiet = false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
use \PHPCI\Logging\BuildLogger;
|
||||
use Exception;
|
||||
use PHPCI\Logging\BuildLogger;
|
||||
use Psr\Log\LogLevel;
|
||||
use PHPCI\Helper\Lang;
|
||||
|
||||
/**
|
||||
* Handles running system commands with variables.
|
||||
|
@ -20,7 +20,7 @@ use PHPCI\Helper\Lang;
|
|||
abstract class BaseCommandExecutor implements CommandExecutor
|
||||
{
|
||||
/**
|
||||
* @var \PHPCI\Logging\BuildLogger
|
||||
* @var BuildLogger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
|
@ -144,13 +144,12 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param string $binary
|
||||
* @param null $buildPath
|
||||
* @param bool $quiet
|
||||
* @return null|string
|
||||
*/
|
||||
public function findBinary($binary, $buildPath = null)
|
||||
public function findBinary($binary, $quiet = false)
|
||||
{
|
||||
$binaryPath = null;
|
||||
$composerBin = $this->getComposerBinDir(realpath($buildPath));
|
||||
$composerBin = $this->getComposerBinDir(realpath($this->buildPath));
|
||||
|
||||
if (is_string($binary)) {
|
||||
$binary = array($binary);
|
||||
|
@ -161,30 +160,30 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
|||
|
||||
if (is_dir($composerBin) && is_file($composerBin.'/'.$bin)) {
|
||||
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
||||
$binaryPath = $composerBin . '/' . $bin;
|
||||
break;
|
||||
return $composerBin . '/' . $bin;
|
||||
}
|
||||
|
||||
if (is_file($this->rootDir . $bin)) {
|
||||
$this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
|
||||
$binaryPath = $this->rootDir . $bin;
|
||||
break;
|
||||
return $this->rootDir . $bin;
|
||||
}
|
||||
|
||||
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
|
||||
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
|
||||
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
|
||||
break;
|
||||
return $this->rootDir . 'vendor/bin/' . $bin;
|
||||
}
|
||||
|
||||
$findCmdResult = $this->findGlobalBinary($bin);
|
||||
if (is_file($findCmdResult)) {
|
||||
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
|
||||
$binaryPath = $findCmdResult;
|
||||
break;
|
||||
return $findCmdResult;
|
||||
}
|
||||
}
|
||||
return $binaryPath;
|
||||
|
||||
if ($quiet) {
|
||||
return;
|
||||
}
|
||||
throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,10 +26,13 @@ interface CommandExecutor
|
|||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param string $binary
|
||||
* @param string $buildPath the current build path
|
||||
* @param bool $quiet Returns null instead of throwing an execption.
|
||||
*
|
||||
* @return null|string
|
||||
*
|
||||
* @throws \Exception when no binary has been found and $quiet is false.
|
||||
*/
|
||||
public function findBinary($binary, $buildPath = null);
|
||||
public function findBinary($binary, $quiet = false);
|
||||
|
||||
/**
|
||||
* Set the buildPath property.
|
||||
|
|
|
@ -133,12 +133,6 @@ class Codeception implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
} else {
|
||||
$codecept = $this->phpci->findBinary('codecept');
|
||||
|
||||
if (!$codecept) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'codecept'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --tap ' . $this->args;
|
||||
|
||||
if (IS_WIN) {
|
||||
|
|
|
@ -81,11 +81,6 @@ class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
{
|
||||
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
|
||||
|
||||
if (!$composerLocation) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'composer'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = '';
|
||||
|
||||
if (IS_WIN) {
|
||||
|
|
|
@ -79,15 +79,10 @@ class Pdepend implements \PHPCI\Plugin
|
|||
|
||||
$pdepend = $this->phpci->findBinary('pdepend');
|
||||
|
||||
if (!$pdepend) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'pdepend'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
||||
|
||||
$this->removeBuildArtifacts();
|
||||
|
||||
|
||||
// If we need to ignore directories
|
||||
if (count($this->phpci->ignore)) {
|
||||
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
||||
|
|
|
@ -81,11 +81,6 @@ class Phing implements \PHPCI\Plugin
|
|||
{
|
||||
$phingExecutable = $this->phpci->findBinary('phing');
|
||||
|
||||
if (!$phingExecutable) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'phing'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd[] = $phingExecutable . ' -f ' . $this->getBuildFilePath();
|
||||
|
||||
if ($this->getPropertyFile()) {
|
||||
|
|
|
@ -149,11 +149,6 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
|
||||
$phpcs = $this->phpci->findBinary('phpcs');
|
||||
|
||||
if (!$phpcs) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpcs'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->phpci->logExecOutput(false);
|
||||
|
||||
$cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
|
||||
|
|
|
@ -90,18 +90,13 @@ class PhpCpd implements \PHPCI\Plugin
|
|||
|
||||
$phpcpd = $this->phpci->findBinary('phpcpd');
|
||||
|
||||
if (!$phpcpd) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'phpcpd'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmpfilename = tempnam('/tmp', 'phpcpd');
|
||||
|
||||
$cmd = $phpcpd . ' --log-pmd "%s" %s "%s"';
|
||||
$success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path);
|
||||
|
||||
print $this->phpci->getLastOutput();
|
||||
|
||||
|
||||
list($errorCount, $data) = $this->processReport(file_get_contents($tmpfilename));
|
||||
$this->build->storeMeta('phpcpd-warnings', $errorCount);
|
||||
$this->build->storeMeta('phpcpd-data', $data);
|
||||
|
|
|
@ -69,11 +69,6 @@ class PhpCsFixer implements \PHPCI\Plugin
|
|||
|
||||
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
|
||||
|
||||
if (!$phpcsfixer) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'php-cs-fixer'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = $phpcsfixer . ' fix . %s %s %s';
|
||||
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
||||
|
||||
|
|
|
@ -104,11 +104,6 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
// Check that the binary exists:
|
||||
$checker = $this->phpci->findBinary('phpdoccheck');
|
||||
|
||||
if (!$checker) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpdoccheck'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build ignore string:
|
||||
$ignore = '';
|
||||
if (count($this->ignore)) {
|
||||
|
|
|
@ -80,11 +80,6 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
|
||||
$phploc = $this->phpci->findBinary('phploc');
|
||||
|
||||
if (!$phploc) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phploc'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
|
||||
$output = $this->phpci->getLastOutput();
|
||||
|
||||
|
|
|
@ -121,11 +121,6 @@ class PhpMessDetector implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
|
||||
$phpmdBinaryPath = $this->phpci->findBinary('phpmd');
|
||||
|
||||
if (!$phpmdBinaryPath) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpmd'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->executePhpMd($phpmdBinaryPath);
|
||||
|
||||
list($errorCount, $data) = $this->processReport(trim($this->phpci->getLastOutput()));
|
||||
|
|
|
@ -78,11 +78,6 @@ class PhpParallelLint implements \PHPCI\Plugin
|
|||
|
||||
$phplint = $this->phpci->findBinary('parallel-lint');
|
||||
|
||||
if (!$phplint) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'parallel-lint'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = $phplint . ' %s "%s"';
|
||||
$success = $this->phpci->executeCommand(
|
||||
$cmd,
|
||||
|
|
|
@ -59,11 +59,6 @@ class PhpSpec implements PHPCI\Plugin
|
|||
|
||||
$phpspec = $this->phpci->findBinary(array('phpspec', 'phpspec.php'));
|
||||
|
||||
if (!$phpspec) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpspec'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
|
||||
$output = $this->phpci->getLastOutput();
|
||||
|
||||
|
|
|
@ -197,15 +197,8 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
chdir($this->phpci->buildPath.'/'.$this->runFrom);
|
||||
}
|
||||
|
||||
|
||||
$phpunit = $this->phpci->findBinary('phpunit');
|
||||
|
||||
if (!$phpunit) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpunit'));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$cmd = $phpunit . ' --tap %s -c "%s" ' . $this->coverage . $this->path;
|
||||
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
|
||||
|
||||
|
@ -232,11 +225,6 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
|||
|
||||
$phpunit = $this->phpci->findBinary('phpunit');
|
||||
|
||||
if (!$phpunit) {
|
||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpunit'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = $phpunit . ' --tap %s "%s"';
|
||||
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $directory);
|
||||
chdir($curdir);
|
||||
|
|
|
@ -148,12 +148,7 @@ class XMPP implements \PHPCI\Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$sendxmpp = $this->phpci->findBinary('/usr/bin/sendxmpp');
|
||||
|
||||
if (!$sendxmpp) {
|
||||
$this->phpci->logFailure('Could not find sendxmpp.');
|
||||
return false;
|
||||
}
|
||||
$sendxmpp = $this->phpci->findBinary('sendxmpp');
|
||||
|
||||
/*
|
||||
* Without recipients we can't send notification
|
||||
|
|
|
@ -16,7 +16,8 @@ class CommandExecutorTest extends ProphecyTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
|
||||
$this->testedExecutor = new UnixCommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
|
||||
$class = IS_WIN ? 'PHPCI\Helper\WindowsCommandExecutor' : 'PHPCI\Helper\UnixCommandExecutor';
|
||||
$this->testedExecutor = new $class($mockBuildLogger->reveal(), __DIR__ . "/");
|
||||
}
|
||||
|
||||
public function testGetLastOutput_ReturnsOutputOfCommand()
|
||||
|
@ -52,4 +53,20 @@ class CommandExecutorTest extends ProphecyTestCase
|
|||
$returnValue = $this->testedExecutor->findBinary($thisFileName);
|
||||
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedMessageRegex WorldWidePeace
|
||||
*/
|
||||
public function testFindBinary_ThrowsWhenNotFound()
|
||||
{
|
||||
$thisFileName = "WorldWidePeace";
|
||||
$this->testedExecutor->findBinary($thisFileName);
|
||||
}
|
||||
|
||||
public function testFindBinary_ReturnsNullWihQuietArgument()
|
||||
{
|
||||
$thisFileName = "WorldWidePeace";
|
||||
$this->assertNull($this->testedExecutor->findBinary($thisFileName, true));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue