简体   繁体   English

消息为“ session_regenerate_id()的PHPUnit_Framework_Error_Warning:无法重新生成会话ID-标头已发送”

[英]'PHPUnit_Framework_Error_Warning' with message 'session_regenerate_id(): Cannot regenerate session id - headers already sent'

I ran into this problem writing controller tests for logging in. I found an answer for the Yii framework but I use Zend. 我在编写用于登录的控制器测试时遇到了这个问题。我找到了Yii框架的答案,但是我使用Zend。 The answer was to use ob_start() but it didn't work for me until I figured out where to put it. 答案是使用ob_start(),但是直到我弄清楚放置在哪里,它对我才起作用。 I ended up landing on having it at the top of my Bootstrap.php file. 我最终将其放置在Bootstrap.php文件的顶部。 If anyone else has figured out a better way of doing this please let me know 如果其他人想出了一种更好的方法,请告诉我

Please try to set: 请尝试设置:

Zend_Session::$_unitTestEnabled = true;

In your tests, could work. 在您的测试中,可以工作。

Another solution could be to redirect the PHPUnit output, so that it doesn't interrupt the html output. 另一个解决方案可能是重定向PHPUnit输出,以便它不会中断html输出。

phpunit --stderr controllerTest.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM