From 9b4c35a11e12f3aad75f836780049ef2714ec678 Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:53:01 +0100 Subject: [PATCH] Add ability to specify project sub-path and set flag for code coverage --- PHPCI/Plugin/PhpUnit.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) mode change 100644 => 100755 PHPCI/Plugin/PhpUnit.php diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php old mode 100644 new mode 100755 index c3fdb0a2..6925a772 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -24,12 +24,20 @@ class PhpUnit implements \PHPCI\Plugin * @var string|string[] $directory The directory (or array of dirs) to run PHPUnit on */ protected $directory; - + /** * @var string $runFrom When running PHPUnit with an XML config, the command is run from this directory */ protected $runFrom; + /** + * @var string, in cases where tests files are in a sub path of the /tests path, + * allows this path to be set in the config. + */ + protected $path; + + protected $coverage = ""; + /** * @var string|string[] $xmlConfigFile The path (or array of paths) of an xml config for PHPUnit */ @@ -54,6 +62,14 @@ class PhpUnit implements \PHPCI\Plugin if (isset($options['args'])) { $this->args = $options['args']; } + + if (isset($options['path'])) { + $this->path = $options['path']; + } + + if (isset($options['coverage'])) { + $this->coverage = " --coverage-html {$options['coverage']} "; + } } /** @@ -72,7 +88,7 @@ class PhpUnit implements \PHPCI\Plugin if ($this->directory !== null) { $success &= $this->runDir($this->directory); } - + return $success; } @@ -86,9 +102,9 @@ class PhpUnit implements \PHPCI\Plugin chdir($this->phpci->buildPath.'/'.$this->runFrom); } - $cmd = PHPCI_BIN_DIR . 'phpunit %s -c "%s"'; + $cmd = PHPCI_BIN_DIR . 'phpunit %s -c "%s" ' . $this->coverage . $this->path; $success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath); - + if ($this->runFrom) { chdir($curdir); }