本文整理汇总了PHP中Test::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::exists方法的具体用法?PHP Test::exists怎么用?PHP Test::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Test
的用法示例。
在下文中一共展示了Test::exists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* This method will initialize this instance of test object with Test model, or id of test model.
* @param DataMapper|integer $test_model Test model or id of test record.
* @throws TestException can be thrown if $test_model is not Test object, test record not exists or test type or subtype is not supported.
*/
public function initialize($test_model)
{
if (is_object($test_model) && !$test_model instanceof Test) {
throw new TestException($this->CI->lang->line('tests_general_error_cant_initialize_with_non_test_model'), 1000001);
} elseif (is_integer($test_model)) {
$test_model_id = $test_model;
$test_model = new Test();
$test_model->get_by_id($test_model_id);
}
if ($test_model->exists()) {
if ($test_model->type !== $this->test_type) {
throw new TestException(sprintf($this->CI->lang->line('tests_general_error_test_type_is_not_supported'), get_class($this)), 1000002);
} elseif (!array_key_exists($test_model->subtype, $this->test_subtypes)) {
throw new TestException(sprintf($this->CI->lang->line('tests_general_error_test_subtype_is_not_supported'), get_class($this)), 1000003);
}
$current_test = array('subtype' => $test_model->subtype, 'config' => unserialize($test_model->configuration), 'id' => $test_model->id, 'enable_scoring' => (int) $test_model->enable_scoring > 0 ? TRUE : FALSE, 'task_id' => $test_model->task_id, 'timeout' => $test_model->timeout);
$this->current_test = $current_test;
} else {
throw new TestException($this->CI->lang->line('tests_general_error_test_record_not_exists'), 1000004);
}
}
示例2: run_single_test
public function run_single_test($test_id, $source_file, $evaluation = FALSE, $student_id = NULL, $token = '')
{
$output = new stdClass();
$output->text = '';
$output->code = 0;
try {
$test = new Test();
$test->get_by_id(intval($test_id));
if ($test->exists()) {
$test_object = $this->load->test($test->type);
$test_object->initialize($test);
$output->text = $test_object->run(decode_from_url($source_file), (bool) (int) $evaluation && strlen($token) > 0, $student_id, $token);
}
} catch (Exception $e) {
$output->text = $e->getMessage();
$output->code = $e->getCode();
}
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($output));
}
示例3: upgrade_java_tests
public function upgrade_java_tests()
{
$this->load->database();
$tests = new Test();
$tests->include_related('task');
$tests->where('type', 'java');
$tests->where('subtype', 'unit_test');
$tests->order_by_related('task', 'name', 'asc');
$tests->order_by('name', 'asc');
$tests->get_iterated();
$unsuccessful_files = array();
if ($tests->exists()) {
echo 'Found ' . $tests->result_count() . ' java unit tests to check, starting process now.' . PHP_EOL;
$this->load->library('cli_progress_bar');
$this->cli_progress_bar->init($tests->result_count());
$this->cli_progress_bar->increment(0);
$this->load->helper('application');
foreach ($tests as $test) {
$this->cli_progress_bar->print_text('Task "' . $test->task_name . '" test "' . $test->name . '" ...', true);
$path_to_dir = APPPATH . '../private/uploads/unit_tests/test_' . $test->id;
$path_to_file = $path_to_dir . '/unit_test/unit_test.zip';
$backup_file = $path_to_dir . '/unit_test/unit_test.backup-' . date('U') . '-' . date('Y-m-d-H-i-s') . '.zip';
if (file_exists($path_to_file)) {
copy($path_to_file, $backup_file);
if (file_exists($backup_file)) {
$this->cli_progress_bar->tick();
do {
$temp_directory = $path_to_dir . '/temp_' . date('U') . '-' . rand(1000, 9999);
} while (file_exists($temp_directory) && is_dir($temp_directory));
mkdir($temp_directory);
if (file_exists($temp_directory) && is_dir($temp_directory)) {
$this->cli_progress_bar->tick();
$zip = new ZipArchive();
if ($zip->open($path_to_file)) {
$zip->extractTo($temp_directory);
$zip->close();
$configuration = @unserialize($test->configuration);
if (is_array($configuration) && array_key_exists('class_to_run', $configuration)) {
$this->cli_progress_bar->tick();
if ($this->upgrade_single_java_unit_test($temp_directory, 'Test' . $configuration['class_to_run'] . '.java')) {
$this->cli_progress_bar->tick();
$zip = new ZipArchive();
if ($zip->open($path_to_file)) {
if ($zip->addFile($temp_directory . '/' . 'Test' . $configuration['class_to_run'] . '.java', 'Test' . $configuration['class_to_run'] . '.java')) {
$this->cli_progress_bar->print_text(' ... Done');
} else {
$this->cli_progress_bar->print_text(' Can\'t update zip archive.');
$unsuccessful_files[] = $path_to_file;
}
$zip->close();
} else {
$this->cli_progress_bar->print_text(' Can\'t open zip archive.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t read test configuration.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t open zip archive.');
$unsuccessful_files[] = $path_to_file;
}
unlink_recursive($temp_directory, true);
} else {
$this->cli_progress_bar->print_text(' Can\'t create temporary directory.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t back up zip file.');
$unsuccessful_files[] = $path_to_file;
}
} else {
$this->cli_progress_bar->print_text(' Can\'t find zip file.');
}
$this->cli_progress_bar->increment();
}
} else {
echo 'No java unit tests found.';
}
if (count($unsuccessful_files)) {
echo PHP_EOL . 'Some files can\'t be processed:' . PHP_EOL;
foreach ($unsuccessful_files as $file) {
echo ' ' . $file . PHP_EOL;
}
}
}
示例4: index
public function index($worker_id = 0)
{
$test_queue = new Test_queue();
$execute_tests = FALSE;
try {
$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
$this->db->trans_begin();
$test_queue->where('worker', NULL);
$test_queue->where('status', 0);
$test_queue->where('version >', 0);
$test_queue->group_start(' NOT ');
$test_queue->where('task_set_id', NULL);
$test_queue->group_end();
$test_queue->group_start(' NOT ');
$test_queue->where('student_id', NULL);
$test_queue->group_end();
$test_queue->order_by('priority', 'asc');
$test_queue->order_by('start', 'asc');
$test_queue->limit(1);
$sql_query = $test_queue->get_sql();
$sql_query = rtrim($sql_query, '; ' . "\n\r") . ' FOR UPDATE;';
$test_queue->query($sql_query);
if ($test_queue->exists()) {
$test_queue->worker = (int) $worker_id;
$test_queue->status = 1;
$test_queue->exec_start = date('Y-m-d H:i:s');
$test_queue->where('worker', NULL);
$test_queue->where('status', 0);
if ($test_queue->save()) {
$this->db->trans_commit();
$execute_tests = TRUE;
} else {
$this->db->trans_rollback();
}
} else {
$this->db->trans_rollback();
}
} catch (Exception $e) {
}
if ($test_queue->exists() && $execute_tests) {
//$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;');
//$this->db->trans_begin();
$this->lang->reinitialize_for_idiom($test_queue->system_language);
$this->lang->load('admin/tests');
$task_set = new Task_set();
$task_set->include_related('course', 'test_scoring_deadline');
$task_set->get_by_id($test_queue->task_set_id);
$student = new Student();
$student->get_by_id($test_queue->student_id);
$tests = new Test();
$tests->where_related($test_queue);
$tests->get_iterated();
try {
if ($task_set->exists() && $student->exists() && $tests->exists()) {
$version = $test_queue->version;
$run_evaluation = $task_set->enable_tests_scoring > 0 && $task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') ? TRUE : FALSE;
$score_percent = array();
$score_points = array();
$bonus_percent = array();
$bonus_points = array();
$total_tests_count = $tests->result_count();
foreach ($tests as $test) {
$test_queue->single_test_exec_start = date('Y-m-d H:i:s');
$test_queue->save();
$files = $task_set->get_student_files($student->id, (int) $version);
if (isset($files[(int) $version]['filepath']) && file_exists($files[(int) $version]['filepath'])) {
$test_object = $this->load->test($test->type);
$test_object->initialize($test);
$token = '';
//echo 'Test queue ' . $test_queue->id . ' is running test ' . $test->id . ' ... ' . PHP_EOL;
try {
$test_output = $test_object->run($files[(int) $version]['filepath'], $run_evaluation && $test->enable_scoring > 0, $student->id, $token);
$test_score = $test_object->get_last_test_score();
} catch (Exception $e) {
$test_output = $e->getMessage();
$test_score = 0;
}
$test_queue->set_join_field($test, 'result_text', $test_output);
$test_queue->set_join_field($test, 'evaluation_table', $test_object->get_last_test_scoring());
$test_queue->set_join_field($test, 'result', $test_object->get_last_exit_code());
//echo 'Test queue ' . $test_queue->id . ' is done with test ' . $test->id . ' ... ' . PHP_EOL;
if ($run_evaluation && $test->enable_scoring > 0) {
$this->db->select('*');
$task_id = $test->task_id;
$this->db->where('task_set_id', $task_set->id);
$this->db->where('task_id', (int) $task_id);
$query = $this->db->get('task_task_set_rel');
if ($query->num_rows() > 0) {
$task_rel = $query->row_object();
$min = (double) $task_rel->test_min_points;
$max = (double) $task_rel->test_max_points;
$percent = (double) $test_score / 100.0;
$points = (1.0 - $percent) * $min + $percent * $max;
if ($task_rel->bonus_task == 0) {
$test_queue->set_join_field($test, 'percent_points', $test_score);
$test_queue->set_join_field($test, 'points', $points);
$score_percent[$task_id] = isset($score_percent[$task_id]) ? $score_percent[$task_id] + $percent : $percent;
$percent = (double) $score_percent[$task_id];
$points = (1.0 - $percent) * $min + $percent * $max;
$score_points[$task_id] = $points;
//.........这里部分代码省略.........