以下的小例子加入了基准测试类和评测器类,视图文件不变。单元测试类的练习没有做!

 

控制器start.php内容如下:

<?php
class Start extends CI_Controller
{
 function __construct()
 {
  parent::__construct();

  $this->output->enable_profiler(TRUE);

  $this->load->helper('url');
  $this->load->helper('form');
  $this->load->library('unit_test');
  $this->unit->active(TRUE);
  $this->load->database();
 }

 function index()
 {
 // $data['mytitle']="My site";
 // $data['base']=$this->config->item('base_url');
 // $data['css']=$this->config->item('css');
  $data['mytitle']="A website to monitor other websites";
  $data['text']="Please log in here!";

  $this->load->view('entrypage',$data);
 }

 function assessme()
 { 
  $this->load->library('session');
  $name=$_POST['username'];
  $password=$_POST['password'];
  if($name=='fred' && $password=='12345')
  { 
    
   $this->benchmark->mark('here_start');
  
   $newdata=array('status'=>'ok');
   $this->session->set_userdata($newdata);
   echo $this->session->userdata('ip_address')."<br>";
   echo $this->session->userdata('session_id')."<br>";
   echo $this->session->userdata('user_agent')."<br>";
   echo $this->session->userdata('last_activity')."<br><br>";

   $currentsession=array('ip_address'=>$this->session->userdata('ip_address'),
           'session_id'=>$this->session->userdata('session_id'),
           'user_agent'=>$this->session->userdata('user_agent'),
           'last_activity'=>$this->session->userdata('last_activity'));
   $this->db->insert('ci_sessions',$currentsession);

   $this->benchmark->mark('here_end');
   echo $this->benchmark->elapsed_time('here','there')."<br>";
  
   $this->output->enable_profiler(TRUE);

   $this->mainpage();
  }
  else
  { 
   $this->index();
  ;}
 }

 function mainpage()
 {
  $test=floor(1.56);
  $expected_result=1;
  $test_name='test php floor function';
  $this->unit->run($test,$expected_result,$test_name);
  $test=floor(2.56);
  $expected_result=1;
  $test_name='tests php floor function';
  $this->unit->run($test,$expected_result,$test_name);
  //echo $this->unit->result();
  $this->load->view('mainpage');
 }
}
?>

posted on 2012-01-16 13:19  vesa3.0  阅读(361)  评论(0编辑  收藏  举报