From e8f23784e8975a8d3f13a2bce2f2223ed7488fa2 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 21 Aug 2015 10:48:51 +0200 Subject: [PATCH 1/3] Issue154 first working draft of feature to optionally define name and path of phpunit executable --- .../Process/PhpunitExecutableFinder.php | 64 ++++++++++++++++++- src/Config.php | 30 +++++++++ .../Process/PhpunitExecutableFinderTest.php | 2 +- 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php index f8681fe..677c286 100644 --- a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php +++ b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php @@ -13,6 +13,8 @@ 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; @@ -20,6 +22,11 @@ class PhpunitExecutableFinder extends AbstractExecutableFinder { + /** + * @var Config + */ + private $config; + /** * @return string */ @@ -65,10 +72,11 @@ 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); } } @@ -102,4 +110,56 @@ protected function makeExecutable($path) return sprintf('%s %s', $phpFinder->find(), $path); } } + /** + * @return bool + */ + private function isExecutableNameConfigured() + { + return $this->getConfig()->isPhpunitConfigured(); + } + + 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; + } + + private function getPhpunitExecutableName() + { + return $this->getConfig()->getPhpunitConfig()->phar; + } + + /** + * @return array + */ + private function getExecutableNames() + { + if ($this->isExecutableNameConfigured()) { + return $probable[] = $this->getPhpunitExecutableName(); + } + return ['phpunit', 'phpunit.phar']; + } + + /** + * @return string + */ + private function getPhpunitExecutablePath() + { + if ($this->getConfig()->isPhpunitConfigured()) { + return $this->getConfig()->getPhpunitConfig()->path; + } + return getcwd(); + } + } diff --git a/src/Config.php b/src/Config.php index 27f3258..45e7473 100644 --- a/src/Config.php +++ b/src/Config.php @@ -41,6 +41,36 @@ 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( + 'Name of phpunit executable is not included in configuration file' + ); + } + + if (!isset($this->config->phpunit->path)) { + throw new JsonConfigException( + 'Path to 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)) { diff --git a/tests/Adapter/Phpunit/Process/PhpunitExecutableFinderTest.php b/tests/Adapter/Phpunit/Process/PhpunitExecutableFinderTest.php index 018a555..b03d6b8 100644 --- a/tests/Adapter/Phpunit/Process/PhpunitExecutableFinderTest.php +++ b/tests/Adapter/Phpunit/Process/PhpunitExecutableFinderTest.php @@ -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); } } From 6f1d556977832e39ff90e735309f3175cc8405a3 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 21 Aug 2015 11:05:04 +0200 Subject: [PATCH 2/3] Issue154 Only one entry with a full path to executable is needed in the humbug.json --- .../Phpunit/Process/PhpunitExecutableFinder.php | 12 +++++++----- src/Config.php | 9 +-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php index 677c286..41c2f42 100644 --- a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php +++ b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php @@ -80,7 +80,7 @@ private function findPhpunit() return $this->makeExecutable($path); } } - $result = $this->searchNonExecutables($probable, [getcwd()]); + $result = $this->searchNonExecutables($probable, [$dir]); if (!is_null($result)) { return $result; } @@ -135,9 +135,12 @@ private function getConfig() return $this->config; } + /** + * @return string + */ private function getPhpunitExecutableName() { - return $this->getConfig()->getPhpunitConfig()->phar; + return basename($this->getConfig()->getPhpunitConfig()->phar); } /** @@ -146,7 +149,7 @@ private function getPhpunitExecutableName() private function getExecutableNames() { if ($this->isExecutableNameConfigured()) { - return $probable[] = $this->getPhpunitExecutableName(); + return [$this->getPhpunitExecutableName()]; } return ['phpunit', 'phpunit.phar']; } @@ -157,9 +160,8 @@ private function getExecutableNames() private function getPhpunitExecutablePath() { if ($this->getConfig()->isPhpunitConfigured()) { - return $this->getConfig()->getPhpunitConfig()->path; + return dirname($this->getConfig()->getPhpunitConfig()->phar); } return getcwd(); } - } diff --git a/src/Config.php b/src/Config.php index 45e7473..2161752 100644 --- a/src/Config.php +++ b/src/Config.php @@ -48,16 +48,9 @@ public function getPhpunitConfig() 'Phpunit destination is not included in configuration file' ); } - if (!isset($this->config->phpunit->phar)) { throw new JsonConfigException( - 'Name of phpunit executable is not included in configuration file' - ); - } - - if (!isset($this->config->phpunit->path)) { - throw new JsonConfigException( - 'Path to phpunit executable is not included in configuration file' + 'full path of phpunit executable is not included in configuration file' ); } From 912d828f6945012483a5940ad3ae422d076af708 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Fri, 21 Aug 2015 11:16:43 +0200 Subject: [PATCH 3/3] Issue154 removed unnecessary private methods --- .../Process/PhpunitExecutableFinder.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php index 41c2f42..fd92e4d 100644 --- a/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php +++ b/src/Adapter/Phpunit/Process/PhpunitExecutableFinder.php @@ -110,13 +110,6 @@ protected function makeExecutable($path) return sprintf('%s %s', $phpFinder->find(), $path); } } - /** - * @return bool - */ - private function isExecutableNameConfigured() - { - return $this->getConfig()->isPhpunitConfigured(); - } private function setConfig() { @@ -135,21 +128,13 @@ private function getConfig() return $this->config; } - /** - * @return string - */ - private function getPhpunitExecutableName() - { - return basename($this->getConfig()->getPhpunitConfig()->phar); - } - /** * @return array */ private function getExecutableNames() { - if ($this->isExecutableNameConfigured()) { - return [$this->getPhpunitExecutableName()]; + if ($this->getConfig()->isPhpunitConfigured()) { + return [basename($this->getConfig()->getPhpunitConfig()->phar)]; } return ['phpunit', 'phpunit.phar']; }