I am trying to run a unit test of my controller (Yii framework).
public function testActionEdit_view_login($controller){
$user = new CWebUser;
$user->id = 978;
$identity = new UserIdentity('me@test.com', '123456');
$user->login($identity);
$controller->actionEdit();
$output = ob_get_contents();
assertContains('Add/Change Profile Picture:', $output);
assertContains('bio', $output);
assertContains('specialties', $output);
assertContains('change login', $output);
assertContains('New Password', $output);
}
When i do
$user->login($identity);
to log in, I get the following error:
session_regenerate_id(): Cannot regenerate session id - headers already sent
I already tried output buffering by putting it at the beginning of the class:
public static function setUpBeforeClass(){
ob_start();
}
I also add ob_clean () to setUp () and ob_end_clean () to tearDownAfterClass ().
However, I am getting a message that the headers have already been sent. There are no spaces or new lines in the file, when I comment on a specific testing method, it works fine. Login failed ().
Has anyone got any ideas on how to prevent this, or perhaps test the controller differently?
Thank you CMO