move findBinary from Builder to CommandExecutor.
This commit is contained in:
parent
1307240622
commit
8d8714746c
|
@ -116,7 +116,7 @@ class Builder implements LoggerAwareInterface, BuildLogger
|
|||
$this->store = Store\Factory::getStore('Build');
|
||||
$this->pluginExecutor = new Plugin\Util\Executor($this->buildPluginFactory($build), $this);
|
||||
|
||||
$this->commandExecutor = new CommandExecutor($this, $this->quiet, $this->verbose);
|
||||
$this->commandExecutor = new CommandExecutor($this, PHPCI_DIR, $this->quiet, $this->verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,6 +228,16 @@ class Builder implements LoggerAwareInterface, BuildLogger
|
|||
return $this->commandExecutor->getLastOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param $binary
|
||||
* @return null|string
|
||||
*/
|
||||
public function findBinary($binary)
|
||||
{
|
||||
return $this->commandExecutor->findBinary($binary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry to the build log.
|
||||
* @param string|string[] $message
|
||||
|
@ -363,39 +373,6 @@ class Builder implements LoggerAwareInterface, BuildLogger
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param $binary
|
||||
* @return null|string
|
||||
*/
|
||||
public function findBinary($binary)
|
||||
{
|
||||
if (is_string($binary)) {
|
||||
$binary = array($binary);
|
||||
}
|
||||
|
||||
foreach ($binary as $bin) {
|
||||
// Check project root directory:
|
||||
if (is_file(PHPCI_DIR . $bin)) {
|
||||
return PHPCI_DIR . $bin;
|
||||
}
|
||||
|
||||
// Check Composer bin dir:
|
||||
if (is_file(PHPCI_DIR . 'vendor/bin/' . $bin)) {
|
||||
return PHPCI_DIR . 'vendor/bin/' . $bin;
|
||||
}
|
||||
|
||||
// Use "which"
|
||||
$which = trim(shell_exec('which ' . $bin));
|
||||
|
||||
if (!empty($which)) {
|
||||
return $which;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a logger instance on the object
|
||||
*
|
||||
|
|
|
@ -24,18 +24,27 @@ class CommandExecutor
|
|||
|
||||
protected $lastOutput;
|
||||
|
||||
/**
|
||||
* The path which findBinary will look in.
|
||||
* @var string
|
||||
*/
|
||||
protected $rootDir;
|
||||
|
||||
/**
|
||||
* @param BuildLogger $logger
|
||||
* @param $rootDir
|
||||
* @param bool $quiet
|
||||
* @param bool $verbose
|
||||
*/
|
||||
public function __construct(BuildLogger $logger, &$quiet = false, &$verbose = false)
|
||||
public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->quiet = $quiet;
|
||||
$this->verbose = $verbose;
|
||||
|
||||
$this->lastOutput = array();
|
||||
|
||||
$this->rootDir = $rootDir;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,4 +85,37 @@ class CommandExecutor
|
|||
{
|
||||
return implode(PHP_EOL, $this->lastOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a binary required by a plugin.
|
||||
* @param $binary
|
||||
* @return null|string
|
||||
*/
|
||||
public function findBinary($binary)
|
||||
{
|
||||
if (is_string($binary)) {
|
||||
$binary = array($binary);
|
||||
}
|
||||
|
||||
foreach ($binary as $bin) {
|
||||
// Check project root directory:
|
||||
if (is_file($this->rootDir . $bin)) {
|
||||
return $this->rootDir . $bin;
|
||||
}
|
||||
|
||||
// Check Composer bin dir:
|
||||
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
|
||||
return $this->rootDir . 'vendor/bin/' . $bin;
|
||||
}
|
||||
|
||||
// Use "which"
|
||||
$which = trim(shell_exec('which ' . $bin));
|
||||
|
||||
if (!empty($which)) {
|
||||
return $which;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class CommandExecutorTest extends ProphecyTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
$mockBuildLogger = $this->prophesize('\PHPCI\BuildLogger');
|
||||
$this->testedExecutor = new CommandExecutor($mockBuildLogger->reveal());
|
||||
$this->testedExecutor = new CommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
|
||||
}
|
||||
|
||||
public function testGetLastOutput_ReturnsOutputOfCommand()
|
||||
|
@ -45,4 +45,11 @@ class CommandExecutorTest extends ProphecyTestCase
|
|||
$returnValue = $this->testedExecutor->executeCommand(array('eerfdcvcho "%s"', 'Hello World'));
|
||||
$this->assertFalse($returnValue);
|
||||
}
|
||||
|
||||
public function testFindBinary_ReturnsPathInSpecifiedRoot()
|
||||
{
|
||||
$thisFileName = "CommandExecutorTest.php";
|
||||
$returnValue = $this->testedExecutor->findBinary($thisFileName);
|
||||
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue