我是单元测试的新手,所以这可能是一个有点愚蠢的问题.想象一下,我们有一个简单的模型方法.
public function get_all_users($uid = false, $params = array()){
$users = array();
if(empty($uid) && empty($params)){return $users;}
$this->db->from('users u');
if($uid){
$this->db->where('u.id',(int)$id);
}
if(!empty($params)){
if(isset($params['is_active']){
$this->db->where('u.status ', 'active');
}
if(isset($params['something_else']){ // some more filter actions}
}
$q = $this->db->get();
if($q->num_rows()){
foreach($q->result_array() as $user){
$users[$user['id']] = $user;
}
}
$q->free_result();
return $users;
}
Run Code Online (Sandbox Code Playgroud)
问题是如何为它编写_good测试?UPD:我想,最好的CI单元测试库是Toast,所以我正在寻找的例子,最好用它来编写.谢谢.
也许这有点愚蠢,但我不确定什么是更好的.如果我必须在db中查看超过10k行的存在,那我该怎么办?
#1 - 一个查询
select id from table1 where name in (smth1,smth2...{till 30k})
Run Code Online (Sandbox Code Playgroud)
#2 - 许多查询
select id from table1 where name=smth1
Run Code Online (Sandbox Code Playgroud)
虽然,性能不是目标,但我不想用mysql下载;)也许,任何其他解决方案都会更合适......谢谢.
upd:任务是获取域列表,保存新的(尚未在db中)并删除那些从列表中消失的域列表.希望,它会有所帮助......
假设这是一个小问题,但在php中是否有类似mysql的LIKE函数?
所以,例如:
like('goo*','google.com');//is true
like('*gl*','google.com');//true
like('google.com','google.com')//also true
Run Code Online (Sandbox Code Playgroud)
我知道正则表达式rullez,但不知道任何解决方案达到此目的