From a0528d2cc444fc2b02497487914c82fe11a0f61d Mon Sep 17 00:00:00 2001 From: meadsteve Date: Wed, 15 May 2013 13:01:47 +0100 Subject: [PATCH 1/2] Added argument to Phpunit plugin: config. This takes the path to an xml configuration file which will be run instead of the specified directory. --- PHPCI/Plugin/PhpUnit.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 34817f11..682521e4 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -8,19 +8,30 @@ 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->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); + if ($this->xmlConfigFile === null) { + $curdir = getcwd(); + chdir($this->phpci->buildPath); + $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' ' . $this->phpci->buildPath . $this->directory); + chdir($curdir); + } + else { + $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $this->xmlConfigFile ); + } return $success; } From 24e709f77e1d4e9c0e84947220699afd45b415a5 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Wed, 15 May 2013 13:41:30 +0100 Subject: [PATCH 2/2] Modified the PHPunit plugin so that it can take multiple config files and dirs and will combine the results of each. --- PHPCI/Plugin/PhpUnit.php | 54 ++++++++++++++++++++++++++++++++++------ README.md | 6 ++++- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 682521e4..910743d5 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -16,23 +16,61 @@ class PhpUnit implements \PHPCI\Plugin 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() { - if ($this->xmlConfigFile === null) { - $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); } - else { - $success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpunit ' . $this->args . ' -c ' . $this->phpci->buildPath . $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: