Example #1
0
 public function index($request)
 {
     if (!$request->is('ajax')) {
         return $this->redirect('/');
     }
     $dir = realpath(urldecode($request->query['dir']));
     $test_dir = realpath(\app\lib\Library::retrieve('test_directory'));
     if (!$dir || strpos($dir, $test_dir) !== 0) {
         return array();
     }
     $dir .= '/';
     $files = scandir($dir);
     // Don't return anything if 'files' are '.' or '..'
     if (count($files) < 3) {
         return array();
     }
     $show_hidden_files = \app\lib\Library::retrieve('show_hidden_files');
     $final_dirs = array();
     $final_files = array();
     foreach ($files as $file) {
         if ($file != '.' && $file != '..' && ($show_hidden_files || strpos($file, '.') !== 0)) {
             $path = $dir . $file;
             $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
             if (is_dir($path)) {
                 $final_dirs[] = array('type' => 'directory', 'name' => $file, 'path' => $path);
             } elseif (is_file($path) && $ext == 'php') {
                 $final_files[] = array('type' => 'file', 'name' => $file, 'path' => $path);
             }
         }
     }
     return array_merge($final_dirs, $final_files);
 }
Example #2
0
 /**
  * Index
  *
  * @param string $request
  *            The request to process
  * @return array
  */
 public function index($request)
 {
     $snapshot_directory = Library::retrieve('snapshot_directory');
     if (!$request->is('ajax')) {
         $snapshots = array();
         $handler = @opendir($snapshot_directory);
         if (!$handler) {
             return compact('snapshots');
         }
         while (($file = readdir($handler)) !== false) {
             $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
             if (strpos($file, '.') === 0 || $ext != 'html') {
                 continue;
             }
             $snapshots[] = $file;
         }
         closedir($handler);
         rsort($snapshots);
         return compact('snapshots');
     }
     if (!isset($request->query['snapshot'])) {
         return '';
     }
     $file = realpath($snapshot_directory) . "/{$request->query['snapshot']}";
     return file_exists($file) ? file_get_contents($file) : '';
 }
Example #3
0
 protected function _store_statistics($stats)
 {
     $db_options = \app\lib\Library::retrieve('db');
     $db = new $db_options['plugin']();
     if (!$db->connect($db_options)) {
         return array('type' => 'failed', 'title' => 'Error Connecting to Database', 'message' => implode(' ', $db->get_errors()));
     }
     $now = date('Y-m-d H:i:s');
     foreach ($stats as $key => $stat) {
         $data = array('run_date' => $now, 'failed' => $stat['failed'], 'incomplete' => $stat['incomplete'], 'skipped' => $stat['skipped'], 'succeeded' => $stat['succeeded']);
         $table = ucfirst(rtrim($key, 's')) . 'Result';
         if (!$db->insert($table, $data)) {
             return array('type' => 'failed', 'title' => 'Error Inserting Record', 'message' => implode(' ', $db->get_errors()));
         }
     }
     return array('type' => 'succeeded', 'title' => 'Statistics Stored', 'message' => 'The statistics generated during this test run were ' . 'successfully stored.');
 }
Example #4
0
 /**
  * Index
  *
  * @param string $request
  *            The request to process
  * @return array
  */
 public function index($request)
 {
     if (!$request->is('ajax')) {
         return $this->redirect('/');
     }
     $dir = realpath(urldecode($request->query['dir']));
     if (!$dir) {
         return array();
     }
     $test_directories = Library::retrieve('test_directories');
     $valid_dir = false;
     $group_name = '';
     foreach ($test_directories as $key => $test_directory) {
         if (strpos($dir, realpath($test_directory)) === 0) {
             $group_name = $key;
             $valid_dir = true;
             break;
         }
     }
     // 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 = 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)) {
             $path = $dir . $file;
             $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
             if (is_dir($path)) {
                 $final_dirs[] = array('type' => 'directory', 'name' => $file, 'path' => $path);
             } elseif (is_file($path) && $ext == 'php') {
                 $final_files[] = array('type' => 'file', 'name' => $file, 'path' => $path);
             }
         }
     }
     return array('name' => $group_name, 'results' => array_merge($final_dirs, $final_files));
 }
Example #5
0
<?php

$root = dirname(dirname(__DIR__));
$config = array('pear_path' => '/usr/share/pear', 'test_directory' => "{$root}/app/test", 'store_statistics' => false, 'db' => array('plugin' => '\\app\\lib\\PDO_MySQL', 'database' => 'vpu', 'host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => 'admin'), 'create_snapshots' => false, 'snapshot_directory' => "{$root}/app/history/", 'sandbox_errors' => false, 'error_reporting' => E_ALL | E_STRICT, 'ignore_hidden_folders' => true, 'xml_configuration_file' => false, 'usable_group_names' => array('DefaultTestGroup'), 'bootstraps' => array());
set_include_path(get_include_path() . PATH_SEPARATOR . $root . PATH_SEPARATOR . $config['pear_path']);
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Util/Log/JSON.php';
spl_autoload_register(function ($class) use($root) {
    $class = str_replace('\\', '/', $class);
    $file = "{$root}/{$class}.php";
    if (file_exists($file)) {
        require $file;
    }
});
foreach ($config['bootstraps'] as $bootstrap) {
    require $bootstrap;
}
\app\lib\Library::store($config);
Example #6
0
/**
 * VisualPHPUnit
 *
 * VisualPHPUnit is a visual front-end for PHPUnit.
 *
 * PHP Version 5.3<
 *
 * @author    Nick Sinopoli <*****@*****.**>
 * @copyright 2011-2015 VisualPHPUnit
 * @license   http://opensource.org/licenses/BSD-3-Clause The BSD License
 * @link      https://github.com/VisualPHPUnit/VisualPHPUnit VisualPHPUnit
 */
use app\lib\Library;
$root = dirname(dirname(__DIR__));
$config = array('composer_vendor_path' => $root . '/vendor', 'test_directories' => array('Sample Tests' => "{$root}/app/testphpunit"), 'store_statistics' => false, 'db' => array('plugin' => '\\app\\lib\\PDOMySQL', 'database' => 'vpu', 'host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => ''), 'create_snapshots' => false, 'snapshot_directory' => "{$root}/app/history/", 'sandbox_errors' => false, 'error_reporting' => E_ALL | E_STRICT, 'ignore_hidden_folders' => true, 'xml_configuration_files' => array(), 'bootstraps' => array());
set_include_path(get_include_path() . PATH_SEPARATOR . $root . PATH_SEPARATOR . $config['composer_vendor_path'] . PATH_SEPARATOR . $config['composer_vendor_path'] . '/phpunit/phpunit/src');
require_once 'autoload.php';
require_once 'Util/Log/JSON.php';
spl_autoload_register(function ($class) use($root) {
    $class = str_replace('\\', '/', $class);
    $file = "{$root}/{$class}.php";
    if (file_exists($file)) {
        require $file;
    }
});
foreach ($config['bootstraps'] as $bootstrap) {
    require $bootstrap;
}
Library::store($config);
Example #7
0
 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') {
         return array('type' => $request->data['graph_type'], 'timeFrame' => $request->data['time_frame'], 'categories' => array(), '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)) {
         return array('error' => array('title' => 'Error Connecting to Database', 'message' => implode(' ', $db->get_errors())));
     }
     switch ($request->data['time_frame']) {
         case 'Monthly':
             $interval = 2678400;
             $sql_format = 'Y-m-01';
             $output = 'M Y';
             break;
         case 'Weekly':
             $interval = 604800;
             $sql_format = 'Y-m-d';
             $output = 'm/d';
             break;
         default:
             $interval = 86400;
             $sql_format = 'Y-m-d';
             $output = 'm/d';
             break;
     }
     $current = $start = strtotime($request->data['start_date']);
     $end = strtotime($request->data['end_date']) + $interval;
     $categories = array();
     $plot_values = array('failed' => array(), 'incomplete' => array(), 'skipped' => array(), 'succeeded' => array());
     while ($current < $end) {
         $categories[] = date($output, $current);
         $next = $current + $interval;
         $data = array('failed' => 0, 'incomplete' => 0, 'skipped' => 0, 'succeeded' => 0);
         $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->fetch_all();
         $num_rows = count($results);
         if ($num_rows > 0) {
             foreach ($results as $result) {
                 foreach ($result as $key => $value) {
                     $data[$key] += $value;
                 }
             }
         }
         foreach ($data as $key => $val) {
             if ($num_rows > 0) {
                 $plot_values[$key][] = round($val / $num_rows, 2);
             } else {
                 $plot_values[$key][] = 0;
             }
         }
         $current = $next;
     }
     $db->close();
     return array('type' => $request->data['graph_type'], 'timeFrame' => $request->data['time_frame'], 'categories' => $categories, 'failed' => $plot_values['failed'], 'succeeded' => $plot_values['succeeded'], 'skipped' => $plot_values['skipped'], 'incomplete' => $plot_values['incomplete']);
 }
Example #8
0
 /**
  * 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);
     // 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);
     $vendor_path = Library::retrieve('composer_vendor_path');
     $command = "{$vendor_path}/bin/phpunit --configuration {$xml_config} --stderr";
     $results = shell_exec($command . " 2>&1");
     ini_set('html_errors', $html_errors);
     $start = strpos($results, '{');
     $end = strrpos($results, '}');
     return substr($results, $start, $end - $start + 1);
 }
Example #9
0
 /**
  * Finish profiling w/ XHProf.
  * 
  * @return string The run ID.
  */
 private function xhprof_finish()
 {
     $profiler_namespace = \app\lib\Library::retrieve('xhprof_namespace');
     $xhprof_data = xhprof_disable();
     $xhprof_runs = new \XHProfRuns_Default();
     return $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
 }
Example #10
0
 /**
  * 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);
     // 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);
     $bin_path = Library::retrieve('composer_bin_path');
     $command = "{$bin_path}/phpunit --configuration {$xml_config} --stderr";
     $results = shell_exec($command);
     ini_set('html_errors', $html_errors);
     return $results;
 }