diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 34817f11..910743d5 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -8,20 +8,69 @@ class PhpUnit implements \PHPCI\Plugin protected $args; protected $phpci; +/** + * @var string $xmlConfigFile The path of an xml config for PHPUnit + */ + protected $xmlConfigFile; + public function __construct(\PHPCI\Builder $phpci, array $options = array()) { $this->phpci = $phpci; - $this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath; + $this->directory = isset($options['directory']) ? $options['directory'] : null; + $this->xmlConfigFile = isset($options['config']) ? $options['config'] : null; $this->args = isset($options['args']) ? $options['args'] : ''; } public function execute() { - $curdir = getcwd(); - chdir($this->phpci->buildPath); - $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory); - chdir($curdir); + $success = true; + + // Run any config files first. This can be either a single value or an array. + if ($this->xmlConfigFile !== null) + { + $success &= $this->runConfigFile($this->xmlConfigFile); + } + + // Run any dirs next. Again this can be either a single value or an array. + if ($this->directory !== null) + { + $success &= $this->runDir($this->directory); + } return $success; } + + protected function runConfigFile($configPath) + { + if (is_array($configPath)) + { + return $this->recurseArg($configPath, array($this, "runConfigFile")); + } + else + { + return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $configPath); + } + } + + protected function runDir($dirPath) + { + if (is_array($dirPath)) { + return $this->recurseArg($dirPath, array($this, "runConfigFile")); + } + else { + $curdir = getcwd(); + chdir($this->phpci->buildPath); + $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $dirPath); + chdir($curdir); + return $success; + } + } + + protected function recurseArg($array, $callable) { + $success = true; + foreach($array as $subItem) { + $success &= call_user_func($callable, $subItem); + } + return $success; + } } \ No newline at end of file diff --git a/README.md b/README.md index 7006ef2a..b4b4ef35 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,11 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a test: php_unit: - directory: "tests/" + config: + - "PHPUnit-all.xml" + - "PHPUnit-ubuntu-fix.xml" + directory: + - "tests/" php_mess_detector: allow_failures: true php_code_sniffer: