I have several unit tests for my controllers, and all throw an error with PHPUnit (v3.5.14) whenever they include a call to Yii::app()->user->login($identity);
I have searched through my code, and don’t see any extraneous whitespace or echo/print statements, so I’m not sure what’s causing the problem. If I comment out the login() call, everything works fine.
"headers already sent" means that you have echoed before starting session or before setting header param. So be carefull echoing(or print) that where are you doing it.
Yes, thanks, I’m quite familiar with the error, as I’ve developed PHP for over a decade. What I can’t figure out is what is causing the error. As far as I know I have no trailing whitespace (or closing PHP tags, for that matter) in my files, and I’m not performing any echo/print statements with logging users in, so I don’t know why the login() action would be breaking (when it tries to store a cookie).
I ended up with the same problem, and found it was I because I had (in error) deleted a ?> at the end of a one of my PHP file. In this case at the end of the root index.php file.
Added it, problem solved…
So for me, it wasn’t an erroneous character, it was the lack of ones needed. Tough to debug!
I think this turns out to be an issue with PHPUnit because of how it writes out test information. Any headers written during testing will cause this error. I solved this by simply testing for the presence of this error since it meant a successful login: