<?php require '../boot.php'; require 'PHPUnit/Framework.php'; require 'PHPUnit/Framework/Test.php'; require 'PHPUnit/TextUI/TestRunner.php'; // we need a lot time and memory here! set_time_limit(120); ini_set('memory_limit', '100M'); // code covarage starts now (if we need it, and xdebug is available) if (isset($_GET['report'])) { if (function_exists('xdebug_start_code_coverage')) { xdebug_start_code_coverage(); } else { unset($_GET['report']); } } // define constas needed for test suite define('DS', DIRECTORY_SEPARATOR); define('TESTS_DIR', TESTS_ROOT . DS . 'unit'); define('TESTS_REPORTS', TESTS_ROOT . DS . 'reports'); define('TESTS_ASSETS', TESTS_ROOT . DS . 'assets'); $options = array(); if (isset($_GET['report'])) { $options['reportDirectory'] = TESTS_REPORTS; } // run the test $r = new Test_Runner(array_cut($_GET, 'for', ''), isset($_GET['skip']) ? explode(',', $_GET['skip']) : array()); $r->runHtml($options);
/** * update()後動作 * * 在更新完成員之後,接下來再依據成員的內容,更新自身$table_name資料表的資料。 * 如果成員有增加,則插入多的資料;如果成員減少了,則刪除多餘的資料。 */ protected function _post_update() { $new_id_array = $this->get_member_id_array(); $id = $this->get_id(); if (isset($id)) { array_unique($new_id_array); $db = $this->db; $db->select($this->foreign_field); $db->from($this->table_name); $db->distinct(); $db->where($this->index_field, $id); $query = $db->get(); $old_id_array = array(); foreach ($query->result_array() as $row) { $old_id_array[] = $row[$this->foreign_field]; } $delete_id_array = array_cut($old_id_array, $new_id_array); if (count($delete_id_array) > 0) { $db->where($this->index_field, $id); $db->where_in($this->foreign_field, $delete_id_array); $db->delete($this->table_name); } $insert_id_array = array_cut($new_id_array, $old_id_array); $set = array(); $set[$this->index_field] = $id; foreach ($insert_id_array as $insert_id) { $set[$this->foreign_field] = $insert_id; $db->insert($this->table_name, $set); } } //if (isset($this->id)) }