diff --git a/.gitignore b/.gitignore index 90f47e11..46474691 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ app/resource/cache bin/phpcbf bin/phpcs bin/phpunit +build vendor .buildpath .project diff --git a/.travis.yml b/.travis.yml index a1c9ca8d..046e7c83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,10 @@ php: before_script: - composer install +- wget -nc -O ./phpDocumentor.phar http://www.phpdoc.org/phpDocumentor.phar +- chmod 755 ./phpDocumentor.phar +- wget -nc -O ./phpcs.phar --no-check-certificate https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar +- chmod 755 ./phpcs.phar - phpenv rehash matrix: @@ -17,4 +21,5 @@ matrix: - php: 5.6 script: -- bin/phpcs \ No newline at end of file +- php ./phpcs.phar +- php ./phpDocumentor.phar -f phpdoc.dist.xml \ No newline at end of file diff --git a/app/config/Routes.php b/app/config/Routes.php index ae4d446e..245f5dde 100644 --- a/app/config/Routes.php +++ b/app/config/Routes.php @@ -1,45 +1,98 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\config; +/** + * Routes + * + * Routing class for http requests + * + * @author Nick Sinopoli + */ class Routes { + /** + * Gret routes + * + * @return array + */ public static function getRoutes() { return array( - array(array('get', 'post'), '/', function ($request) { - $controller = new \app\controller\Home(); - return $controller->call('index', $request); - }), - - array('get', '/archives', function ($request) { - $controller = new \app\controller\Archives(); - return $controller->call('index', $request); - }), - - array(array('get', 'post'), '/graphs', function ($request) { - $controller = new \app\controller\Graph(); - return $controller->call('index', $request); - }), - - array('get', '/file-list', function ($request) { - $controller = new \app\controller\FileList(); - return $controller->call('index', $request); - }), - - array('get', '/help', function ($request) { - $controller = new \app\controller\Home(); - return $controller->call('help', $request); - }), - + array( + array( + 'get', + 'post' + ), + '/', + function ($request) { + $controller = new \app\controller\Home(); + return $controller->call('index', $request); + } + ), + + array( + 'get', + '/archives', + function ($request) { + $controller = new \app\controller\Archives(); + return $controller->call('index', $request); + } + ), + + array( + array( + 'get', + 'post' + ), + '/graphs', + function ($request) { + $controller = new \app\controller\Graph(); + return $controller->call('index', $request); + } + ), + + array( + 'get', + '/file-list', + function ($request) { + $controller = new \app\controller\FileList(); + return $controller->call('index', $request); + } + ), + + array( + 'get', + '/help', + function ($request) { + $controller = new \app\controller\Home(); + return $controller->call('help', $request); + } + ), + // 404 - array('get', '*', function ($request) { - return array( - 'status' => 404, - 'body' => '

Not Found

' - ); - }) + array( + 'get', + '*', + function ($request) { + return array( + 'status' => 404, + 'body' => '

Not Found

' + ); + } + ) ); } } diff --git a/app/config/bootstrap.php b/app/config/bootstrap.php index 7302e9ef..b9826130 100644 --- a/app/config/bootstrap.php +++ b/app/config/bootstrap.php @@ -1,5 +1,16 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ $root = dirname(dirname(__DIR__)); $config = array( diff --git a/app/controller/Archives.php b/app/controller/Archives.php index 5027265c..5944999b 100644 --- a/app/controller/Archives.php +++ b/app/controller/Archives.php @@ -1,18 +1,42 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\controller; +/** + * Archives + * + * Class for managing archives + * + * @author Nick Sinopoli + */ class Archives extends \app\core\Controller { - // GET + /** + * Index + * + * @param string $request + * The request to process + * @return array + */ public function index($request) { $snapshot_directory = \app\lib\Library::retrieve('snapshot_directory'); - if (!$request->is('ajax')) { + if (! $request->is('ajax')) { $snapshots = array(); $handler = @opendir($snapshot_directory); - if (!$handler) { + if (! $handler) { return compact('snapshots'); } while (($file = readdir($handler)) !== false) { @@ -24,16 +48,15 @@ public function index($request) } closedir($handler); rsort($snapshots); - + return compact('snapshots'); } - - if (!isset($request->query['snapshot'])) { + + if (! isset($request->query['snapshot'])) { return ''; } - - $file = realpath($snapshot_directory) - . "/{$request->query['snapshot']}"; - return ( file_exists($file) ) ? file_get_contents($file) : ''; + + $file = realpath($snapshot_directory) . "/{$request->query['snapshot']}"; + return (file_exists($file)) ? file_get_contents($file) : ''; } } diff --git a/app/controller/FileList.php b/app/controller/FileList.php index 314014a3..415697d3 100644 --- a/app/controller/FileList.php +++ b/app/controller/FileList.php @@ -1,22 +1,46 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\controller; +/** + * FileList + * + * Class for managing file lists + * + * @author Nick Sinopoli + */ class FileList extends \app\core\Controller { - - // GET + + /** + * Index + * + * @param string $request + * The request to process + * @return array + */ public function index($request) { - if (!$request->is('ajax')) { + if (! $request->is('ajax')) { return $this->redirect('/'); } - + $dir = realpath(urldecode($request->query['dir'])); - if (!$dir) { + if (! $dir) { return array(); } - + $test_directories = \app\lib\Library::retrieve('test_directories'); $valid_dir = false; $group_name = ''; @@ -28,28 +52,26 @@ public function index($request) } } - //echo 'here'; - - if (!$valid_dir) { + // echo 'here'; + + if (! $valid_dir) { return array(); } - + $dir .= '/'; $files = scandir($dir); // Don't return anything if 'files' are '.' or '..' if (count($files) < 3) { return array(); } - + $ignore_hidden = \app\lib\Library::retrieve('ignore_hidden_folders'); - + $final_dirs = array(); $final_files = array(); foreach ($files as $file) { - $is_hidden = ( strpos($file, '.') === 0 ); - if ($file != '.' && $file != '..' - && (!$is_hidden || !$ignore_hidden) - ) { + $is_hidden = (strpos($file, '.') === 0); + if ($file != '.' && $file != '..' && (! $is_hidden || ! $ignore_hidden)) { $path = $dir . $file; $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); if (is_dir($path)) { @@ -60,14 +82,17 @@ public function index($request) ); } elseif (is_file($path) && $ext == 'php') { $final_files[] = array( - 'type' => 'file', - 'name' => $file, - 'path' => $path + 'type' => 'file', + 'name' => $file, + 'path' => $path ); } } } - - return array('name' => $group_name, 'results' => array_merge($final_dirs, $final_files)); + + return array( + 'name' => $group_name, + 'results' => array_merge($final_dirs, $final_files) + ); } } diff --git a/app/controller/Graph.php b/app/controller/Graph.php index def4192d..3a0efd4b 100644 --- a/app/controller/Graph.php +++ b/app/controller/Graph.php @@ -1,43 +1,67 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\controller; +/** + * Graph + * + * Class for managing graphs + * + * @author Nick Sinopoli + */ class Graph extends \app\core\Controller { - // GET + /** + * Index + * + * @param string $request + * The request to process + * @return array + */ public function index($request) { if ($request->is('get')) { return array(); } - + $table = "{$request->data['graph_type']}Result"; - if (!$request->data['start_date'] || !$request->data['end_date'] - || ($table != 'SuiteResult' && $table != 'TestResult') - ) { + if (! $request->data['start_date'] || + ! $request->data['end_date'] || + ($table != 'SuiteResult' && $table != 'TestResult')) { return array( - 'type' => $request->data['graph_type'], - 'timeFrame' => $request->data['time_frame'], + 'type' => $request->data['graph_type'], + 'timeFrame' => $request->data['time_frame'], 'categories' => array(), - 'failed' => 0, - 'succeeded' => 0, - 'skipped' => 0, - 'incomplete' => 0, + 'failed' => 0, + 'succeeded' => 0, + 'skipped' => 0, + 'incomplete' => 0 ); } - + $db_options = \app\lib\Library::retrieve('db'); $db = new $db_options['plugin'](); - if (!$db->connect($db_options)) { + if (! $db->connect($db_options)) { return array( 'error' => array( - 'title' => 'Error Connecting to Database', + 'title' => 'Error Connecting to Database', 'message' => implode(' ', $db->getErrors()) ) ); } - + switch ($request->data['time_frame']) { case 'Monthly': $interval = 2678400; @@ -57,36 +81,35 @@ public function index($request) } $current = $start = strtotime($request->data['start_date']); $end = strtotime($request->data['end_date']) + $interval; - + $categories = array(); $plot_values = array( - 'failed' => array(), + 'failed' => array(), 'incomplete' => array(), - 'skipped' => array(), - 'succeeded' => array() + 'skipped' => array(), + 'succeeded' => array() ); while ($current < $end) { $categories[] = date($output, $current); $next = $current + $interval; - + $data = array( - 'failed' => 0, + 'failed' => 0, 'incomplete' => 0, - 'skipped' => 0, - 'succeeded' => 0 + 'skipped' => 0, + 'succeeded' => 0 ); - - $sql = "select failed, incomplete, skipped, succeeded " - . "from {$table} where run_date >= ? and run_date < ?"; + + $sql = "select failed, incomplete, skipped, succeeded from {$table} where run_date >= ? and run_date < ?"; $params = array( date($sql_format, $current), date($sql_format, $next) ); $db->query($sql, $params); - + $results = $db->fetchAll(); $num_rows = count($results); - + if ($num_rows > 0) { foreach ($results as $result) { foreach ($result as $key => $value) { @@ -94,7 +117,7 @@ public function index($request) } } } - + foreach ($data as $key => $val) { if ($num_rows > 0) { $plot_values[$key][] = round($val / $num_rows, 2); @@ -102,19 +125,19 @@ public function index($request) $plot_values[$key][] = 0; } } - + $current = $next; } - + $db->close(); - + return array( - 'type' => $request->data['graph_type'], - 'timeFrame' => $request->data['time_frame'], + 'type' => $request->data['graph_type'], + 'timeFrame' => $request->data['time_frame'], 'categories' => $categories, - 'failed' => $plot_values['failed'], - 'succeeded' => $plot_values['succeeded'], - 'skipped' => $plot_values['skipped'], + 'failed' => $plot_values['failed'], + 'succeeded' => $plot_values['succeeded'], + 'skipped' => $plot_values['skipped'], 'incomplete' => $plot_values['incomplete'] ); } diff --git a/app/controller/Home.php b/app/controller/Home.php index 1483808a..24b8913e 100644 --- a/app/controller/Home.php +++ b/app/controller/Home.php @@ -1,64 +1,99 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\controller; +use \app\lib\Library; + +/** + * Home + * + * Class for managing homepage + * + * @author Nick Sinopoli + */ class Home extends \app\core\Controller { + /** + * Create a snapshot + * + * @param array $view_data + * View data + * @return array + */ protected function createSnapshot($view_data) { $directory = \app\lib\Library::retrieve('snapshot_directory'); - $filename = realpath($directory). '/' . date('Y-m-d_H-i') . '.html'; - + $filename = realpath($directory) . '/' . date('Y-m-d_H-i') . '.html'; + $contents = $this->renderHtml('partial/test_results', $view_data); - + $handle = @fopen($filename, 'a'); - if (!file_exists($directory) || !$handle) { + if (! file_exists($directory) || ! $handle) { + $message = 'Please ensure that the snapshot_directory '; + $message += 'in app/config/bootstrap.php exists and has the proper permissions.'; return array( - 'type' => 'failed', - 'title' => 'Error Creating Snapshot', - 'message' => 'Please ensure that the ' - . 'snapshot_directory in ' - . 'app/config/bootstrap.php exists and ' - . 'has the proper permissions.' + 'type' => 'failed', + 'title' => 'Error Creating Snapshot', + 'message' => $message ); } - + fwrite($handle, $contents); fclose($handle); return array( - 'type' => 'succeeded', - 'title' => 'Snapshot Created', + 'type' => 'succeeded', + 'title' => 'Snapshot Created', 'message' => "Snapshot can be found at {$filename}." ); } - // GET + /** + * help + * + * @param string $request + * The request to process + * @return array + */ public function help($request) { return array(); } - // GET/POST + /** + * Index + * + * @param string $request + * The request to process + * @return array + */ public function index($request) { if ($request->is('get')) { $normalize_path = function ($path) { return str_replace('\\', '/', realpath($path)); }; - $test_directories = json_encode(array_map( - $normalize_path, - array_values(\app\lib\Library::retrieve('test_directories')) - )); - + $test_directories = json_encode( + array_map($normalize_path, array_values(Library::retrieve('test_directories'))) + ); + $suites = array(); $stats = array(); - $store_statistics = \app\lib\Library::retrieve('store_statistics'); - $create_snapshots = \app\lib\Library::retrieve('create_snapshots'); - $sandbox_errors = \app\lib\Library::retrieve('sandbox_errors'); - $xml_configuration_files = \app\lib\Library::retrieve( - 'xml_configuration_files' - ); + $store_statistics = Library::retrieve('store_statistics'); + $create_snapshots = Library::retrieve('create_snapshots'); + $sandbox_errors = Library::retrieve('sandbox_errors'); + $xml_configuration_files = Library::retrieve('xml_configuration_files'); return compact( 'create_snapshots', 'sandbox_errors', @@ -69,94 +104,100 @@ public function index($request) 'xml_configuration_files' ); } - + $tests = explode('|', $request->data['test_files']); $vpu = new \app\lib\VPU(); - + if ($request->data['sandbox_errors']) { error_reporting(\app\lib\Library::retrieve('error_reporting')); - set_error_handler(array($vpu, 'handleErrors')); + set_error_handler(array( + $vpu, + 'handleErrors' + )); } - + $xml_config = false; - + $notifications = array(); if ($xml_file_index = $request->data['xml_configuration_file']) { $files = \app\lib\Library::retrieve('xml_configuration_files'); $xml_config = $files[$xml_file_index - 1]; - if (!$xml_config || !$xml_config = realpath($xml_config)) { + if (! $xml_config || ! $xml_config = realpath($xml_config)) { + $message = 'Please ensure that the xml_configuration_file in '; + $message += 'app/config/bootstrap.php exists and has the proper permissions.'; $notifications[] = array( - 'type' => 'failed', - 'title' => 'No Valid XML Configuration File Found', - 'message' => 'Please ensure that the ' - . 'xml_configuration_file in ' - . 'app/config/bootstrap.php exists and ' - . 'has the proper permissions.' + 'type' => 'failed', + 'title' => 'No Valid XML Configuration File Found', + 'message' => $message ); } } - - $results = ( $xml_config ) - ? $vpu->runWithXml($xml_config) - : $vpu->runTests($tests); + + $results = ($xml_config) ? $vpu->runWithXml($xml_config) : $vpu->runTests($tests); $results = $vpu->compileSuites($results, 'web'); - + if ($request->data['sandbox_errors']) { restore_error_handler(); } - + $suites = $results['suites']; $stats = $results['stats']; $errors = $vpu->getErrors(); $to_view = compact('suites', 'stats', 'errors'); - + if ($request->data['create_snapshots']) { $notifications[] = $this->createSnapshot($to_view); } if ($request->data['store_statistics']) { $notifications[] = $this->storeStatistics($stats); } - + return $to_view + compact('notifications'); } + /** + * Stro statistics + * + * @param array $stats + * Stats to process + * + * @return array + */ protected function storeStatistics($stats) { $db_options = \app\lib\Library::retrieve('db'); $db = new $db_options['plugin'](); - if (!$db->connect($db_options)) { + if (! $db->connect($db_options)) { return array( - 'type' => 'failed', - 'title' => 'Error Connecting to Database', + 'type' => 'failed', + 'title' => 'Error Connecting to Database', 'message' => implode(' ', $db->getErrors()) ); } - + $now = date('Y-m-d H:i:s'); foreach ($stats as $key => $stat) { $data = array( - 'run_date' => $now, - 'failed' => $stat['failed'], + 'run_date' => $now, + 'failed' => $stat['failed'], 'incomplete' => $stat['incomplete'], - 'skipped' => $stat['skipped'], - 'succeeded' => $stat['succeeded'] + 'skipped' => $stat['skipped'], + 'succeeded' => $stat['succeeded'] ); $table = ucfirst(rtrim($key, 's')) . 'Result'; - if (!$db->insert($table, $data)) { + if (! $db->insert($table, $data)) { return array( - 'type' => 'failed', - 'title' => 'Error Inserting Record', + 'type' => 'failed', + 'title' => 'Error Inserting Record', 'message' => implode(' ', $db->getErrors()) ); } } - + return array( - 'type' => 'succeeded', - 'title' => 'Statistics Stored', - 'message' => 'The statistics generated during this test run were ' - . 'successfully stored.' + 'type' => 'succeeded', + 'title' => 'Statistics Stored', + 'message' => 'The statistics generated during this test run were ' . 'successfully stored.' ); - } } diff --git a/app/core/Controller.php b/app/core/Controller.php index ecdda6ac..e9d26dea 100644 --- a/app/core/Controller.php +++ b/app/core/Controller.php @@ -1,66 +1,83 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\core; +/** + * Controller + * + * Controller class for MVC + * + * @author Nick Sinopoli + */ class Controller { - /** - * The class configuration settings. - * - * @var array - * @access protected - */ + /** + * The class configuration settings. + * + * @var array + */ protected $config; - /** - * Contains the optional response status and headers. - * - * @var array - * @access protected - */ + /** + * Contains the optional response status and headers. + * + * @var array + */ protected $response = array(); - /** - * Loads the configuration settings for the controller. - * - * @param array $config The configuration options. - * @access public - * @return void - */ + /** + * Loads the configuration settings for the controller. + * + * @param array $config + * The configuration options. + */ public function __construct(array $config = array()) { $defaults = array( 'dependencies' => array( - 'view' => 'app\core\View' + 'view' => 'app\core\View' ) ); $this->config = $config + $defaults; } - /** - * Primary entry point for all controller actions. The supplied action is - * called, returning a response which is then filtered based on the request - * source (e.g., xhr, web). - * - * @param string $action The method to be called. - * @param obj $request The request object. - * @access public - * @return array - */ + /** + * Primary entry point for all controller actions. + * The supplied action is + * called, returning a response which is then filtered based on the request + * source (e.g., xhr, web). + * + * @param string $action + * The method to be called. + * @param obj $request + * The request object. + * @return array + */ public function call($action, $request) { $results = $this->$action($request); - + if (is_null($results) || $results === false) { return false; } - - if (!is_array($results)) { + + if (! is_array($results)) { $this->response['body'] = $results; return $this->response; } - + if ($request->is('ajax')) { $this->response['body'] = $this->renderJson($results); } else { @@ -69,45 +86,48 @@ public function call($action, $request) $file = lcfirst($classname) . "/{$action}"; $this->response['body'] = $this->renderHtml($file, $results); } - + return $this->response; } - /** - * Redirects the page. - * - * @param string $page The page to be redirected to. - * @access public - * @return bool - */ + /** + * Redirects the page. + * + * @param string $page + * The page to be redirected to. + * @return boolean + */ public function redirect($page) { $this->setResponseStatus(303); - $this->setResponseHeaders(array('Location: ' . $page)); + $this->setResponseHeaders(array( + 'Location: ' . $page + )); return ''; } - /** - * Converts the supplied value to JSON. - * - * @param mixed $value The value to encode. - * @access public - * @return string - */ + /** + * Converts the supplied value to JSON. + * + * @param mixed $value + * The value to encode. + * @return string + */ public function renderJson($value) { $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP; return json_encode($value, $options); } - /** - * Renders a view. - * - * @param string $action The file to be rendered. - * @param array $vars The variables to be substituted in the view. - * @access public - * @return string - */ + /** + * Renders a view. + * + * @param string $action + * The file to be rendered. + * @param array $vars + * The variables to be substituted in the view. + * @return string + */ public function renderHtml($file, $vars = array()) { $view = $this->config['dependencies']['view']; @@ -115,29 +135,31 @@ public function renderHtml($file, $vars = array()) return $view->render($file, $vars); } - /** - * Sets the response headers. Note that the supplied headers must be - * well-formed HTTP headers. Example: - * - * $headers = array('Content-Type: text/html; charset=utf-8'); - * - * @param array $headers The response headers. - * @access public - * @return void - */ + /** + * Sets the response headers. + * Note that the supplied headers must be + * well-formed HTTP headers. Example: + * + * $headers = array('Content-Type: text/html; charset=utf-8'); + * + * @param array $headers + * The response headers. + * @return void + */ public function setResponseHeaders($headers) { $this->response['headers'] = $headers; } - /** - * Sets the response status. Note that the supplied status must be the - * integer associated with the HTTP status code (e.g., 404 for Not Found). - * - * @param int $status The response status. - * @access public - * @return void - */ + /** + * Sets the response status. + * Note that the supplied status must be the + * integer associated with the HTTP status code (e.g., 404 for Not Found). + * + * @param integer $status + * The response status. + * @return void + */ public function setResponseStatus($status) { $this->response['status'] = $status; diff --git a/app/core/View.php b/app/core/View.php index b621601f..73c28bab 100644 --- a/app/core/View.php +++ b/app/core/View.php @@ -1,69 +1,91 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\core; +use \RuntimeException; + +/** + * View + * + * View class for MVC + * + * @author Nick Sinopoli + */ class View { + /** + * Configuration options + * + * @var array + */ protected $config; - /** - * Loads the configuration settings for the view. - * - * @param array $config The configuration options. - * @access public - * @return void - */ + /** + * Loads the configuration settings for the view. + * + * @param array $config + * The configuration options. + */ public function __construct(array $config = array()) { $defaults = array( 'dependencies' => array( - 'compiler' => 'app\lib\Compiler', + 'compiler' => 'app\lib\Compiler' ) ); $this->config = $config + $defaults; } - /** - * Escapes a value for output in an HTML context. - * - * @param mixed $value - * @access public - * @return mixed - */ + /** + * Escapes a value for output in an HTML context. + * + * @param mixed $value + * Value to escape + * @return mixed + */ public function escape($value) { return nl2br(htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); } - /** - * Renders a given file with the supplied variables. - * - * @param string $file The file to be rendered. - * @param mixed $vars The variables to be substituted in the view. - * @access public - * @return string - */ + /** + * Renders a given file with the supplied variables. + * + * @param string $file + * The file to be rendered. + * @param mixed $vars + * The variables to be substituted in the view. + * @return string + */ public function render($file, $vars = null) { $path = dirname(__DIR__) . '/resource/cache/'; $file = dirname(__DIR__) . "/view/{$file}.html"; - + $compiler = $this->config['dependencies']['compiler']; $options = compact('path'); $__template__ = $compiler::compile($file, $options); - - if (!$__template__) { - throw new \RuntimeException( - 'Could not write cache file. Please ensure that the ' - . "permissions of {$path} are correct." - ); + $message = "Could not write cache file. Please ensure that the permissions of {$path} are correct"; + if (! $__template__) { + throw new RuntimeException($message); } - + if (is_array($vars)) { extract($vars); } - + ob_start(); require $__template__; return ob_get_clean(); diff --git a/app/lib/Compiler.php b/app/lib/Compiler.php index f209492d..b15a997e 100644 --- a/app/lib/Compiler.php +++ b/app/lib/Compiler.php @@ -1,52 +1,66 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\lib; +/** + * Compiler + * + * Class for compiling templates + * + * @author Nick Sinopoli + */ class Compiler { - /** - * Retrieves the compiled filename, and caches the file - * if it is not already cached. - * - * @param string $file The file location. - * @param array $options The compilation options, which take the - * following keys: - * 'path' - The path where where the cached file - * should be stored. - * @access public - * @return string - */ + /** + * Retrieves the compiled filename, and caches the file + * if it is not already cached. + * + * @param string $file + * The file location. + * @param array $options + * The compilation options, which take the + * following keys: + * 'path' - The path where where the cached file + * should be stored. + * @return string + */ public static function compile($file, $options = array()) { $options += array( 'path' => 'compiled/' ); - + $stats = stat($file); $dir = dirname($file); - $location = basename(dirname($dir)) . '_' . basename($dir) - . '_' . basename($file, '.html'); - $template = 'template_' . $location . '_' . $stats['mtime'] - . '_' . $stats['ino'] . '_' . $stats['size'] . '.html'; + $location = basename(dirname($dir)) . '_' . basename($dir) . '_' . basename($file, '.html'); + $template = 'template_' . $location . '_' . $stats['mtime'] . '_' . $stats['ino'] . '_' . $stats['size']; + $template += '.html'; $template = $options['path'] . $template; - + if (file_exists($template)) { return $template; } - + $compiled = self::replace(file_get_contents($file)); $template_dir = dirname($template); - if (!is_dir($template_dir) && !mkdir($template_dir, 0755, true)) { + if (! is_dir($template_dir) && ! mkdir($template_dir, 0755, true)) { return false; } - - if (!is_writable($template_dir) - || file_put_contents($template, $compiled) === false - ) { + + if (! is_writable($template_dir) || file_put_contents($template, $compiled) === false) { return false; } - + $pattern = $template_dir . '/template_' . $location . '_*.html'; foreach (glob($pattern) as $old) { if ($old !== $template) { @@ -56,30 +70,21 @@ public static function compile($file, $options = array()) return $template; } - /** - * Replaces a template with custom syntax. - * - * @param string $template The template. - * @access public - * @return string - */ + /** + * Replaces a template with custom syntax. + * + * @param string $template + * The template. + * @return string + */ protected static function replace($template) { $replace = array( - '/\<\?=\s*\$this->(.+?)\s*;?\s*\?>/msx' => - '$1; ?>', - - '/\$e\((.+?)\)\s*;/msx' => - 'echo $this->escape($1);', - - '/\<\?=\s*(.+?)\s*;?\s*\?>/msx' => - 'escape($1); ?>' - ); - - return preg_replace( - array_keys($replace), - array_values($replace), - $template + '/\<\?=\s*\$this->(.+?)\s*;?\s*\?>/msx' => '$1; ?>', + '/\$e\((.+?)\)\s*;/msx' => 'echo $this->escape($1);', + '/\<\?=\s*(.+?)\s*;?\s*\?>/msx' => 'escape($1); ?>' ); + + return preg_replace(array_keys($replace), array_values($replace), $template); } } diff --git a/app/lib/Library.php b/app/lib/Library.php index d0dac596..2989706a 100644 --- a/app/lib/Library.php +++ b/app/lib/Library.php @@ -1,26 +1,41 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\lib; +/** + * Library + * + * Class for managing library + * + * @author Nick Sinopoli + */ class Library { - /** - * The configuration settings. - * - * @var array - * @access protected - */ + /** + * The configuration settings. + * + * @var array + */ protected static $config = array(); - /** - * Retrieves the configuration options, or a specific option if a key is - * supplied. - * - * @param string $key The key. - * @access public - * @return void - */ + /** + * Retrieves the configuration options, or a specific option if a key is + * supplied. + * + * @param string $key + * The key. + * @return void + */ public static function retrieve($key = null) { if ($key) { @@ -29,14 +44,13 @@ public static function retrieve($key = null) return self::$config; } - - /** - * Stores the supplied configuration options. - * - * @param array $config The configuration options. - * @access public - * @return void - */ + /** + * Stores the supplied configuration options. + * + * @param array $config + * The configuration options. + * @return void + */ public static function store($config = array()) { self::$config = $config; diff --git a/app/lib/PDOMySQL.php b/app/lib/PDOMySQL.php index ba41e693..a9fc6d69 100644 --- a/app/lib/PDOMySQL.php +++ b/app/lib/PDOMySQL.php @@ -1,86 +1,95 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\lib; use \PDO; use \PDOException; +/** + * PDOMySQL + * + * Class for managing PDO operations + * + * @author Nick Sinopoli + */ class PDOMySQL { - /** - * Number of rows affected by MySQL query. - * - * @var int - * @access protected - */ + /** + * Number of rows affected by MySQL query. + * + * @var int + */ protected $affectedRows = 0; - /** - * The db handle. - * - * @var object - * @access protected - */ + /** + * The db handle. + * + * @var object + */ protected $dbh; - /** - * The error messages generated by PDOExceptions. - * - * @var array - * @access protected - */ + /** + * The error messages generated by PDOExceptions. + * + * @var array + */ protected $errors = array(); - /** - * The result set associated with a prepared statement. - * - * @var PDOStatement - * @access protected - */ + /** + * The result set associated with a prepared statement. + * + * @var \PDOStatement + */ protected $statement; - /** - * Returns the number of rows affected by the last DELETE, - * INSERT, or UPDATE query. - * - * @access public - * @return int - */ + /** + * Returns the number of rows affected by the last DELETE, + * INSERT, or UPDATE query. + * + * @return integer + */ public function affectedRows() { return $this->affectedRows; } - /** - * Closes the connection. - * - * @access public - * @return bool - */ + /** + * Closes the connection. + * + * @return boolean + */ public function close() { $this->dbh = null; return true; } - /** - * Connects and selects database. - * - * @param array $options Contains the connection information. Takes the - * following options: - * 'database' - The name of the database. - * 'host' - The database host. - * 'port' - The database port. - * 'username' - The database username. - * 'password' - The database password. - * @access public - * @return bool - */ + /** + * Connects and selects database. + * + * @param array $options + * Contains the connection information. Takes the + * following options: + * 'database' - The name of the database. + * 'host' - The database host. + * 'port' - The database port. + * 'username' - The database username. + * 'password' - The database password. + * @return boolean + */ public function connect($options = array()) { - $dsn = "mysql:host={$options['host']};port={$options['port']}" - . ";dbname={$options['database']}"; + $dsn = "mysql:host={$options['host']};port={$options['port']}" . ";dbname={$options['database']}"; try { $this->dbh = new PDO($dsn, $options['username'], $options['password']); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -91,16 +100,17 @@ public function connect($options = array()) } } - /** - * Fetches the next row from the result set in memory (i.e., the one - * that was created after running query()). - * - * @param string $fetch_style Controls how the rows will be returned. - * @param obj $obj The object to be fetched into if - * $fetch_style is set to 'into'. - * @access public - * @return mixed - */ + /** + * Fetches the next row from the result set in memory (i.e., the one + * that was created after running query()). + * + * @param string $fetch_style + * Controls how the rows will be returned. + * @param obj $obj + * The object to be fetched into if + * $fetch_style is set to 'into'. + * @return mixed + */ public function fetch($fetch_style = null, $obj = null) { $this->setFetchMode($fetch_style, $obj); @@ -109,13 +119,13 @@ public function fetch($fetch_style = null, $obj = null) return $row; } - /** - * Returns an array containing all of the result set rows. - * - * @param string $fetch_style Controls how the rows will be returned. - * @access public - * @return mixed - */ + /** + * Returns an array containing all of the result set rows. + * + * @param string $fetch_style + * Controls how the rows will be returned. + * @return mixed + */ public function fetchAll($fetch_style = null) { $this->setFetchMode($fetch_style); @@ -124,15 +134,15 @@ public function fetchAll($fetch_style = null) return $rows; } - /** - * Returns a single column from the next row of a result set or false - * if there are no more rows. - * - * @param int $column_number Zero-index number of the column to - * retrieve from the row. - * @access public - * @return mixed - */ + /** + * Returns a single column from the next row of a result set or false + * if there are no more rows. + * + * @param integer $column_number + * Zero-index number of the column to + * retrieve from the row. + * @return mixed + */ public function fetchColumn($column_number = 0) { $column = $this->statement->fetchColumn($column_number); @@ -140,99 +150,100 @@ public function fetchColumn($column_number = 0) return $column; } - /** - * Returns the errors generated by PDOExceptions. - * - * @access public - * @return array - */ + /** + * Returns the errors generated by PDOExceptions. + * + * @return array + */ public function getErrors() { return $this->errors; } - /** - * Inserts a record into the database. - * - * @param string $table The table containing the record to be inserted. - * @param array $data An array containing the data to be inserted. - * Format should be as follows: - * array('column_name' => 'column_value'); - * @access public - * @return bool - */ + /** + * Inserts a record into the database. + * + * @param string $table + * The table containing the record to be inserted. + * @param array $data + * An array containing the data to be inserted. + * Format should be as follows: + * array('column_name' => 'column_value'); + * @return bool + */ public function insert($table, $data) { $sql = "INSERT INTO {$table} "; - + $key_names = array_keys($data); $fields = implode(', ', $key_names); $values = ':' . implode(', :', $key_names); - + $sql .= "({$fields}) VALUES ({$values})"; - + $statement = $this->dbh->prepare($sql); - + try { $statement->execute($data); } catch (PDOException $e) { $this->errors[] = $e->getMessage(); return false; } - + $this->affectedRows = $statement->rowCount(); return true; } - /** - * Returns the ID of the last inserted row or sequence value. - * - * @access public - * @return int - */ + /** + * Returns the ID of the last inserted row or sequence value. + * + * @return integer + */ public function insertId() { return $this->dbh->lastInsertId(); } - /** - * Executes SQL query. - * - * @param string $sql The SQL query to be executed. - * @param array $parameters An array containing the parameters to be - * bound. - * @access public - * @return bool - */ + /** + * Executes SQL query. + * + * @param string $sql + * The SQL query to be executed. + * @param array $parameters + * An array containing the parameters to be + * bound. + * @return boolean + */ public function query($sql, $parameters = array()) { $statement = $this->dbh->prepare($sql); - + foreach ($parameters as $index => $parameter) { $statement->bindValue($index + 1, $parameter); } - + try { $statement->execute(); } catch (PDOException $e) { $this->errors[] = $e->getMessage(); return false; } - + $this->affectedRows = $statement->rowCount(); $this->statement = $statement; return true; } - /** - * Sets the fetch mode. - * - * @param string $fetch_style Controls how the rows will be returned. - * @param obj $obj The object to be fetched into for use with - * FETCH_INTO. - * @access protected - * @return int - */ + /** + * Sets the fetch mode. + * + * @param string $fetch_style + * Controls how the rows will be returned. + * @param obj $obj + * The object to be fetched into for use with + * FETCH_INTO. + * @return integer + */ protected function setFetchMode($fetch_style, $obj = null) { switch ($fetch_style) { @@ -248,29 +259,31 @@ protected function setFetchMode($fetch_style, $obj = null) } } - /** - * Updates a record in the database. - * - * @param string $table The table containing the record to be inserted. - * @param array $data An array containing the data to be inserted. - * Format should be as follows: - * array('column_name' => 'column_value'); - * @param array $where The WHERE clause of the SQL query. - * @access public - * @return bool - */ + /** + * Updates a record in the database. + * + * @param string $table + * The table containing the record to be inserted. + * @param array $data + * An array containing the data to be inserted. + * Format should be as follows: + * array('column_name' => 'column_value'); + * @param array $where + * The WHERE clause of the SQL query. + * @return boolean + */ public function update($table, $data, $where = null) { $sql = "UPDATE {$table} SET "; - + $key_names = array_keys($data); foreach ($key_names as $name) { $sql .= "{$name}=:{$name}, "; } - + $sql = rtrim($sql, ', '); - - if (!is_null($where)) { + + if (! is_null($where)) { $sql .= ' WHERE '; foreach ($where as $name => $val) { $sql .= "{$name}=:{$name}_where, "; @@ -278,53 +291,53 @@ public function update($table, $data, $where = null) } } $statement = $this->dbh->prepare($sql); - + try { $statement->execute($data); } catch (PDOException $e) { $this->errors[] = $e->getMessage(); return false; } - + $this->affectedRows = $statement->rowCount(); return true; } - /** - * Inserts or updates (if exists) a record in the database. - * - * @param string $table The table containing the record to be inserted. - * @param array $data An array containing the data to be inserted. - * Format should be as follows: - * array('column_name' => 'column_value'); - * @access public - * @return bool - */ + /** + * Inserts or updates (if exists) a record in the database. + * + * @param string $table + * The table containing the record to be inserted. + * @param array $data + * An array containing the data to be inserted. + * Format should be as follows: + * array('column_name' => 'column_value'); + * @return boolean + */ public function upsert($table, $data) { $sql = "INSERT INTO {$table}"; - + $key_names = array_keys($data); $fields = implode(', ', $key_names); $values = ':' . implode(', :', $key_names); - - + $sql .= "({$fields}) VALUES ({$values}) ON DUPLICATE KEY UPDATE "; - + foreach ($key_names as $name) { $sql .= "{$name}=:{$name}, "; } - + $sql = rtrim($sql, ', '); $statement = $this->dbh->prepare($sql); - + try { $statement->execute($data); } catch (PDOException $e) { $this->errors[] = $e->getMessage(); return false; } - + $this->affectedRows = $statement->rowCount(); return true; } diff --git a/app/lib/VPU.php b/app/lib/VPU.php index 0699efe1..a1fa51eb 100644 --- a/app/lib/VPU.php +++ b/app/lib/VPU.php @@ -1,25 +1,49 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace app\lib; +use \RecursiveDirectoryIterator; +use \RecursiveIteratorIterator; +use \DomainException; +use \PHPUnit_TextUI_Command; +use \PHPUnit_Framework_TestResult; +use \PHPUnit_Util_Log_JSON; +use \PHPUnit_Framework_TestSuite; +use \PHPUnit_Util_Configuration; + +/** + * VPU + * + * Main class for processing test data + * + * @author Nick Sinopoli + */ class VPU { - /** - * The error messages collected by the custom error handler. - * - * @var array - * @access protected - */ + /** + * The error messages collected by the custom error handler. + * + * @var array + */ protected $errors = array(); - /** - * Adds percentage statistics to the provided statistics. - * - * @param array $statistics The statistics. - * @access protected - * @return array - */ + /** + * Adds percentage statistics to the provided statistics. + * + * @param array $statistics + * The statistics. + * @return array + */ protected function addPercentages($statistics) { $results = array(); @@ -31,67 +55,68 @@ protected function addPercentages($statistics) } // Avoid divide by zero error if ($stats['total']) { - $results[$name]['percent' . ucfirst($key)] = - round($stats[$key] / $stats['total'] * 100, 1); + $results[$name]['percent' . ucfirst($key)] = round($stats[$key] / $stats['total'] * 100, 1); } else { $results[$name]['percent' . ucfirst($key)] = 0; } } } - + return $results; } - /** - * Returns the class name without the namespace. - * - * @param string $class The class name. - * @access protected - * @return string - */ + /** + * Returns the class name without the namespace. + * + * @param string $class + * The class name. + * @return string + */ protected function classnameOnly($class) { $name = explode('\\', $class); return end($name); } - /** - * Organizes the output from PHPUnit into a more manageable array - * of suites and statistics. - * - * @param string $pu_output The JSON output from PHPUnit. - * @param string $source The executing source (web or cli). - * @access public - * @return array - */ + /** + * Organizes the output from PHPUnit into a more manageable array + * of suites and statistics. + * + * @param string $pu_output + * The JSON output from PHPUnit. + * @param string $source + * The executing source (web or cli). + * @return array + */ public function compileSuites($pu_output, $source) { $results = $this->parseOutput($pu_output); - + $collection = array(); $statistics = array( 'suites' => array( - 'succeeded' => 0, - 'skipped' => 0, + 'succeeded' => 0, + 'skipped' => 0, 'incomplete' => 0, - 'failed' => 0, - 'total' => 0 + 'failed' => 0, + 'total' => 0 ) ); $statistics['tests'] = $statistics['suites']; + foreach ($results as $result) { - if (!isset($result['event']) || $result['event'] != 'test') { + if (! isset($result['event']) || $result['event'] != 'test') { continue; } - + $suite_name = $this->classnameOnly($result['suite']); - - if (!isset($collection[$suite_name])) { + + if (! isset($collection[$suite_name])) { $collection[$suite_name] = array( - 'tests' => array(), - 'name' => $suite_name, + 'tests' => array(), + 'name' => $suite_name, 'status' => 'succeeded', - 'time' => 0 + 'time' => 0 ); } $result = $this->formatTestResults($result, $source); @@ -104,44 +129,44 @@ public function compileSuites($pu_output, $source) $statistics['tests'][$result['status']] += 1; $statistics['tests']['total'] += 1; } - + foreach ($collection as $suite) { $statistics['suites'][$suite['status']] += 1; $statistics['suites']['total'] += 1; } - + $final = array( 'suites' => $collection, - 'stats' => $this->addPercentages($statistics) + 'stats' => $this->addPercentages($statistics) ); - + return $final; } - /** - * Converts the first nested layer of PHPUnit-generated JSON to an - * associative array. - * - * @param string $str The JSON output from PHPUnit. - * @access protected - * @return array - */ + /** + * Converts the first nested layer of PHPUnit-generated JSON to an + * associative array. + * + * @param string $str + * The JSON output from PHPUnit. + * @return array + */ protected function convertJson($str) { $str = str_replace('"', '"', $str); - + $tags = array(); $nest = 0; $start_mark = 0; $in_quotes = false; - + $length = strlen($str); - for ($i = 0; $i < $length; $i++) { + for ($i = 0; $i < $length; $i ++) { $char = $str{$i}; - + if ($char == '"') { // Escaped quote in debug output - if (!$in_quotes || $str{$i - 1} == "\\") { + if (! $in_quotes || $str{$i - 1} == "\\") { $i = strpos($str, '"', $i + 1) - 1; $in_quotes = true; } else { @@ -149,88 +174,69 @@ protected function convertJson($str) } continue; } - + if ($char == '{') { - $nest++; + $nest ++; if ($nest == 1) { $start_mark = $i; } } elseif ($char == '}' && $nest > 0) { if ($nest == 1) { - $tags[] = substr( - $str, - $start_mark + 1, - $i - $start_mark - 1 - ); + $tags[] = substr($str, $start_mark + 1, $i - $start_mark - 1); $start_mark = $i; } - $nest--; + $nest --; } } - + return $tags; } - /** - * Normalizes the test results. - * - * @param array $test_results The parsed test results. - * @param string $source The executing source (web or cli). - * @access protected - * @return string - */ + /** + * Normalizes the test results. + * + * @param array $test_results + * The parsed test results. + * @param string $source + * The executing source (web or cli). + * @return string + */ protected function formatTestResults($test_results, $source) { - $status = $this->getTestStatus( - $test_results['status'], - $test_results['message'] - ); - $name = substr( - $test_results['test'], - strpos($test_results['test'], '::') + 2 - ); + $status = $this->getTestStatus($test_results['status'], $test_results['message']); + $name = substr($test_results['test'], strpos($test_results['test'], '::') + 2); $time = $test_results['time']; $message = $test_results['message']; - $output = ( isset($test_results['output']) ) - ? trim($test_results['output']) - : ''; + $output = (isset($test_results['output'])) ? trim($test_results['output']) : ''; $trace = $this->getTrace($test_results['trace'], $source); - - return compact( - 'status', - 'name', - 'time', - 'message', - 'output', - 'trace' - ); + + return compact('status', 'name', 'time', 'message', 'output', 'trace'); } - /** - * Returns the errors collected by the custom error handler. - * - * @access public - * @return array - */ + /** + * Returns the errors collected by the custom error handler. + * + * @access public + * @return array + */ public function getErrors() { return $this->errors; } - /** - * Determines the overall suite status based on the current status - * of the suite and the status of a single test. - * - * @param string $test_status The status of the test. - * @param string $suite_status The current status of the suite. - * @access protected - * @return string - */ + /** + * Determines the overall suite status based on the current status + * of the suite and the status of a single test. + * + * @param string $test_status + * The status of the test. + * @param string $suite_status + * The current status of the suite. + * @return string + */ protected function getSuiteStatus($test_status, $suite_status) { - if ($test_status === 'incomplete' && $suite_status !== 'failed' - && $suite_status !== 'skipped' - ) { + if ($test_status === 'incomplete' && $suite_status !== 'failed' && $suite_status !== 'skipped') { return 'incomplete'; } if ($test_status === 'skipped' && $suite_status !== 'failed') { @@ -242,14 +248,15 @@ protected function getSuiteStatus($test_status, $suite_status) return $suite_status; } - /** - * Retrieves the status from a PHPUnit test result. - * - * @param string $status The status supplied by VPU's transformed JSON. - * @param string $message The message supplied by VPU's transformed JSON. - * @access protected - * @return string - */ + /** + * Retrieves the status from a PHPUnit test result. + * + * @param string $status + * The status supplied by VPU's transformed JSON. + * @param string $message + * The message supplied by VPU's transformed JSON. + * @return string + */ protected function getTestStatus($status, $message) { switch ($status) { @@ -270,51 +277,55 @@ protected function getTestStatus($status, $message) } } - /** - * Filters the stack trace from a PHPUnit test result to exclude VPU's - * trace. - * - * @param string $stack The stack trace. - * @param string $source The executing source (web or cli). - * @access protected - * @return string - */ + /** + * Filters the stack trace from a PHPUnit test result to exclude VPU's + * trace. + * + * @param string $stack + * The stack trace. + * @param string $source + * The executing source (web or cli). + * @return string + */ protected function getTrace($stack, $source) { - if (!$stack) { + if (! $stack) { return ''; } - + ob_start(); if ($source == 'web') { - print_r(array_slice($stack, 0, -6)); + print_r(array_slice($stack, 0, - 6)); } else { - print_r(array_slice($stack, 0, -2)); + print_r(array_slice($stack, 0, - 2)); } $trace = trim(ob_get_contents()); if (ob_get_length()) { ob_end_clean(); } - + return $trace; } - /** - * Serves as the error handler. - * - * @param int $number The level of the error raised. - * @param string $message The error message. - * @param string $file The file in which the error was raised. - * @param int $line The line number at which the error was raised. - * @access public - * @return bool - */ + /** + * Serves as the error handler. + * + * @param integer $number + * The level of the error raised. + * @param string $message + * The error message. + * @param string $file + * The file in which the error was raised. + * @param integer $line + * The line number at which the error was raised. + * @return bool + */ public function handleErrors($number, $message, $file, $line) { if ($number > error_reporting()) { return true; } - + switch ($number) { case E_WARNING: $type = 'E_WARNING'; @@ -351,13 +362,13 @@ public function handleErrors($number, $message, $file, $line) return true; } - /** - * Parses and formats the JSON output from PHPUnit into an associative array. - * - * @param string $pu_output The JSON output from PHPUnit. - * @access protected - * @return array - */ + /** + * Parses and formats the JSON output from PHPUnit into an associative array. + * + * @param string $pu_output + * The JSON output from PHPUnit. + * @return array + */ protected function parseOutput($pu_output) { $results = ''; @@ -367,11 +378,11 @@ protected function parseOutput($pu_output) $pu_output = substr_replace($pu_output, '|||', $pos, strlen($elem)); $results .= $elem . ','; } - + $results = '[' . rtrim($results, ',') . ']'; - + $results = json_decode($results, true); - + // For PHPUnit 3.5.x, which doesn't include test output in the JSON $pu_output = explode('|||', $pu_output); foreach ($pu_output as $key => $data) { @@ -379,40 +390,40 @@ protected function parseOutput($pu_output) $results[$key]['output'] = $data; } } - + return $results; } - /** - * Retrieves the files from any supplied directories, and filters - * the list of tests by ensuring that the files exist and are PHP files. - * - * @param array $tests The directories/filenames containing the tests to - * be run through PHPUnit. - * @access protected - * @return array - */ + /** + * Retrieves the files from any supplied directories, and filters + * the list of tests by ensuring that the files exist and are PHP files. + * + * @param array $tests + * The directories/filenames containing the tests to + * be run through PHPUnit. + * @return array + */ protected function parseTests($tests) { $collection = array(); - + foreach ($tests as $test) { if (is_dir($test)) { - $it = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator(realpath($test)), - \RecursiveIteratorIterator::LEAVES_ONLY + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(realpath($test)), + RecursiveIteratorIterator::LEAVES_ONLY ); while ($it->valid()) { $ext = strtolower(pathinfo($it->key(), PATHINFO_EXTENSION)); - if (!$it->isDot() && $ext == 'php') { + if (! $it->isDot() && $ext == 'php') { $collection[] = $it->key(); } - + $it->next(); } continue; } - + $ext = strtolower(pathinfo($test, PATHINFO_EXTENSION)); if (file_exists($test) && $ext == 'php') { $collection[] = realpath($test); @@ -422,18 +433,18 @@ protected function parseTests($tests) return array_keys(array_flip($collection)); } - /** - * Runs supplied tests through PHPUnit. - * - * @param array $tests The directories/filenames containing the tests - * to be run through PHPUnit. - * @access public - * @return string - */ + /** + * Runs supplied tests through PHPUnit. + * + * @param array $tests + * The directories/filenames containing the tests + * to be run through PHPUnit. + * @return string + */ public function runTests($tests) { - $suite = new \PHPUnit_Framework_TestSuite(); - + $suite = new PHPUnit_Framework_TestSuite(); + $tests = $this->parseTests($tests); $original_classes = get_declared_classes(); foreach ($tests as $test) { @@ -446,41 +457,41 @@ public function runTests($tests) $suite->addTestSuite($test); } } - - $result = new \PHPUnit_Framework_TestResult(); - $result->addListener(new \PHPUnit_Util_Log_JSON("/tmp/res.json")); - + + $result = new PHPUnit_Framework_TestResult(); + $result->addListener(new PHPUnit_Util_Log_JSON("/tmp/res.json")); + // We need to temporarily turn off html_errors to ensure correct // parsing of test debug output $html_errors = ini_get('html_errors'); ini_set('html_errors', 0); - + ob_start(); $suite->run($result); - //$results = ob_get_contents(); + // $results = ob_get_contents(); $results = file_get_contents("/tmp/res.json"); if (ob_get_length()) { ob_end_clean(); } - + ini_set('html_errors', $html_errors); return $results; } - /** - * Checks that the provided XML configuration file contains the necessary - * JSON listener. - * - * @param string $xml_config The path to the PHPUnit XML configuration - * file. - * @access protected - * @return void - */ + /** + * Checks that the provided XML configuration file contains the necessary + * JSON listener. + * + * @param string $xml_config + * The path to the PHPUnit XML configuration + * file. + * @return void + */ protected function checkXmlConfiguration($xml_config) { - $configuration = \PHPUnit_Util_Configuration::getInstance($xml_config); + $configuration = PHPUnit_Util_Configuration::getInstance($xml_config); $listeners = $configuration->getListenerConfiguration(); - + $required_listener = 'PHPUnit_Util_Log_JSON'; $found = false; foreach ($listeners as $listener) { @@ -489,41 +500,44 @@ protected function checkXmlConfiguration($xml_config) break; } } - if (!$found) { - throw new \DomainException( - "XML Configuration file doesn't contain the required " . - "{$required_listener} listener." + if (! $found) { + throw new DomainException( + "XML Configuration file doesn't contain the required {$required_listener} listener." ); } } - /** - * Runs PHPUnit with the supplied XML configuration file. - * - * @param string $xml_config The path to the PHPUnit XML configuration - * file. - * @access public - * @return string - */ + /** + * Runs PHPUnit with the supplied XML configuration file. + * + * @param string $xml_config + * The path to the PHPUnit XML configuration + * file. + * @return string + */ public function runWithXml($xml_config) { $this->checkXmlConfiguration($xml_config); - $command = new \PHPUnit_TextUI_Command(); - + $command = new PHPUnit_TextUI_Command(); + // We need to temporarily turn off html_errors to ensure correct // parsing of test debug output $html_errors = ini_get('html_errors'); ini_set('html_errors', 0); - + ob_start(); - $command->run(array('--configuration', $xml_config, '--stderr'), false); + $command->run(array( + '--configuration', + $xml_config, + '--stderr' + ), false); $results = ob_get_contents(); if (ob_get_length()) { ob_end_clean(); } - + ini_set('html_errors', $html_errors); - + $start = strpos($results, '{'); $end = strrpos($results, '}'); return substr($results, $start, $end - $start + 1); diff --git a/app/public/index.php b/app/public/index.php index f3dfedf9..bcb0a872 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -1,6 +1,18 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ +require dirname(__DIR__) . '/config/bootstrap.php'; - $request = new \nx\core\Request(); - $dispatcher = new \nx\core\Dispatcher(); - $dispatcher->handle($request, \app\config\Routes::getRoutes()); +$request = new \nx\core\Request(); +$dispatcher = new \nx\core\Dispatcher(); +$dispatcher->handle($request, \app\config\Routes::getRoutes()); diff --git a/app/test/DateTest.php b/app/test/DateTest.php index c0574bbd..3a36ed40 100644 --- a/app/test/DateTest.php +++ b/app/test/DateTest.php @@ -1,19 +1,52 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * Data test + * + * Testing class + * + * @author Nick Sinopoli + */ class DateTest extends PHPUnit_Framework_TestCase { - public function testThis() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'test'; $this->assertEquals($key, $value, 'test_this() failed!'); } - public function testThisToo() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { $key = 'test'; $value = 'test'; diff --git a/app/test/IncompleteTest.php b/app/test/IncompleteTest.php index 5a4b9103..67f2e163 100644 --- a/app/test/IncompleteTest.php +++ b/app/test/IncompleteTest.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * Incomplete tests + * + * Testing class + * + * @author Nick Sinopoli + */ class IncompleteTest extends PHPUnit_Framework_TestCase { - public function testSomething() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { // Optional: Test anything here, if you want. $this->assertTrue(true, 'This should already work.'); @@ -15,7 +41,14 @@ public function testSomething() $this->markTestIncomplete('This test has not been implemented yet.'); } - public function testSomethingElse() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { $key = 'test'; $value = 'test'; diff --git a/app/test/PUTest.php b/app/test/PUTest.php index d46fe8fd..15d4fce3 100644 --- a/app/test/PUTest.php +++ b/app/test/PUTest.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * PU Tests + * + * Testing class + * + * @author Nick Sinopoli + */ class PUTest extends PHPUnit_Framework_TestCase { - public function testThis() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'value'; @@ -14,7 +40,14 @@ public function testThis() $this->assertEquals($key, $value, 'test_this() failed!'); } - public function testThisToo() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { somestr; $key = 'test'; diff --git a/app/test/PUTest2.php b/app/test/PUTest2.php index 067a7ec1..60d7ca5c 100644 --- a/app/test/PUTest2.php +++ b/app/test/PUTest2.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * PU2 tests + * + * Testing class + * + * @author Nick Sinopoli + */ class PUTest2 extends PHPUnit_Framework_TestCase { - public function testThis() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'test'; @@ -14,7 +40,14 @@ public function testThis() $this->assertEquals($key, $value, 'test_this() failed!'); } - public function testThisToo() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { $key = 'test'; $value = 'test'; diff --git a/app/test/SkippedTest.php b/app/test/SkippedTest.php index 0bbde870..53ef5adb 100644 --- a/app/test/SkippedTest.php +++ b/app/test/SkippedTest.php @@ -1,11 +1,35 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * Skipped test + * + * Testing class + * + * @author Nick Sinopoli + */ class SkippedTest extends PHPUnit_Framework_TestCase { + /** + * Setup the tests + * + * @return void + */ protected function setUp() { if (! extension_loaded('something_bogus')) { @@ -13,7 +37,14 @@ protected function setUp() } } - public function testSomethingElse() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'value'; diff --git a/app/test/sample_dir/IncompleteTest2.php b/app/test/sample_dir/IncompleteTest2.php index 1c106ab5..65881977 100644 --- a/app/test/sample_dir/IncompleteTest2.php +++ b/app/test/sample_dir/IncompleteTest2.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * Incomplete test 2 + * + * Testing class + * + * @author Nick Sinopoli + */ class IncompleteTest2 extends PHPUnit_Framework_TestCase { - public function testSomething() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { // Optional: Test anything here, if you want. $this->assertTrue(true, 'This should already work.'); @@ -15,7 +41,14 @@ public function testSomething() $this->markTestIncomplete('This test has not been implemented yet.'); } - public function testSomethingElse() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { $key = 'test'; $value = 'test'; diff --git a/app/test/sample_dir/PUTest3.php b/app/test/sample_dir/PUTest3.php index 006b8707..b2b91b65 100644 --- a/app/test/sample_dir/PUTest3.php +++ b/app/test/sample_dir/PUTest3.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * PU3 test + * + * Testing class + * + * @author Nick Sinopoli + */ class PUTest3 extends PHPUnit_Framework_TestCase { - public function testThis() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'test'; @@ -14,7 +40,14 @@ public function testThis() $this->assertEquals($key, $value, 'test_this() failed!'); } - public function testThisToo() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { $key = 'test'; $value = 'test'; diff --git a/app/test/sample_dir/PUTest4.php b/app/test/sample_dir/PUTest4.php index 53097dd5..22ed116e 100644 --- a/app/test/sample_dir/PUTest4.php +++ b/app/test/sample_dir/PUTest4.php @@ -1,12 +1,38 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace visualphpunit; use \PHPUnit_Framework_TestCase; +/** + * PU4 test + * + * Testing class + * + * @author Nick Sinopoli + */ class PUTest4 extends PHPUnit_Framework_TestCase { - public function testThis() + /** + * Test one thing + * + * This test is just a dummy + * + * @test + */ + public function oneThing() { $key = 'test'; $value = 'value'; @@ -14,7 +40,14 @@ public function testThis() $this->assertEquals($key, $value, 'test_this() failed!'); } - public function testThisToo() + /** + * Test another thing + * + * This test is just a dummy + * + * @test + */ + public function anotherThing() { somestr; $key = 'test'; diff --git a/composer.json b/composer.json index b0ea8fe2..88504b6c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name" : "visual-php-unit/visual-php-unit", + "name" : "visualphpunit/visualphpunit", "description" : "A PHPUnit GUI", "type" : "application", "authors" : [{ @@ -54,8 +54,5 @@ "config" : { "bin-dir" : "bin/", "vendor-dir" : "vendor/" - }, - "require-dev" : { - "squizlabs/php_codesniffer" : "2.3.2@stable" } } \ No newline at end of file diff --git a/nx/core/Dispatcher.php b/nx/core/Dispatcher.php index 79fc4b27..9d88ab07 100644 --- a/nx/core/Dispatcher.php +++ b/nx/core/Dispatcher.php @@ -1,12 +1,18 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace nx\core; /** * The Dispatcher handles incoming HTTP requests and sends back responses. - * - * @author Nick Sinopoli - * @copyright 2011-2012 Nick Sinopoli - * @license http://opensource.org/licenses/BSD-3-Clause The BSD License */ class Dispatcher { diff --git a/nx/core/Request.php b/nx/core/Request.php index a3aee354..f804a1c4 100644 --- a/nx/core/Request.php +++ b/nx/core/Request.php @@ -1,4 +1,14 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace nx\core; /** diff --git a/nx/core/Response.php b/nx/core/Response.php index 90030ed0..255c7316 100644 --- a/nx/core/Response.php +++ b/nx/core/Response.php @@ -1,4 +1,14 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace nx\core; /** diff --git a/nx/core/Router.php b/nx/core/Router.php index 2ef71213..03485c85 100644 --- a/nx/core/Router.php +++ b/nx/core/Router.php @@ -1,5 +1,14 @@ + * @copyright 2011-2015 VisualPHPUnit + * @license http://opensource.org/licenses/BSD-3-Clause The BSD License + * @link https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit + */ namespace nx\core; /** diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 00000000..b1398ba0 --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,14 @@ + + +VisualPHPUnit + + build/phpdoc + + + build/phpdoc + + + app + nx + + \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy