/** * Fired when the thread did not properly complete * For example, this is called when the remote end hangs up, segfaults, * or otherwise closes the connection unexpectedly. * @param $key a key that describes file/class/test that was running * @param $data the data payload for the key **/ public function onThreadFail($key, $data) { $key = Snap_Request::decodeTestKey($key); $file = $key['file']; $class = $key['class']; $method = $key['method']; if (!$data) { $data = 'No error output captured. Please ensure your PHP environment allows output of errors.'; } // remove start and end tokens $data = str_replace(array(SNAPTEST_TOKEN_START, SNAPTEST_TOKEN_END), '', $data); $report = array('type' => 'fatal', 'message' => $file . ' had a fatal error: ' . $data, 'skip_details' => TRUE); $this->report_list[] = $report; $this->reporter->announceTestFail($report); }
<?php // snaptest index file // creates the layout, includes the necessary components, etc $urls = array('css' => Snap_Request::makeURL(array('mode' => 'resource', 'file' => 'css')), 'css-ie6' => Snap_Request::makeURL(array('mode' => 'resource', 'file' => 'css-ie6')), 'css-ie7' => Snap_Request::makeURL(array('mode' => 'resource', 'file' => 'css-ie7')), 'js' => Snap_Request::makeURL(array('mode' => 'resource', 'file' => 'js'))); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-us" /> <title>SnapTest Web Testing Console</title> <link rel="stylesheet" type="text/css" href="<?php echo $urls['css']; ?> "> <!--[if IE 6]> <link rel="stylesheet" type="text/css" href="<?php echo $urls['css-ie6']; ?> "> <![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" href="<?php echo $urls['css-ie7']; ?> "> <![endif]-->
/** * Sets the URL Base * @param string $base the base URL **/ public function setURLBase($base) { self::$base = $base; }
/** * Adapter function for making long option strings * @param $options an array of options * @return string **/ protected function makeLongOptions($options) { return Snap_Request::makeLongOptions($options); }
<?php // runtest interface // get the option $options = Snap_Request::getLongOptions(array('file' => 'null', 'test' => 'null', 'klass' => 'null')); if (!$options['file']) { echo ''; exit; } $file = $options['file']; $test = $options['test']; $klass = $options['klass']; // decrypt if required if (SNAP_WI_CRYPT) { $file = snap_decrypt($file, SNAP_WI_CRYPT); } // ensure file path matches test path prefix $file = str_replace(array('..', '//'), array('.', '/'), $file); if (!is_file($file)) { echo ''; exit; } if (strpos($file, SNAP_WI_TEST_PATH) !== 0 || !preg_match('#' . SNAP_WI_TEST_MATCH . '#', $file)) { echo ''; exit; } // file is safe, check test and klass if (!$test || !$klass) { echo ''; exit; }
<?php // snaptest web core initialization // requires PHP 5.2+ if (version_compare(phpversion(), '5.0.0') < 0) { echo "\n"; echo "SnapTest requires a PHP version >= 5.0.0\n"; exit; } define('SNAPTEST_CLI_INTERFACE', FALSE); require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'constants.php'; $options = Snap_Request::getLongOptions(array('mode' => 'index', 'key' => '')); require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'webfiles' . DIRECTORY_SEPARATOR . 'functions.php'; Snap_Request::setURLBase(SNAP_WI_URL_PATH); switch ($options['mode']) { case 'index': include SNAPTEST_WEBFILES . 'index.php'; exit; case 'resource': include SNAPTEST_WEBFILES . 'resource.php'; exit; case 'getfiles': include SNAPTEST_WEBFILES . 'getfiles.php'; exit; case 'loadtests': include SNAPTEST_WEBFILES . 'loadtests.php'; exit; case 'runtest': include SNAPTEST_WEBFILES . 'runtest.php'; exit; default:
<?php // loadtests module. Scans a file, and adds all tests found to an array // get the option $options = Snap_Request::getLongOptions(array('file' => 'null')); if (!$options['file']) { echo ''; exit; } $file = $options['file']; $file_original = $options['file']; // decrypt if required if (SNAP_WI_CRYPT) { $file = snap_decrypt($file, SNAP_WI_CRYPT); } // ensure file path matches test path prefix $file = str_replace(array('..', '//'), array('.', '/'), $file); if (!is_file($file)) { echo ''; exit; } if (strpos($file, SNAP_WI_TEST_PATH) !== 0 || !preg_match('#' . SNAP_WI_TEST_MATCH . '#', $file)) { echo ''; exit; } $analyzer = new Snap_FileAnalyzer(); $results = $analyzer->analyzeFile($file); $output = array(); foreach ($results as $klassname => $classes) { if (!is_array($classes)) { $out = array();
$file_list = SNAP_recurse_directory($path, $xtn); } else { $file_list = array($path); } writelog('Path contains ' . count($file_list) . ' files for scanning'); // start a dispatcher for multi-processing $dispatcher = new Snap_Dispatcher($php, __FILE__); // build master test list $analyzer = new Snap_FileAnalyzer(); $master_test_list = $dispatcher->dispatch(array('keys' => $file_list, 'dispatch' => array('analyze' => TRUE, 'verbose' => SNAPTEST_VERBOSE_MODE, 1 => '__KEY__'), 'onThreadComplete' => array($analyzer, 'onThreadComplete'), 'onThreadFail' => array($analyzer, 'onThreadFail'), 'onComplete' => array($analyzer, 'onComplete'))); unset($analyzer); // build a master test key list $master_test_key_list = array(); foreach ($master_test_list as $file => $classes) { if (!is_array($classes)) { die("File {$file} could not be read due to a fatal error:\n" . $classes . "\n"); } foreach ($classes as $klass => $tests) { foreach ($tests as $test) { $master_test_key_list[] = Snap_Request::makeTestKey($file, $klass, $test); } } } unset($master_test_list); writelog('Total tests found by analyzer: ' . count($master_test_key_list)); // create a test aggregator for $outmode $reporter = new Snap_TestAggregator($out_mode, count($master_test_key_list)); // dispatch the tests $dispatcher->dispatch(array('keys' => $master_test_key_list, 'dispatch' => array('test' => '__KEY__', 'verbose' => SNAPTEST_VERBOSE_MODE), 'onThreadComplete' => array($reporter, 'onThreadComplete'), 'onThreadFail' => array($reporter, 'onThreadFail'), 'onComplete' => array($reporter, 'onComplete'))); writelog('Complete, shutting down.' . "\n"); exit;