小测试

看了《PHP敏捷开发框架CodeIgniter》第7章,发现从设计角度来讲,CodeIgniter整体设计框架,用其设计者得话讲就是:

“我想要简化问题,所以,我决定创建一个大的控制器对象包含很多其它对象的实例:…当一个用户创建他们自己的控制器时,他们能够轻松地访问任何资源,不用担心作用域的问题。”

 

第8章看了个开头,为了增加体验,把开始的例子,也就是对PHP函数floor的测试代码贴在这里,在start.php中:

<?php
class Start extends CI_Controller
{
 function __construct()
 {
  parent::__construct();
  $this->load->helper('url');
  $this->load->helper('form');
  $this->load->library('unit_test');
  $this->unit->active(TRUE);
 }

 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')
  {
   $newdata=array('status'=>'ok');
   $this->session->set_userdata($newdata);
   $ip=$this->session->userdata('ip_address');
   echo $ip;
   $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->report();
  $this->load->view('mainpage');
 }
}
?>

 

两个视图文件不变。另外,如果将$this->unit->report()变成$this->unit->result(), 看不到想要的结果!

转载于:https://www.cnblogs.com/oemwang/archive/2012/01/13/2321417.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值