diff --git a/.gitignore b/.gitignore index 5c17a79b..8083e865 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ composer.lock composer.phar config.php .DS_Store +.settings/ +.project +.buildpath diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 58c50d70..b1aec937 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -96,17 +96,17 @@ class Builder if(is_array($message)) { - $cb = $this->logCallback; - - $message = array_map(function($item) use ($cb, $prefix) + + foreach ($message as $item) { - if(is_callable($cb)) + if(is_callable($this->logCallback)) { - $cb($prefix . $item); + $this->logCallback($prefix . $item); } - + $this->log .= $prefix . $item . PHP_EOL; - }, $message); + } + } else { diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 910743d5..1ed744fc 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -7,10 +7,15 @@ class PhpUnit implements \PHPCI\Plugin protected $directory; protected $args; protected $phpci; + + /** + * @var string $runFrom When running PHPUnit with an XML config, the command is run from this directory + */ + protected $runFrom; -/** - * @var string $xmlConfigFile The path of an xml config for PHPUnit - */ + /** + * @var string $xmlConfigFile The path of an xml config for PHPUnit + */ protected $xmlConfigFile; public function __construct(\PHPCI\Builder $phpci, array $options = array()) @@ -18,6 +23,7 @@ class PhpUnit implements \PHPCI\Plugin $this->phpci = $phpci; $this->directory = isset($options['directory']) ? $options['directory'] : null; $this->xmlConfigFile = isset($options['config']) ? $options['config'] : null; + $this->runFrom = isset($options['run_from']) ? $options['run_from'] : null; $this->args = isset($options['args']) ? $options['args'] : ''; } @@ -48,7 +54,15 @@ class PhpUnit implements \PHPCI\Plugin } else { - return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $configPath); + if ($this->runFrom) { + $curdir = getcwd(); + chdir($this->phpci->buildPath.'/'.$this->runFrom); + } + $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $configPath); + if ($this->runFrom) { + chdir($curdir); + } + return $success; } } diff --git a/README.md b/README.md index 5ab5bb3b..1c611cc4 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a - "PHPUnit-ubuntu-fix.xml" directory: - "tests/" + run_from: "phpunit/" php_mess_detector: allow_failures: true php_code_sniffer: