From 9b4c35a11e12f3aad75f836780049ef2714ec678 Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:53:01 +0100 Subject: [PATCH 1/7] 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); } From f5c7f85bedc75c20cb39231de52d70ee2b427c5b Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:54:23 +0100 Subject: [PATCH 2/7] Add ability to specify sub path and override global ignore list in phpci.yml --- PHPCI/Plugin/PhpCodeSniffer.php | 19 ++++++++++++++++--- PHPCI/Plugin/PhpCpd.php | 20 +++++++++++++++++--- PHPCI/Plugin/PhpMessDetector.php | 21 ++++++++++++++++++--- 3 files changed, 51 insertions(+), 9 deletions(-) mode change 100644 => 100755 PHPCI/Plugin/PhpCodeSniffer.php mode change 100644 => 100755 PHPCI/Plugin/PhpCpd.php mode change 100644 => 100755 PHPCI/Plugin/PhpMessDetector.php diff --git a/PHPCI/Plugin/PhpCodeSniffer.php b/PHPCI/Plugin/PhpCodeSniffer.php old mode 100644 new mode 100755 index 5986f724..ccaf69a7 --- a/PHPCI/Plugin/PhpCodeSniffer.php +++ b/PHPCI/Plugin/PhpCodeSniffer.php @@ -47,6 +47,17 @@ class PhpCodeSniffer implements \PHPCI\Plugin */ protected $encoding; + /** + * @var string, based on the assumption the root may not hold the code to be + * tested, exteds the base path + */ + protected $path; + + /** + * @var array - paths to ignore + */ + protected $ignore; + /** * @param \PHPCI\Builder $phpci * @param array $options @@ -59,6 +70,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin $this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2'; $this->tab_width = isset($options['tab_width']) ? $options['tab_width'] : ''; $this->encoding = isset($options['encoding']) ? $options['encoding'] : ''; + $this->path = (isset($options['path'])) ? $options['path'] : ''; + $this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore; } /** @@ -67,8 +80,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin public function execute() { $ignore = ''; - if (count($this->phpci->ignore)) { - $ignore = ' --ignore=' . implode(',', $this->phpci->ignore); + if (count($this->ignore)) { + $ignore = ' --ignore=' . implode(',', $this->ignore); } if (strpos($this->standard, '/') !== false) { @@ -93,6 +106,6 @@ class PhpCodeSniffer implements \PHPCI\Plugin } $cmd = PHPCI_BIN_DIR . 'phpcs %s %s %s %s %s "%s"'; - return $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $tab_width, $encoding, $this->phpci->buildPath); + return $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $tab_width, $encoding, $this->phpci->buildPath . $this->path); } } diff --git a/PHPCI/Plugin/PhpCpd.php b/PHPCI/Plugin/PhpCpd.php old mode 100644 new mode 100755 index 5ec0bd9f..ecb54077 --- a/PHPCI/Plugin/PhpCpd.php +++ b/PHPCI/Plugin/PhpCpd.php @@ -21,11 +21,25 @@ class PhpCpd implements \PHPCI\Plugin protected $args; protected $phpci; + /** + * @var string, based on the assumption the root may not hold the code to be + * tested, exteds the base path + */ + protected $path; + + /** + * @var array - paths to ignore + */ + protected $ignore; + public function __construct(\PHPCI\Builder $phpci, array $options = array()) { $this->phpci = $phpci; $this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath; $this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2'; + $this->path = (isset($options['path'])) ? $options['path'] : ''; + $this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore; + } /** @@ -34,15 +48,15 @@ class PhpCpd implements \PHPCI\Plugin public function execute() { $ignore = ''; - if (count($this->phpci->ignore)) { + if (count($this->ignore)) { $map = function ($item) { return ' --exclude ' . (substr($item, -1) == '/' ? substr($item, 0, -1) : $item); }; - $ignore = array_map($map, $this->phpci->ignore); + $ignore = array_map($map, $this->ignore); $ignore = implode('', $ignore); } - return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd %s "%s"', $ignore, $this->phpci->buildPath); + return $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd %s "%s"', $ignore, $this->phpci->buildPath.$this->path); } } diff --git a/PHPCI/Plugin/PhpMessDetector.php b/PHPCI/Plugin/PhpMessDetector.php old mode 100644 new mode 100755 index 545cb070..40ca3fcf --- a/PHPCI/Plugin/PhpMessDetector.php +++ b/PHPCI/Plugin/PhpMessDetector.php @@ -27,6 +27,17 @@ class PhpMessDetector implements \PHPCI\Plugin */ protected $suffixes; + /** + * @var string, based on the assumption the root may not hold the code to be + * tested, exteds the base path + */ + protected $path; + + /** + * @var array - paths to ignore + */ + protected $ignore; + /** * Array of PHPMD rules. Can be one of the builtins (codesize, unusedcode, naming, design, controversial) * or a filenname (detected by checking for a / in it), either absolute or relative to the project root. @@ -44,6 +55,10 @@ class PhpMessDetector implements \PHPCI\Plugin $this->suffixes = isset($options['suffixes']) ? (array)$options['suffixes'] : array('php'); + $this->ignore = (isset($options['ignore'])) ? (array)$options['ignore'] : $this->phpci->ignore; + + $this->path = (isset($options['path'])) ? $options['path'] : ''; + $this->rules = isset($options['rules']) ? (array)$options['rules'] : array('codesize', 'unusedcode', 'naming'); foreach ($this->rules as &$rule) { if ($rule[0] !== '/' && strpos($rule, '/') !== FALSE) { @@ -58,8 +73,8 @@ class PhpMessDetector implements \PHPCI\Plugin public function execute() { $ignore = ''; - if (count($this->phpci->ignore)) { - $ignore = ' --exclude ' . implode(',', $this->phpci->ignore); + if (count($this->ignore)) { + $ignore = ' --exclude ' . implode(',', $this->ignore); } $suffixes = ''; @@ -68,6 +83,6 @@ class PhpMessDetector implements \PHPCI\Plugin } $cmd = PHPCI_BIN_DIR . 'phpmd "%s" text %s %s %s'; - return $this->phpci->executeCommand($cmd, $this->phpci->buildPath, implode(',', $this->rules), $ignore, $suffixes); + return $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $this->path, implode(',', $this->rules), $ignore, $suffixes); } } From df32fcbbd475de987e4532cc9d9c65f7dfc77371 Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:56:13 +0100 Subject: [PATCH 3/7] Fix bug resulting in UI displaying errors (level of error reporting enabled may have been partially cause) when project object not set. --- PHPCI/View/BuildsTable.phtml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/PHPCI/View/BuildsTable.phtml b/PHPCI/View/BuildsTable.phtml index 98cdce91..6d72c9a2 100644 --- a/PHPCI/View/BuildsTable.phtml +++ b/PHPCI/View/BuildsTable.phtml @@ -6,6 +6,7 @@ + getStatus()) { @@ -37,7 +38,14 @@ switch($build->getStatus()) ?> #getId(), 6, '0', STR_PAD_LEFT); ?> - getProject()->getTitle(); ?> + + getProject())) { + print $build->getProject()->getTitle(); + } else { + print ' - '; + } + ?> getCommitId(); ?> getBranch(); ?> From 459269f61f50ad9086935164647b85349eaaa49d Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:56:54 +0100 Subject: [PATCH 4/7] Fix notice on command line when PHPCI_DB_HOST not set --- PHPCI/Plugin/Mysql.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) mode change 100644 => 100755 PHPCI/Plugin/Mysql.php diff --git a/PHPCI/Plugin/Mysql.php b/PHPCI/Plugin/Mysql.php old mode 100644 new mode 100755 index 5138116e..e6ac7d54 --- a/PHPCI/Plugin/Mysql.php +++ b/PHPCI/Plugin/Mysql.php @@ -20,7 +20,7 @@ use PDO; */ class Mysql implements \PHPCI\Plugin { - + /** * @var \PHPCI\Builder */ @@ -30,7 +30,7 @@ class Mysql implements \PHPCI\Plugin protected $host; protected $user; protected $pass; - + /** * Database Connection * @var PDO @@ -43,7 +43,8 @@ class Mysql implements \PHPCI\Plugin $this->queries = $options; $config = \b8\Database::getConnection('write')->getDetails(); - $this->host = PHPCI_DB_HOST; + + $this->host =(defined('PHPCI_DB_HOST')) ? PHPCI_DB_HOST : null; $this->user = $config['user']; $this->pass = $config['pass']; @@ -63,11 +64,11 @@ class Mysql implements \PHPCI\Plugin public function execute() { $success = true; - + try { $opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); $this->pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts); - + foreach ($this->queries as $query) { if (!is_array($query)) { // Simple query @@ -86,28 +87,28 @@ class Mysql implements \PHPCI\Plugin return $success; } - + protected function executeFile($query) { if (!isset($query['file'])) { throw new \Exception("Import statement must contain a 'file' key"); } - + $import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']); if (!is_readable($import_file)) { throw new \Exception("Cannot open SQL import file: $import_file"); } - + $database = isset($query['database'])? $this->phpci->interpolate($query['database']): null; - + $import_command = $this->getImportCommand($import_file, $database); if (!$this->phpci->executeCommand($import_command)) { throw new \Exception("Unable to execute SQL file"); } - + return true; } - + /** * Builds the MySQL import command required to import/execute the specified file * @param string $import_file Path to file, relative to the build root @@ -119,7 +120,7 @@ class Mysql implements \PHPCI\Plugin 'bz2' => '| bzip2 --decompress', 'gz' => '| gzip --decompress', ); - + $extension = strtolower(pathinfo($import_file, PATHINFO_EXTENSION)); $decomp_cmd = ''; if (array_key_exists($extension, $decompression)) { From fd3097514b1460d318ff90e6b6ed7728a0a54e51 Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:57:44 +0100 Subject: [PATCH 5/7] Fix fatal error when $project is not set, which prevents access to Interface --- PHPCI/View/Project/view.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/View/Project/view.phtml b/PHPCI/View/Project/view.phtml index 3067f5ed..9f419eff 100644 --- a/PHPCI/View/Project/view.phtml +++ b/PHPCI/View/Project/view.phtml @@ -1,5 +1,5 @@
-

Project: getTitle(); ?>

+

Project: getTitle() : ' - '; ?>

From 1fb292fefbe4e20ce4a3fc82cd1bddbdf396c31d Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 09:59:53 +0100 Subject: [PATCH 6/7] updated --- PHPCI/build/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 PHPCI/build/.gitignore diff --git a/PHPCI/build/.gitignore b/PHPCI/build/.gitignore old mode 100644 new mode 100755 From 741c1bab55f3c43975810bc2c4968bc0a7bb209b Mon Sep 17 00:00:00 2001 From: Stephen Brooks Date: Wed, 18 Sep 2013 10:01:21 +0100 Subject: [PATCH 7/7] updated --- build/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build/.gitignore diff --git a/build/.gitignore b/build/.gitignore old mode 100644 new mode 100755