simpletest를 사용하여 codeigniter 시스템을 테스트하려고하는데 오류가 계속 발생합니다. 나는 PHP와 codeigniter에 매우 익숙하다. 그래서 쉽게 가라.Codeigniter 테스팅 - 비 객체의 멤버 함수 호출
Fatal error: Call to a member function add() on a non-object in C:\xampp\htdocs\di2\application\tests\simple_test.php on line 35
이것은 데이터베이스에 새 사용자를 추가하려는 순간의 테스트 파일입니다. 나는이 오류가있는 이유
class Users_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
//Used to retrieve all of the members from the database and list them by their id in descending order
function get($id = null)
{
$this->db->select('id, first_name, last_name, dob, email_address, phone_number, address_line_1, address_line_2, town, county, postcode, student, volunteer');
$this->db->from('Users');
if (!is_null($id)) $this->db->where('id', $id);
$this->db->order_by('id', 'desc');
return $this->db->get()->result();
}
function add($data)
{
$this->db->insert('Users', $data);
return $this->db->insert_id();
}
function update($data, $id)
{
$this->db->where('id', $id);
$this->db->update('Users', $data);
return $this->db->affected_rows();
}
function delete($id)
{
$this->db->where('id', $id);
$this->db->delete('Users');
return $this->db->affected_rows();
}
function filterUsers()
{
return $this->db->get('Users')->result();
}
}
사람이 말해 주시겠습니까, 나는 그것을 고치 갈 수있는 방법 :
require_once BASEPATH."core/Model.php";
require_once APPPATH."models/Users_model.php";
class ExampleTest extends UnitTestCase
{
function ExampleTest()
{
parent::__construct('Example tests');
}
///// All functions starting with "test" will be tested /////
function testSimpleStuff()
{
$name = 'Andreas';
$online = TRUE;
$this->assertEqual($name, 'Andreas');
$this->assertTrue($online);
}
//There are already 8 members in the table
function testAdd()
{
$this->model->add("new member");
$this->assertEqual($this->model->get(9),'new member');
$this->assertNull($this->model->get(0));
$this->assertNull($this->model->get(10));
}
}
이
내가 전화하고있는 모델입니다. 미리 건배.
내가 CodeIgniter를 사용하고 있지 않다, 그러나 당신은 클래스 Users_Model의 객체를 생성 한? '$ this-> model'이 객체가 아닌 것 같습니다 ... – briosheje