Skip to content

Commit

Permalink
Merge pull request #1 from daniel-mueller/Issue154
Browse files Browse the repository at this point in the history
Issue154 first working draft of feature to optionally define name and…
  • Loading branch information
daniel-mueller committed Aug 21, 2015
2 parents facf911 + 912d828 commit 3920494
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
53 changes: 50 additions & 3 deletions src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
use Humbug\Process\AbstractExecutableFinder;
use Humbug\Process\ComposerExecutableFinder;
use Humbug\Exception\RuntimeException;
use Humbug\Config;
use Humbug\Config\JsonParser;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\PhpExecutableFinder;

class PhpunitExecutableFinder extends AbstractExecutableFinder
{

/**
* @var Config
*/
private $config;

/**
* @return string
*/
Expand Down Expand Up @@ -65,14 +72,15 @@ private function findComposer()
*/
private function findPhpunit()
{
$probable = ['phpunit', 'phpunit.phar'];
$probable = $this->getExecutableNames();
$dir = $this->getPhpunitExecutablePath();
$finder = new ExecutableFinder;
foreach ($probable as $name) {
if ($path = $finder->find($name, null, [getcwd()])) {
if ($path = $finder->find($name, null, [$dir])) {
return $this->makeExecutable($path);
}
}
$result = $this->searchNonExecutables($probable, [getcwd()]);
$result = $this->searchNonExecutables($probable, [$dir]);
if (!is_null($result)) {
return $result;
}
Expand Down Expand Up @@ -102,4 +110,43 @@ protected function makeExecutable($path)
return sprintf('%s %s', $phpFinder->find(), $path);
}
}

private function setConfig()
{
$config = (new JsonParser())->parseFile();
$this->config = new Config($config);
}

/**
* @return Config
*/
private function getConfig()
{
if (is_null($this->config)) {
$this->setConfig();
}
return $this->config;
}

/**
* @return array
*/
private function getExecutableNames()
{
if ($this->getConfig()->isPhpunitConfigured()) {
return [basename($this->getConfig()->getPhpunitConfig()->phar)];
}
return ['phpunit', 'phpunit.phar'];
}

/**
* @return string
*/
private function getPhpunitExecutablePath()
{
if ($this->getConfig()->isPhpunitConfigured()) {
return dirname($this->getConfig()->getPhpunitConfig()->phar);
}
return getcwd();
}
}
23 changes: 23 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ public function getSource()
return $this->config->source;
}

public function getPhpunitConfig()
{
if (!isset($this->config->phpunit)) {
throw new JsonConfigException(
'Phpunit destination is not included in configuration file'
);
}
if (!isset($this->config->phpunit->phar)) {
throw new JsonConfigException(
'full path of phpunit executable is not included in configuration file'
);
}

return $this->config->phpunit;
}

/**
* @return bool
*/
public function isPhpunitConfigured() {
return isset($this->config->phpunit);
}

public function getTimeout()
{
if (!isset($this->config->timeout)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function testFinderCanLocatePhpunitExecutable()
{
$finder = new PhpunitExecutableFinder();
$result = $finder->find();
$this->assertRegExp('%phpunit(\\.bat|\\.phar)?$%', $result);
$this->assertRegExp('%phpunit.*(\\.bat|\\.phar)?$%', $result);
}
}

0 comments on commit 3920494

Please sign in to comment.