Session_regenerate_id () - headers already sent in Yii controller unit testing

I am trying to run a unit test of my controller (Yii framework).

/** 
   * @dataProvider provider
   */
  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

+5
2

. Yii ob_start(), , , . .

+2

$user->login :

$mockSession = $this->getMock('CHttpSession', array('regenerateID'));
Yii::app()->setComponent('session', $mockSession);

regenerateID , .

ob_start() bootstrap , PHPUnit, .

, .

Yii 1.1.7 1.1.10, regenerateID 1.1.8, .

+3

All Articles