public function index($request) { if ($request->is('get')) { $test_directory = str_replace('\\', '/', realpath(\app\lib\Library::retrieve('test_directory'))); $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'); $use_xml = \app\lib\Library::retrieve('xml_configuration_file'); $xhprof_installed = \app\lib\Library::isXHProfInstalled(); return compact('create_snapshots', 'sandbox_errors', 'stats', 'store_statistics', 'suites', 'test_directory', 'use_xml', 'xhprof_installed'); } $data = array(); if (!empty($request->data['data_keys']) && !empty($request->data['data_values'])) { $data = array_combine($request->data['data_keys'], $request->data['data_values']); } $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, 'handle_errors')); } $xml_config = false; $notifications = array(); if ($request->data['use_xml']) { $xml_config = \app\lib\Library::retrieve('xml_configuration_file'); if (!$xml_config || !($xml_config = realpath($xml_config))) { $notifications[] = array('type' => 'failed', 'title' => 'No Valid XML Configuration File Found', 'message' => 'Please ensure that the ' . '<code>xml_configuration_file</code> in ' . '<code>app/config/bootstrap.php</code> exists and ' . 'has the proper permissions.'); } } $use_xhprof = $request->data['use_xhprof']; list($results, $memory_stats, $xhprof_run_id) = $xml_config ? $vpu->run_with_xml($xml_config, $use_xhprof) : $vpu->run_tests($tests, $data, $use_xhprof); $results = $vpu->compile_suites($results, 'web'); $xhprof_url = false; if ($xhprof_run_id !== false) { $xhprof_url_root = \app\lib\Library::retrieve('xhprof_root') . '/xhprof_html/'; $xhprof_ns = \app\lib\Library::retrieve('xhprof_namespace'); $xhprof_url = $xhprof_url_root . '?source=' . urlencode($xhprof_ns) . '&run=' . urlencode($xhprof_run_id); } if ($request->data['sandbox_errors']) { restore_error_handler(); } $suites = $results['suites']; $stats = $results['stats']; $errors = $vpu->get_errors(); $to_view = compact('suites', 'stats', 'errors', 'memory_stats', 'xhprof_url'); if ($request->data['create_snapshots']) { $notifications[] = $this->_create_snapshot($to_view); } if ($request->data['store_statistics']) { $notifications[] = $this->_store_statistics($stats); } return $to_view + compact('notifications'); }