I am very new to php and phpunit test cases. I am trying to write a testcase to save the values into database using $_POST in test case. When I execute the test case, POST is returning null values. Please help how to use $_POST variable in php unit testing.
TEST CLASS-
public function setUp() {
$this->resetInstance();
$this->CI->load->model('save_data_model');
$this->obj = $this->CI->save_data_model;
}
public function test_SaveData()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = array('value1'=>'10','value2'=>'100');
$actual = $this->obj->SaveData('1');
$this->assertNotNull($actual);
}
}
MODEL -
public function SaveData($id)
{
$sql['value1'] = $_POST['js_data']['input_value1'];
$sql['value2'] = $_POST['js_data']['input_value1'];
$sql['id'] = $id;
if(!empty($id))
{
$this->db->where('id',$id);
if($this->db->update('table_name',$sql))
{
return 'Updated';
}
else
{
return 'Not Updated';
}
}
}
Severity: NoticeMessage: Undefined index: js_dataFilename in SaveData.php
Database error: A Database Error Occurred
NULL VALUE FOR value1
UPDATE `table_name` SET `value1` = NULL, `value2` = NULL
WHERE `id` = '1'