unit testing - Transaction test mode in CodeIgniter -
i saw in docs codeigniter:
"you can optionally put transaction system "test mode", cause queries rolled -- if queries produce valid result. use test mode set first parameter in
$this->db->trans_start()functiontrue"
i understand able use transaction (test_mode) support database fixture testing insert, update, delete. still affects database. set db_debug true. idea problem? much.
example code in controller: public function __construct(){ //load database library , model $this->load->library('database'); $this->load->model('message_mdl'); } public function do() { $data_insert = array('message' => 'hello'); $this->db->trans_start(true); $this->message_mdl->insert($data_insert); $this->db->trans_complete(); }
i tried not working me too. don't know why! i'll trying find reason. 'll here proper method. if find out pls let me know too.
but tried alternate method, working fine.
public function dothis() { $data_insert = array('message' => 'hello'); $this->db->trans_begin(); //manually start transaction. $this->message_mdl->insert($data_insert); $this->db->trans_rollback(); //rollback } make sure don't use $this->db->trans_off(); @ all.
Comments
Post a Comment