From 251f4d671394e642ffdcdda07627e361bdcec28e Mon Sep 17 00:00:00 2001 From: MarkMaldaba Date: Wed, 15 May 2013 16:04:55 +0100 Subject: [PATCH 01/15] Fix for running PHP under CGI on Windows machines. In this situation, the environement variables defining the system temp path are not necessarily available to PHP, so sys_get_temp_dir() falls back to using the system path (e.g. C:\WINDOWS), which is normally unwritable. This means that temp-file creation fails. I've added code to detect this situation, and if it occurs we point it to %SystemRoot%\TEMP instead, which usually is present and writable. May not fix 100% of cases, but should fix the vast majority of situations where this may occur. --- PHPCI/Controller/ProjectController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index d424f376..aae1bbb1 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -89,6 +89,15 @@ class ProjectController extends b8\Controller else { $tempPath = sys_get_temp_dir() . '/'; + + // FastCGI fix for Windows machines, where temp path is not available to + // PHP, and defaults to the unwritable system directory. If the temp + // path is pointing to the system directory, shift to the 'TEMP' + // sub-folder, which should also exist, but actually be writable. + if ($tempPath == getenv("SystemRoot") . '/') { + $tempPath = getenv("SystemRoot") . '/TEMP/'; + } + $id = $tempPath . md5(microtime(true)); if (!is_dir($tempPath)) { mkdir($tempPath); From f5e1d969fd631b316d9d3f8de0a743aee509c80d Mon Sep 17 00:00:00 2001 From: MarkMaldaba Date: Wed, 15 May 2013 16:31:21 +0100 Subject: [PATCH 02/15] Follow-up to commit fa7ad2f45ddea003258b0448fd1038650ec2f66b, which replaced short-tags with print statements. This one was missed (or, perhaps, has since crept in). A CodeSniffer test candidate, methinks! --- PHPCI/View/ProjectForm.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/View/ProjectForm.phtml b/PHPCI/View/ProjectForm.phtml index 59342ae0..350c95a4 100644 --- a/PHPCI/View/ProjectForm.phtml +++ b/PHPCI/View/ProjectForm.phtml @@ -68,7 +68,7 @@ $(document).ready(function() // Show sign in with Github button. var el = $('#element-reference'); - var rtn = ; + var rtn = ; var url = 'https://github.com/login/oauth/authorize?client_id=' + window.github_app_id + '&scope=repo&redirect_uri=' + rtn; var btn = $('').addClass('btn btn-inverse').text('Sign in with Github').attr('href', url); From 505b0c0563483bb8da34f47a40c3bd4a0d5262b2 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 15 May 2013 17:25:11 +0100 Subject: [PATCH 03/15] Updating base models to ones generated by the new b8framework generator. Now include strict typing, proper commenting and better formatting. Fixes #13 --- PHPCI/Model/Base/BuildBase.php | 409 ++++++++++++++++++++----------- PHPCI/Model/Base/ProjectBase.php | 266 ++++++++++++-------- PHPCI/Model/Base/UserBase.php | 237 +++++++++++------- 3 files changed, 578 insertions(+), 334 deletions(-) diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index 81e27d4f..55b4182d 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -12,144 +12,146 @@ use b8\Model; */ class BuildBase extends Model { - public static $sleepable= array(); - protected $_tableName = 'build'; - protected $_modelName = 'Build'; - protected $_data = array( - 'id' => null, - 'project_id' => null, - 'commit_id' => null, - 'status' => null, - 'log' => null, - 'branch' => null, - 'created' => null, - 'started' => null, - 'finished' => null, - 'plugins' => null, - ); - protected $_getters = array( - 'id' => 'getId', - 'project_id' => 'getProjectId', - 'commit_id' => 'getCommitId', - 'status' => 'getStatus', - 'log' => 'getLog', - 'branch' => 'getBranch', - 'created' => 'getCreated', - 'started' => 'getStarted', - 'finished' => 'getFinished', - 'plugins' => 'getPlugins', + /** + * @var array + */ + public static $sleepable = array(); - 'Project' => 'getProject', + /** + * @var string + */ + protected $_tableName = 'build'; - ); + /** + * @var string + */ + protected $_modelName = 'Build'; - protected $_setters = array( - 'id' => 'setId', - 'project_id' => 'setProjectId', - 'commit_id' => 'setCommitId', - 'status' => 'setStatus', - 'log' => 'setLog', - 'branch' => 'setBranch', - 'created' => 'setCreated', - 'started' => 'setStarted', - 'finished' => 'setFinished', - 'plugins' => 'setPlugins', + /** + * @var array + */ + protected $_data = array( + 'id' => null, + 'project_id' => null, + 'commit_id' => null, + 'status' => null, + 'log' => null, + 'branch' => null, + 'created' => null, + 'started' => null, + 'finished' => null, + 'plugins' => null, + ); - 'Project' => 'setProject', - ); - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => '11', + /** + * @var array + */ + protected $_getters = array( + 'id' => 'getId', + 'project_id' => 'getProjectId', + 'commit_id' => 'getCommitId', + 'status' => 'getStatus', + 'log' => 'getLog', + 'branch' => 'getBranch', + 'created' => 'getCreated', + 'started' => 'getStarted', + 'finished' => 'getFinished', + 'plugins' => 'getPlugins', + 'Project' => 'getProject', + ); - 'primary_key' => true, - 'auto_increment' => true, - - ), - 'project_id' => array( - 'type' => 'int', - 'length' => '11', - - - - - ), - 'commit_id' => array( - 'type' => 'varchar', - 'length' => '50', - - - - - ), - 'status' => array( - 'type' => 'tinyint', - 'length' => '4', - - - - - ), - 'log' => array( - 'type' => 'text', - 'length' => '', - 'nullable' => true, - - - - ), - 'branch' => array( - 'type' => 'varchar', - 'length' => '50', - - - - - ), - 'created' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - 'started' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - 'finished' => array( - 'type' => 'datetime', - 'length' => '', - 'nullable' => true, - - - - ), - 'plugins' => array( - 'type' => 'text', - 'length' => '', - 'nullable' => true, - - - - ), - ); - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'project_id' => array('columns' => 'project_id'), - 'idx_status' => array('columns' => 'status'), - ); - public $foreignKeys = array( - 'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'), - ); + /** + * @var array + */ + protected $_setters = array( + 'id' => 'setId', + 'project_id' => 'setProjectId', + 'commit_id' => 'setCommitId', + 'status' => 'setStatus', + 'log' => 'setLog', + 'branch' => 'setBranch', + 'created' => 'setCreated', + 'started' => 'setStarted', + 'finished' => 'setFinished', + 'plugins' => 'setPlugins', + 'Project' => 'setProject', + ); + /** + * @var array + */ + public $columns = array( + 'id' => array( + 'type' => 'int', + 'length' => '11', + 'primary_key' => true, + 'auto_increment' => true, + ), + 'project_id' => array( + 'type' => 'int', + 'length' => '11', + ), + 'commit_id' => array( + 'type' => 'varchar', + 'length' => '50', + ), + 'status' => array( + 'type' => 'tinyint', + 'length' => '4', + ), + 'log' => array( + 'type' => 'text', + 'length' => '', + 'nullable' => true, + ), + 'branch' => array( + 'type' => 'varchar', + 'length' => '50', + ), + 'created' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, + ), + 'started' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, + ), + 'finished' => array( + 'type' => 'datetime', + 'length' => '', + 'nullable' => true, + ), + 'plugins' => array( + 'type' => 'text', + 'length' => '', + 'nullable' => true, + ), + ); + + /** + * @var array + */ + public $indexes = array( + 'PRIMARY' => array('unique' => true, 'columns' => 'id'), + 'project_id' => array('columns' => 'project_id'), + 'idx_status' => array('columns' => 'status'), + ); + + /** + * @var array + */ + public $foreignKeys = array( + 'build_ibfk_1' => array('local_col' => 'project_id', 'update' => 'CASCADE', 'delete' => 'CASCADE', 'table' => 'project', 'col' => 'id'), + ); + /** + * Get the value of Id / id. + * + * @return int + */ public function getId() { $rtn = $this->_data['id']; @@ -158,6 +160,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of ProjectId / project_id. + * + * @return int + */ public function getProjectId() { $rtn = $this->_data['project_id']; @@ -166,6 +173,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of CommitId / commit_id. + * + * @return string + */ public function getCommitId() { $rtn = $this->_data['commit_id']; @@ -174,6 +186,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Status / status. + * + * @return int + */ public function getStatus() { $rtn = $this->_data['status']; @@ -182,6 +199,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Log / log. + * + * @return string + */ public function getLog() { $rtn = $this->_data['log']; @@ -190,6 +212,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Branch / branch. + * + * @return string + */ public function getBranch() { $rtn = $this->_data['branch']; @@ -198,6 +225,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Created / created. + * + * @return \DateTime + */ public function getCreated() { $rtn = $this->_data['created']; @@ -212,6 +244,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Started / started. + * + * @return \DateTime + */ public function getStarted() { $rtn = $this->_data['started']; @@ -226,6 +263,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Finished / finished. + * + * @return \DateTime + */ public function getFinished() { $rtn = $this->_data['finished']; @@ -240,6 +282,11 @@ class BuildBase extends Model return $rtn; } + /** + * Get the value of Plugins / plugins. + * + * @return string + */ public function getPlugins() { $rtn = $this->_data['plugins']; @@ -248,13 +295,17 @@ class BuildBase extends Model return $rtn; } - - + /** + * Set the value of Id / id. + * + * Must not be null. + * @param $value int + */ public function setId($value) { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if($this->_data['id'] == $value) + if($this->_data['id'] === $value) { return; } @@ -264,11 +315,17 @@ class BuildBase extends Model $this->_setModified('id'); } + /** + * Set the value of ProjectId / project_id. + * + * Must not be null. + * @param $value int + */ public function setProjectId($value) { $this->_validateNotNull('ProjectId', $value); $this->_validateInt('ProjectId', $value); - if($this->_data['project_id'] == $value) + if($this->_data['project_id'] === $value) { return; } @@ -278,11 +335,17 @@ class BuildBase extends Model $this->_setModified('project_id'); } + /** + * Set the value of CommitId / commit_id. + * + * Must not be null. + * @param $value string + */ public function setCommitId($value) { $this->_validateNotNull('CommitId', $value); $this->_validateString('CommitId', $value); - if($this->_data['commit_id'] == $value) + if($this->_data['commit_id'] === $value) { return; } @@ -292,11 +355,17 @@ class BuildBase extends Model $this->_setModified('commit_id'); } + /** + * Set the value of Status / status. + * + * Must not be null. + * @param $value int + */ public function setStatus($value) { $this->_validateNotNull('Status', $value); $this->_validateInt('Status', $value); - if($this->_data['status'] == $value) + if($this->_data['status'] === $value) { return; } @@ -306,11 +375,16 @@ class BuildBase extends Model $this->_setModified('status'); } + /** + * Set the value of Log / log. + * + * @param $value string + */ public function setLog($value) { $this->_validateString('Log', $value); - if($this->_data['log'] == $value) + if($this->_data['log'] === $value) { return; } @@ -320,11 +394,17 @@ class BuildBase extends Model $this->_setModified('log'); } + /** + * Set the value of Branch / branch. + * + * Must not be null. + * @param $value string + */ public function setBranch($value) { $this->_validateNotNull('Branch', $value); $this->_validateString('Branch', $value); - if($this->_data['branch'] == $value) + if($this->_data['branch'] === $value) { return; } @@ -334,11 +414,16 @@ class BuildBase extends Model $this->_setModified('branch'); } + /** + * Set the value of Created / created. + * + * @param $value \DateTime + */ public function setCreated($value) { $this->_validateDate('Created', $value); - if($this->_data['created'] == $value) + if($this->_data['created'] === $value) { return; } @@ -348,11 +433,16 @@ class BuildBase extends Model $this->_setModified('created'); } + /** + * Set the value of Started / started. + * + * @param $value \DateTime + */ public function setStarted($value) { $this->_validateDate('Started', $value); - if($this->_data['started'] == $value) + if($this->_data['started'] === $value) { return; } @@ -362,11 +452,16 @@ class BuildBase extends Model $this->_setModified('started'); } + /** + * Set the value of Finished / finished. + * + * @param $value \DateTime + */ public function setFinished($value) { $this->_validateDate('Finished', $value); - if($this->_data['finished'] == $value) + if($this->_data['finished'] === $value) { return; } @@ -376,11 +471,16 @@ class BuildBase extends Model $this->_setModified('finished'); } + /** + * Set the value of Plugins / plugins. + * + * @param $value string + */ public function setPlugins($value) { $this->_validateString('Plugins', $value); - if($this->_data['plugins'] == $value) + if($this->_data['plugins'] === $value) { return; } @@ -390,8 +490,6 @@ class BuildBase extends Model $this->_setModified('plugins'); } - - /** * Get the Project model for this Build by Id. * @@ -408,9 +506,23 @@ class BuildBase extends Model return null; } - return \b8\Store\Factory::getStore('Project')->getById($key); + $cacheKey = 'Cache.Project.' . $key; + $rtn = $this->registry->get($cacheKey, null); + + if(empty($rtn)) + { + $rtn = \b8\Store\Factory::getStore('Project')->getById($key); + $this->registry->set($cacheKey, $rtn); + } + + return $rtn; } + /** + * Set Project - Accepts an ID, an array representing a Project or a Project model. + * + * @param $value mixed + */ public function setProject($value) { // Is this an instance of Project? @@ -429,11 +541,14 @@ class BuildBase extends Model return $this->setProjectId($value); } + /** + * Set Project - Accepts a Project model. + * + * @param $value \PHPCI\Model\Project + */ public function setProjectObject(\PHPCI\Model\Project $value) { return $this->setProjectId($value->getId()); } - - } diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index e7a2c915..91ca4c12 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -12,95 +12,109 @@ use b8\Model; */ class ProjectBase extends Model { - public static $sleepable= array(); - protected $_tableName = 'project'; - protected $_modelName = 'Project'; - protected $_data = array( - 'id' => null, - 'title' => null, - 'reference' => null, - 'git_key' => null, - 'type' => null, - 'token' => null, - ); - protected $_getters = array( - 'id' => 'getId', - 'title' => 'getTitle', - 'reference' => 'getReference', - 'git_key' => 'getGitKey', - 'type' => 'getType', - 'token' => 'getToken', - - - ); - - protected $_setters = array( - 'id' => 'setId', - 'title' => 'setTitle', - 'reference' => 'setReference', - 'git_key' => 'setGitKey', - 'type' => 'setType', - 'token' => 'setToken', - - ); - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => '11', - - 'primary_key' => true, - 'auto_increment' => true, - - ), - 'title' => array( - 'type' => 'varchar', - 'length' => '250', - - - - - ), - 'reference' => array( - 'type' => 'varchar', - 'length' => '250', - - - - - ), - 'git_key' => array( - 'type' => 'text', - 'length' => '', - - - - - ), - 'type' => array( - 'type' => 'varchar', - 'length' => '50', - - - - - ), - 'token' => array( - 'type' => 'varchar', - 'length' => '50', - 'nullable' => true, - - - - ), - ); - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - ); - public $foreignKeys = array( - ); - + /** + * @var array + */ + public static $sleepable = array(); + + /** + * @var string + */ + protected $_tableName = 'project'; + + /** + * @var string + */ + protected $_modelName = 'Project'; + + /** + * @var array + */ + protected $_data = array( + 'id' => null, + 'title' => null, + 'reference' => null, + 'git_key' => null, + 'type' => null, + 'token' => null, + ); + + /** + * @var array + */ + protected $_getters = array( + 'id' => 'getId', + 'title' => 'getTitle', + 'reference' => 'getReference', + 'git_key' => 'getGitKey', + 'type' => 'getType', + 'token' => 'getToken', + ); + + /** + * @var array + */ + protected $_setters = array( + 'id' => 'setId', + 'title' => 'setTitle', + 'reference' => 'setReference', + 'git_key' => 'setGitKey', + 'type' => 'setType', + 'token' => 'setToken', + ); + + /** + * @var array + */ + public $columns = array( + 'id' => array( + 'type' => 'int', + 'length' => '11', + 'primary_key' => true, + 'auto_increment' => true, + ), + 'title' => array( + 'type' => 'varchar', + 'length' => '250', + ), + 'reference' => array( + 'type' => 'varchar', + 'length' => '250', + ), + 'git_key' => array( + 'type' => 'text', + 'length' => '', + ), + 'type' => array( + 'type' => 'varchar', + 'length' => '50', + ), + 'token' => array( + 'type' => 'varchar', + 'length' => '50', + 'nullable' => true, + ), + ); + + /** + * @var array + */ + public $indexes = array( + 'PRIMARY' => array('unique' => true, 'columns' => 'id'), + ); + + /** + * @var array + */ + public $foreignKeys = array( + ); + /** + * Get the value of Id / id. + * + * @return int + */ public function getId() { $rtn = $this->_data['id']; @@ -109,6 +123,11 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Title / title. + * + * @return string + */ public function getTitle() { $rtn = $this->_data['title']; @@ -117,6 +136,11 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Reference / reference. + * + * @return string + */ public function getReference() { $rtn = $this->_data['reference']; @@ -125,6 +149,11 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of GitKey / git_key. + * + * @return string + */ public function getGitKey() { $rtn = $this->_data['git_key']; @@ -133,6 +162,11 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Type / type. + * + * @return string + */ public function getType() { $rtn = $this->_data['type']; @@ -141,6 +175,11 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Token / token. + * + * @return string + */ public function getToken() { $rtn = $this->_data['token']; @@ -149,13 +188,17 @@ class ProjectBase extends Model return $rtn; } - - + /** + * Set the value of Id / id. + * + * Must not be null. + * @param $value int + */ public function setId($value) { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if($this->_data['id'] == $value) + if($this->_data['id'] === $value) { return; } @@ -165,11 +208,17 @@ class ProjectBase extends Model $this->_setModified('id'); } + /** + * Set the value of Title / title. + * + * Must not be null. + * @param $value string + */ public function setTitle($value) { $this->_validateNotNull('Title', $value); $this->_validateString('Title', $value); - if($this->_data['title'] == $value) + if($this->_data['title'] === $value) { return; } @@ -179,11 +228,17 @@ class ProjectBase extends Model $this->_setModified('title'); } + /** + * Set the value of Reference / reference. + * + * Must not be null. + * @param $value string + */ public function setReference($value) { $this->_validateNotNull('Reference', $value); $this->_validateString('Reference', $value); - if($this->_data['reference'] == $value) + if($this->_data['reference'] === $value) { return; } @@ -193,11 +248,17 @@ class ProjectBase extends Model $this->_setModified('reference'); } + /** + * Set the value of GitKey / git_key. + * + * Must not be null. + * @param $value string + */ public function setGitKey($value) { $this->_validateNotNull('GitKey', $value); $this->_validateString('GitKey', $value); - if($this->_data['git_key'] == $value) + if($this->_data['git_key'] === $value) { return; } @@ -207,11 +268,17 @@ class ProjectBase extends Model $this->_setModified('git_key'); } + /** + * Set the value of Type / type. + * + * Must not be null. + * @param $value string + */ public function setType($value) { $this->_validateNotNull('Type', $value); $this->_validateString('Type', $value); - if($this->_data['type'] == $value) + if($this->_data['type'] === $value) { return; } @@ -221,11 +288,16 @@ class ProjectBase extends Model $this->_setModified('type'); } + /** + * Set the value of Token / token. + * + * @param $value string + */ public function setToken($value) { $this->_validateString('Token', $value); - if($this->_data['token'] == $value) + if($this->_data['token'] === $value) { return; } @@ -235,10 +307,6 @@ class ProjectBase extends Model $this->_setModified('token'); } - - - - /** * Get Build models by ProjectId for this Project. * diff --git a/PHPCI/Model/Base/UserBase.php b/PHPCI/Model/Base/UserBase.php index 6f4fd31f..5863a61d 100644 --- a/PHPCI/Model/Base/UserBase.php +++ b/PHPCI/Model/Base/UserBase.php @@ -12,85 +12,102 @@ use b8\Model; */ class UserBase extends Model { - public static $sleepable= array(); - protected $_tableName = 'user'; - protected $_modelName = 'User'; - protected $_data = array( - 'id' => null, - 'email' => null, - 'hash' => null, - 'is_admin' => null, - 'name' => null, - ); - protected $_getters = array( - 'id' => 'getId', - 'email' => 'getEmail', - 'hash' => 'getHash', - 'is_admin' => 'getIsAdmin', - 'name' => 'getName', - - - ); - - protected $_setters = array( - 'id' => 'setId', - 'email' => 'setEmail', - 'hash' => 'setHash', - 'is_admin' => 'setIsAdmin', - 'name' => 'setName', - - ); - public $columns = array( - 'id' => array( - 'type' => 'int', - 'length' => '11', - - 'primary_key' => true, - 'auto_increment' => true, - - ), - 'email' => array( - 'type' => 'varchar', - 'length' => '250', - - - - - ), - 'hash' => array( - 'type' => 'varchar', - 'length' => '250', - - - - - ), - 'is_admin' => array( - 'type' => 'tinyint', - 'length' => '1', - - - - - ), - 'name' => array( - 'type' => 'varchar', - 'length' => '250', - - - - - ), - ); - public $indexes = array( - 'PRIMARY' => array('unique' => true, 'columns' => 'id'), - 'idx_email' => array('unique' => true, 'columns' => 'email'), - ); - public $foreignKeys = array( - ); - + /** + * @var array + */ + public static $sleepable = array(); + + /** + * @var string + */ + protected $_tableName = 'user'; + + /** + * @var string + */ + protected $_modelName = 'User'; + + /** + * @var array + */ + protected $_data = array( + 'id' => null, + 'email' => null, + 'hash' => null, + 'is_admin' => null, + 'name' => null, + ); + + /** + * @var array + */ + protected $_getters = array( + 'id' => 'getId', + 'email' => 'getEmail', + 'hash' => 'getHash', + 'is_admin' => 'getIsAdmin', + 'name' => 'getName', + ); + + /** + * @var array + */ + protected $_setters = array( + 'id' => 'setId', + 'email' => 'setEmail', + 'hash' => 'setHash', + 'is_admin' => 'setIsAdmin', + 'name' => 'setName', + ); + + /** + * @var array + */ + public $columns = array( + 'id' => array( + 'type' => 'int', + 'length' => '11', + 'primary_key' => true, + 'auto_increment' => true, + ), + 'email' => array( + 'type' => 'varchar', + 'length' => '250', + ), + 'hash' => array( + 'type' => 'varchar', + 'length' => '250', + ), + 'is_admin' => array( + 'type' => 'tinyint', + 'length' => '1', + ), + 'name' => array( + 'type' => 'varchar', + 'length' => '250', + ), + ); + + /** + * @var array + */ + public $indexes = array( + 'PRIMARY' => array('unique' => true, 'columns' => 'id'), + 'idx_email' => array('unique' => true, 'columns' => 'email'), + ); + + /** + * @var array + */ + public $foreignKeys = array( + ); + /** + * Get the value of Id / id. + * + * @return int + */ public function getId() { $rtn = $this->_data['id']; @@ -99,6 +116,11 @@ class UserBase extends Model return $rtn; } + /** + * Get the value of Email / email. + * + * @return string + */ public function getEmail() { $rtn = $this->_data['email']; @@ -107,6 +129,11 @@ class UserBase extends Model return $rtn; } + /** + * Get the value of Hash / hash. + * + * @return string + */ public function getHash() { $rtn = $this->_data['hash']; @@ -115,6 +142,11 @@ class UserBase extends Model return $rtn; } + /** + * Get the value of IsAdmin / is_admin. + * + * @return int + */ public function getIsAdmin() { $rtn = $this->_data['is_admin']; @@ -123,6 +155,11 @@ class UserBase extends Model return $rtn; } + /** + * Get the value of Name / name. + * + * @return string + */ public function getName() { $rtn = $this->_data['name']; @@ -131,13 +168,17 @@ class UserBase extends Model return $rtn; } - - + /** + * Set the value of Id / id. + * + * Must not be null. + * @param $value int + */ public function setId($value) { $this->_validateNotNull('Id', $value); $this->_validateInt('Id', $value); - if($this->_data['id'] == $value) + if($this->_data['id'] === $value) { return; } @@ -147,11 +188,17 @@ class UserBase extends Model $this->_setModified('id'); } + /** + * Set the value of Email / email. + * + * Must not be null. + * @param $value string + */ public function setEmail($value) { $this->_validateNotNull('Email', $value); $this->_validateString('Email', $value); - if($this->_data['email'] == $value) + if($this->_data['email'] === $value) { return; } @@ -161,11 +208,17 @@ class UserBase extends Model $this->_setModified('email'); } + /** + * Set the value of Hash / hash. + * + * Must not be null. + * @param $value string + */ public function setHash($value) { $this->_validateNotNull('Hash', $value); $this->_validateString('Hash', $value); - if($this->_data['hash'] == $value) + if($this->_data['hash'] === $value) { return; } @@ -175,11 +228,17 @@ class UserBase extends Model $this->_setModified('hash'); } + /** + * Set the value of IsAdmin / is_admin. + * + * Must not be null. + * @param $value int + */ public function setIsAdmin($value) { $this->_validateNotNull('IsAdmin', $value); $this->_validateInt('IsAdmin', $value); - if($this->_data['is_admin'] == $value) + if($this->_data['is_admin'] === $value) { return; } @@ -189,11 +248,17 @@ class UserBase extends Model $this->_setModified('is_admin'); } + /** + * Set the value of Name / name. + * + * Must not be null. + * @param $value string + */ public function setName($value) { $this->_validateNotNull('Name', $value); $this->_validateString('Name', $value); - if($this->_data['name'] == $value) + if($this->_data['name'] === $value) { return; } @@ -203,8 +268,4 @@ class UserBase extends Model $this->_setModified('name'); } - - - - } From 988fa42d92b17e8048809bc5beb9a9661a9e1cfd Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 15 May 2013 18:27:13 +0100 Subject: [PATCH 04/15] Updating PHPCI to use Symfony/Console rather than a series of individual PHP files. --- PHPCI/Builder.php | 36 +++++++--- PHPCI/Command/GenerateCommand.php | 26 +++++++ PHPCI/Command/InstallCommand.php | 114 ++++++++++++++++++++++++++++++ PHPCI/Command/RunCommand.php | 46 ++++++++++++ bootstrap.php | 4 +- console | 17 +++++ cron.php | 18 ----- generate.php | 7 -- install.php | 95 ------------------------- 9 files changed, 231 insertions(+), 132 deletions(-) create mode 100644 PHPCI/Command/GenerateCommand.php create mode 100644 PHPCI/Command/InstallCommand.php create mode 100644 PHPCI/Command/RunCommand.php create mode 100755 console delete mode 100644 cron.php delete mode 100644 generate.php delete mode 100644 install.php diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 2d9607ff..9ba46fad 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -17,11 +17,17 @@ class Builder protected $verbose = false; protected $plugins = array(); protected $build; + protected $logCallback; - public function __construct(Build $build) + public function __construct(Build $build, $logCallback = null) { $this->build = $build; $this->store = Store\Factory::getStore('Build'); + + if(!is_null($logCallback) && is_callable($logCallback)) + { + $this->logCallback = $logCallback; + } } public function execute() @@ -87,24 +93,32 @@ class Builder protected function log($message, $prefix = '') { + if(is_array($message)) { - $message = array_map(function($item) use ($prefix) + $cb = $this->logCallback; + + $message = array_map(function($item) use ($cb, $prefix) { - return $prefix . $item; - }, $message); + if(is_callable($cb)) + { + $cb($prefix . $item); + } - $message = implode(PHP_EOL, $message); - - $this->log .= $message; - print $message . PHP_EOL; + $this->log .= $prefix . $item . PHP_EOL; + }, $message); } else { - $message = $prefix . $message . PHP_EOL; + $message = $prefix . $message; - $this->log .= $message; - print $message; + $this->log .= $message . PHP_EOL; + + if(isset($this->logCallback) && is_callable($this->logCallback)) + { + $cb = $this->logCallback; + $cb($message); + } } $this->build->setLog($this->log); diff --git a/PHPCI/Command/GenerateCommand.php b/PHPCI/Command/GenerateCommand.php new file mode 100644 index 00000000..52b12198 --- /dev/null +++ b/PHPCI/Command/GenerateCommand.php @@ -0,0 +1,26 @@ +setName('phpci:generate') + ->setDescription('Generate models and stores from the database.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $gen = new \b8\Database\CodeGenerator(\b8\Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/'); + $gen->generateModels(); + $gen->generateStores(); + } +} \ No newline at end of file diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php new file mode 100644 index 00000000..2a2cf7c2 --- /dev/null +++ b/PHPCI/Command/InstallCommand.php @@ -0,0 +1,114 @@ +setName('phpci:install') + ->setDescription('Install PHPCI.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $dbHost = $this->ask('Enter your MySQL host: '); + $dbName = $this->ask('Enter the database name PHPCI should use: '); + $dbUser = $this->ask('Enter your MySQL username: '); + $dbPass = $this->ask('Enter your MySQL password: ', true); + $ciUrl = $this->ask('Your PHPCI URL (without trailing slash): ', true); + $ghId = $this->ask('(Optional) Github Application ID: ', true); + $ghSecret = $this->ask('(Optional) Github Application Secret: ', true); + + $cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost . ' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"'; + shell_exec($cmd); + + $str = "set('install_url', '{$ciUrl}'); +"; + + if(!empty($ghId) && !empty($ghSecret)) + { + $str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL; + } + + + file_put_contents(PHPCI_DIR . 'config.php', $str); + + if(!file_exists(PHPCI_DIR . 'composer.phar')) + { + print 'INSTALLING: Composer' . PHP_EOL; + file_put_contents(PHPCI_DIR . 'composerinstaller.php', file_get_contents('https://getcomposer.org/installer')); + shell_exec('php ' . PHPCI_DIR . 'composerinstaller.php'); + unlink(PHPCI_DIR . 'composerinstaller.php'); + } + + print 'RUNNING: Composer' . PHP_EOL; + shell_exec('php '.PHPCI_DIR.'composer.phar install'); + + + require(PHPCI_DIR . 'bootstrap.php'); + + $gen = new \b8\Database\Generator(\b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/'); + $gen->generate(); + + $adminEmail = $this->ask('Enter your email address: '); + $adminPass = $this->ask('Enter your desired admin password: '); + $adminName = $this->ask('Enter your name: '); + + try + { + $user = new \PHPCI\Model\User(); + $user->setEmail($adminEmail); + $user->setName($adminName); + $user->setIsAdmin(1); + $user->setHash(password_hash($adminPass, PASSWORD_DEFAULT)); + + $store = \b8\Store\Factory::getStore('User'); + $store->save($user); + + print 'User account created!' . PHP_EOL; + } + catch(\Exception $ex) + { + print 'There was a problem creating your account. :(' . PHP_EOL; + print $ex->getMessage(); + } + } + + function ask($question, $emptyOk = false) + { + print $question . ' '; + + $rtn = ''; + $fp = fopen('php://stdin', 'r'); + $rtn = fgets($fp); + fclose($fp); + + $rtn = trim($rtn); + + if(!$emptyOk && empty($rtn)) + { + $rtn = $this->ask($question, $emptyOk); + } + + return $rtn; + } +} \ No newline at end of file diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php new file mode 100644 index 00000000..94334269 --- /dev/null +++ b/PHPCI/Command/RunCommand.php @@ -0,0 +1,46 @@ +setName('phpci:run-builds') + ->setDescription('Run all pending PHPCI builds.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->output = $output; + + $store = Factory::getStore('Build'); + $result = $store->getByStatus(0); + + foreach($result['items'] as $build) + { + if ($input->getOption('verbose')) { + $builder = new Builder($build, array($this, 'logCallback')); + } + else { + $builder = new Builder($build); + } + + $builder->execute(); + } + } + + public function logCallback($log) + { + $this->output->writeln($log); + } +} \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index 50cae0a4..1fcf3598 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,5 +1,7 @@ set('app_namespace', 'PHPCI'); b8\Registry::getInstance()->set('DefaultController', 'Index'); diff --git a/console b/console new file mode 100755 index 00000000..cae511bd --- /dev/null +++ b/console @@ -0,0 +1,17 @@ +#!/usr/bin/env php +add(new RunCommand); +$application->add(new InstallCommand); +$application->add(new GenerateCommand); +$application->run(); diff --git a/cron.php b/cron.php deleted file mode 100644 index 80dbe7d8..00000000 --- a/cron.php +++ /dev/null @@ -1,18 +0,0 @@ -getByStatus(0); - -foreach($result['items'] as $build) -{ - $builder = new PHPCI\Builder($build); - $builder->execute(); -} \ No newline at end of file diff --git a/generate.php b/generate.php deleted file mode 100644 index d3e791dc..00000000 --- a/generate.php +++ /dev/null @@ -1,7 +0,0 @@ -generateModels(); -$gen->generateStores(); \ No newline at end of file diff --git a/install.php b/install.php deleted file mode 100644 index 52da6899..00000000 --- a/install.php +++ /dev/null @@ -1,95 +0,0 @@ -set('install_url', '{$ciUrl}'); -"; - -if(!empty($ghId) && !empty($ghSecret)) -{ - $str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL; -} - - -file_put_contents('./config.php', $str); - -if(!file_exists('./composer.phar')) -{ - print 'INSTALLING: Composer' . PHP_EOL; - file_put_contents('./composerinstaller.php', file_get_contents('https://getcomposer.org/installer')); - shell_exec('php composerinstaller.php'); - unlink('./composerinstaller.php'); -} - -print 'RUNNING: Composer' . PHP_EOL; -shell_exec('php composer.phar install'); - - -require_once('bootstrap.php'); - -$gen = new b8\Database\Generator(b8\Database::getConnection(), 'PHPCI', './PHPCI/Model/Base/'); -$gen->generate(); - -$adminEmail = ask('Enter your email address: '); -$adminPass = ask('Enter your desired admin password: '); -$adminName = ask('Enter your name: '); - -try -{ - $user = new PHPCI\Model\User(); - $user->setEmail($adminEmail); - $user->setName($adminName); - $user->setIsAdmin(1); - $user->setHash(password_hash($adminPass, PASSWORD_DEFAULT)); - - $store = b8\Store\Factory::getStore('User'); - $store->save($user); - - print 'User account created!' . PHP_EOL; -} -catch(Exception $ex) -{ - print 'There was a problem creating your account. :(' . PHP_EOL; - print $ex->getMessage(); -} - - -function ask($question, $emptyOk = false) -{ - print $question . ' '; - - $rtn = ''; - $fp = fopen('php://stdin', 'r'); - $rtn = fgets($fp); - fclose($fp); - - $rtn = trim($rtn); - - if(!$emptyOk && empty($rtn)) - { - $rtn = ask($question, $emptyOk); - } - - return $rtn; -} \ No newline at end of file From acbec4447b66295b66f102b7e0e154cabb7c60c4 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 15 May 2013 18:29:32 +0100 Subject: [PATCH 05/15] Updating README and composer.json for symfony/console --- README.md | 5 ++--- composer.json | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b4b4ef35..0a76ba50 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ _**Please be aware that this is a brand new project, in an alpha state, so there ####Pre-requisites: * PHP 5.3+ * A web server. We prefer nginx. -* The YAML extension: `pecl install yaml` * A MySQL server to connect to (doesn't have to be on the same server.) * PHPCI needs to be able to run `exec()`, so make sure this is not disabled. @@ -38,7 +37,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there ####Installing from Github: * Step 1: `git clone https://github.com/Block8/PHPCI.git` * Step 2: `cd PHPCI` -* Step 3: `php install.php` +* Step 3: `chmod +x ./console && ./console phpci:install` * When prompted, enter your database host, username, password and the database name that PHPCI should use. * The script will attempt to create the database if it does not exist already. * If you intend to use the MySQL plugin to create / destroy databases, the user you entered above will need CREATE / DELETE permissions on the server. @@ -61,7 +60,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there Finally, you'll want to set up PHPCI to run as a regular cronjob, so run `crontab -e` and enter the following: - * * * * * /usr/bin/php /path/to/phpci/cron.php + * * * * * /usr/bin/php /path/to/phpci/console phpci:run-builds Obviously, make sure you change the `/path/to/phpci` to the directory in which you installed PHPCI, and update the PHP path if necessary. diff --git a/composer.json b/composer.json index 78e5eefe..03e9ec38 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "squizlabs/php_codesniffer": "1.*", "ircmaxell/password-compat": "1.x", "phpspec/phpspec": "2.*", - "symfony/yaml": "2.2.x-dev" + "symfony/yaml": "2.2.x-dev", + "symfony/console": "2.2.*" } } From 4e9672057c30cf19e00baaaeaf662043a99e3eb9 Mon Sep 17 00:00:00 2001 From: MarkMaldaba Date: Wed, 15 May 2013 18:33:53 +0100 Subject: [PATCH 06/15] Updated minimum PHP version in README.md. Symfony/YAML requires PHP 5.3.3 (and Composer requires 5.3.2, so there is not a great compatibility loss by the recent switch away from the PECL extension for YAML). --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a76ba50..d9245142 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ _**Please be aware that this is a brand new project, in an alpha state, so there ##Installing PHPCI: ####Pre-requisites: -* PHP 5.3+ +* PHP 5.3.3+ * A web server. We prefer nginx. * A MySQL server to connect to (doesn't have to be on the same server.) * PHPCI needs to be able to run `exec()`, so make sure this is not disabled. From 2624ea78248815ded43a1fae043839cfe6698133 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 15 May 2013 20:35:26 +0200 Subject: [PATCH 07/15] Updating README to mention the mailing list. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9245142..5ab5bb3b 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,9 @@ As mentioned earlier, PHPCI is powered by plugins, there are several phases in w The `ignore` section is merely an array of paths that should be ignored in all tests (where possible.) ##Contributing -Contributions from others would be very much appreciated! Simply fork the repository, and send us a pull request when you're ready. +Contributions from others would be very much appreciated! If you just want to make a simple change, simply fork the repository, and send us a pull request when you're ready. + +If you'd like to get more involved in developing PHPCI or to become a maintainer / committer on the main PHPCI repository, join the [mailing list](https://groups.google.com/forum/#!forum/php-ci). ##Questions? -Email us at hello+phpci@block8.co.uk and we'll do our best to help! \ No newline at end of file +Your best place to go is the [mailing list](https://groups.google.com/forum/#!forum/php-ci), if you're already a member of the mailing list, you can simply email php-ci@googlegroups.com. From 2b709d25e837588f43382f8524ec460af1c0b127 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 15 May 2013 19:37:56 +0100 Subject: [PATCH 08/15] Fix --- bootstrap.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bootstrap.php b/bootstrap.php index 1fcf3598..00901c45 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -23,7 +23,11 @@ spl_autoload_register(function ($class) define('APPLICATION_PATH', dirname(__FILE__) . '/'); require_once('vendor/autoload.php'); -require('config.php'); + +if(file_exists(APPLICATION_PATH . 'config.php')) +{ + require('config.php'); +} b8\Registry::getInstance()->set('app_namespace', 'PHPCI'); b8\Registry::getInstance()->set('DefaultController', 'Index'); From 1372a8192678ada22781cbce33b177c667670f56 Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Wed, 15 May 2013 15:53:00 -0400 Subject: [PATCH 09/15] Ignore Eclipse environment files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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 From a4a443f255960263cc78ee9d4bd19a91a673c3d0 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Wed, 15 May 2013 21:53:36 +0100 Subject: [PATCH 10/15] fix symlink check and build dir --- PHPCI/Builder.php | 24 ++++++++++++++---------- PHPCI/build/.gitkeep | 0 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 PHPCI/build/.gitkeep diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 9ba46fad..58c50d70 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -106,7 +106,7 @@ class Builder } $this->log .= $prefix . $item . PHP_EOL; - }, $message); + }, $message); } else { @@ -153,8 +153,8 @@ class Builder switch ($type) { case 'local': - $this->buildPath = $this->ciDir . 'build/' . $buildId; - + $this->buildPath = substr($this->buildPath, 0, -1); + if(!is_file($reference . '/phpci.yml')) { $this->logFailure('Project does not contain a phpci.yml file.'); @@ -163,7 +163,7 @@ class Builder $yamlFile = file_get_contents($reference . '/phpci.yml'); $this->config = $yamlParser->parse($yamlFile); - + if(array_key_exists('build_settings', $this->config) && is_array($this->config['build_settings']) && array_key_exists('prefer_symlink', $this->config['build_settings']) @@ -175,20 +175,24 @@ class Builder } $this->log(sprintf('Symlinking: %s to %s',$reference, $this->buildPath)); - symlink($reference, $this->buildPath); + if ( !symlink($reference, $this->buildPath) ) + { + $this->logFailure('Failed to symlink.'); + return false; + } } else { $this->executeCommand(sprintf("cp -Rf %s %s/", $reference, $this->buildPath)); } - + $this->buildPath .= '/'; break; case 'github': case 'bitbucket': mkdir($this->buildPath, 0777, true); - + if(!empty($key)) { // Do an SSH clone: @@ -276,7 +280,7 @@ class Builder $this->success = false; } } - + continue; } @@ -295,7 +299,7 @@ class Builder $this->success = false; } } - + $this->logFailure('PLUGIN STATUS: FAILED'); continue; } @@ -322,7 +326,7 @@ class Builder { $this->plugins[$plugin] = true; } - + $this->logSuccess('PLUGIN STATUS: SUCCESS!'); } } diff --git a/PHPCI/build/.gitkeep b/PHPCI/build/.gitkeep new file mode 100644 index 00000000..e69de29b From 776046c7fb61967a06679cff73a0de57d8384aca Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Wed, 15 May 2013 22:01:02 +0100 Subject: [PATCH 11/15] Include build dir by default --- build/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 build/.gitkeep diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 00000000..e69de29b From 440d60066533de8ac61df9bfc9d6bdbc10200873 Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Wed, 15 May 2013 20:26:45 -0400 Subject: [PATCH 12/15] Fixed error about using $this outside of object context --- PHPCI/Builder.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 58c50d70..d3ec7fac 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -104,8 +104,6 @@ class Builder { $cb($prefix . $item); } - - $this->log .= $prefix . $item . PHP_EOL; }, $message); } else From dae10c19772386fe933d9c11f5ff8d58f02d74c4 Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Wed, 15 May 2013 23:26:49 -0400 Subject: [PATCH 13/15] Added phpunit flag to allow running tests from an alternate working directory --- PHPCI/Plugin/PhpUnit.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 910743d5..591ec571 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -7,6 +7,7 @@ class PhpUnit implements \PHPCI\Plugin protected $directory; protected $args; protected $phpci; + protected $runFrom; /** * @var string $xmlConfigFile The path of an xml config for PHPUnit @@ -18,6 +19,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 +50,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; } } From d3f61ab79e7a8e2e281afa00701dc53037f20ff2 Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Wed, 15 May 2013 23:43:34 -0400 Subject: [PATCH 14/15] Getting to the bottom of the logging issue --- PHPCI/Builder.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index d3ec7fac..b1aec937 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -96,15 +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); } - }, $message); + + $this->log .= $prefix . $item . PHP_EOL; + } + } else { From ead7f9a5eb5e5d09a73f42ec636a9eaf7cdbf59a Mon Sep 17 00:00:00 2001 From: Steve Kamerman Date: Wed, 15 May 2013 23:50:21 -0400 Subject: [PATCH 15/15] Added comments --- PHPCI/Plugin/PhpUnit.php | 10 +++++++--- README.md | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 591ec571..1ed744fc 100644 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -7,11 +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()) 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: