• <tfoot id='TgnEX'></tfoot>
    1. <small id='TgnEX'></small><noframes id='TgnEX'>

    2. <i id='TgnEX'><tr id='TgnEX'><dt id='TgnEX'><q id='TgnEX'><span id='TgnEX'><b id='TgnEX'><form id='TgnEX'><ins id='TgnEX'></ins><ul id='TgnEX'></ul><sub id='TgnEX'></sub></form><legend id='TgnEX'></legend><bdo id='TgnEX'><pre id='TgnEX'><center id='TgnEX'></center></pre></bdo></b><th id='TgnEX'></th></span></q></dt></tr></i><div id='TgnEX'><tfoot id='TgnEX'></tfoot><dl id='TgnEX'><fieldset id='TgnEX'></fieldset></dl></div>

    3. <legend id='TgnEX'><style id='TgnEX'><dir id='TgnEX'><q id='TgnEX'></q></dir></style></legend>

        • <bdo id='TgnEX'></bdo><ul id='TgnEX'></ul>

        PHPUnit 输出导致 Zend_Session 异常

        时间:2023-10-03

          <tfoot id='lpI9A'></tfoot>
          <i id='lpI9A'><tr id='lpI9A'><dt id='lpI9A'><q id='lpI9A'><span id='lpI9A'><b id='lpI9A'><form id='lpI9A'><ins id='lpI9A'></ins><ul id='lpI9A'></ul><sub id='lpI9A'></sub></form><legend id='lpI9A'></legend><bdo id='lpI9A'><pre id='lpI9A'><center id='lpI9A'></center></pre></bdo></b><th id='lpI9A'></th></span></q></dt></tr></i><div id='lpI9A'><tfoot id='lpI9A'></tfoot><dl id='lpI9A'><fieldset id='lpI9A'></fieldset></dl></div>

              • <bdo id='lpI9A'></bdo><ul id='lpI9A'></ul>

                <small id='lpI9A'></small><noframes id='lpI9A'>

              • <legend id='lpI9A'><style id='lpI9A'><dir id='lpI9A'><q id='lpI9A'></q></dir></style></legend>
                    <tbody id='lpI9A'></tbody>
                • 本文介绍了PHPUnit 输出导致 Zend_Session 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我收到了许多与此完全相同的错误:

                  Zend_Session_Exception:会话必须在任何输出发送到浏览器之前启动;输出开始于/usr/local/zend/share/pear/PHPUnit/Util/Printer.php/173

                  运行我的应用程序的测试套件时.这是 PHPUnit 3.5.10 和 PHP 5.3.5.

                  没有神秘的、意外的空白输出导致这种情况.我已经确定发送到浏览器的输出"是正在执行的 PHPUnit 测试的实际输出.如果我打开 PHPUnit/Util/Printer.php 并将 print $buffer 行与 if (strpos($buffer, 'PHPUnit 3.5.10 by Sebastian Bergmann') === false)(有效停止PHPUnit的第一行输出),然后我的第一个测试成功(直到测试用例输出一个点表示测试成功,然后下一个测试失败,因为输出了点).>

                  我团队中的另一位开发人员能够成功运行完整的测试套件,所以我知道这不是应用程序代码的问题.一定是我本地环境的一些配置设置或问题.

                  我已经检查了 php.ini 以验证 output_buffering 已打开并且 implicit_flush 已关闭,它们确实如此.

                  我还尝试将 Zend_Session::$_unitTestEnabled = true; 添加到我的测试引导程序中,但这并没有帮助(无论如何应该没有必要,因为它可以在另一个开发人员的机器上运行在我们的 CI 服务器上没有它).

                  除了忽略错误之外还有什么建议吗?我从来没有见过这样的事情,真的很茫然.

                  谢谢!

                  更新:

                  为了进一步隔离问题,我通过执行以下测试脚本将 ZF 和我的应用程序排除在外:

                  assertTrue(true);}}

                  测试失败:

                  1) SessionTest::testSessionsession_start():无法发送会话 cookie - 头已经发送(输出开始于/home/mmsa/test.php:1)

                  然而,完全相同的测试适用于朋友的机器.相同版本的 PHP 和 PHPUnit.

                  解决方案

                  使用 -stderr 标志运行 phpunit,(新版本可能使用 --stderr 代替)例如

                   phpunit -stderr mytest.php# 或者phpunit --stderr mytest.php

                  这会将 phpunit 的输出定向到 stderr,防止它中断 HTTP 标头生成.

                  该测试可能适用于您朋友的机器,因为他启用了输出缓冲(尽管我不确定这在 CLI 上下文中是否相关).

                  I am getting numerous errors exactly like this one:

                  Zend_Session_Exception: Session must be started before any output has been sent to the browser; output started in /usr/local/zend/share/pear/PHPUnit/Util/Printer.php/173
                  

                  When running my application's test suite. This is with PHPUnit 3.5.10 and PHP 5.3.5.

                  There is no mysterious, unexpected whitespace output that is causing this. I've determined that the "output being sent to the browser" is the actual output from the PHPUnit tests being executed. If I open up PHPUnit/Util/Printer.php and wrap the print $buffer line with if (strpos($buffer, 'PHPUnit 3.5.10 by Sebastian Bergmann') === false) (effectively stopping the first line of output from PHPUnit), then my first test succeeds (until the test case outputs a dot indicating that the test succeeded, then the next test fails because the dot was output).

                  Another developer on my team is able to run the full test suite successfully, so I know it's not a problem with the application code. It must be some configuration setting or problem with my local environment.

                  I've already checked php.ini to verify that output_buffering is turned on and implicit_flush is turned off, and they are.

                  I've also tried adding Zend_Session::$_unitTestEnabled = true; to my test bootstrap, but that didn't help (and shouldn't be necessary anyway because it works on another developer's machine and on our CI server without it).

                  Any suggestions besides ignoring the errors? I've never seen anything like this and am truly at a loss.

                  Thanks!

                  UPDATE:

                  To attempt to further isolate the problem, I took ZF and my application out of the equation by executing the following test script:

                  <?php
                  
                  class SessionTest extends PHPUnit_Framework_TestCase
                  {
                      public function testSession()
                      {
                          session_start();
                          $this->assertTrue(true);
                      }
                  }
                  

                  The test fails:

                  1) SessionTest::testSession
                  session_start(): Cannot send session cookie - headers already sent by (output started at /home/mmsa/test.php:1)
                  

                  However, the exact same test works on a friend's machine. Same version of PHP and PHPUnit.

                  解决方案

                  Run phpunit with the -stderr flag, (newer versions may use --stderr instead) e.g.

                   phpunit -stderr mytest.php
                   # or
                   phpunit --stderr mytest.php
                  

                  This directs phpunit's output to stderr, preventing it from interrupting HTTP header generation.

                  It's possible that the test works on your friend's machine because he has output buffering enabled (although I'm not sure if that's relevant in a CLI context).

                  这篇关于PHPUnit 输出导致 Zend_Session 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Zend Framework中如何实现服务层? 下一篇:使用 Zend 框架的原始 SQL 查询

                  相关文章

                  最新文章

                  <i id='UtYYu'><tr id='UtYYu'><dt id='UtYYu'><q id='UtYYu'><span id='UtYYu'><b id='UtYYu'><form id='UtYYu'><ins id='UtYYu'></ins><ul id='UtYYu'></ul><sub id='UtYYu'></sub></form><legend id='UtYYu'></legend><bdo id='UtYYu'><pre id='UtYYu'><center id='UtYYu'></center></pre></bdo></b><th id='UtYYu'></th></span></q></dt></tr></i><div id='UtYYu'><tfoot id='UtYYu'></tfoot><dl id='UtYYu'><fieldset id='UtYYu'></fieldset></dl></div>
                  <tfoot id='UtYYu'></tfoot>
                • <legend id='UtYYu'><style id='UtYYu'><dir id='UtYYu'><q id='UtYYu'></q></dir></style></legend>
                • <small id='UtYYu'></small><noframes id='UtYYu'>

                    <bdo id='UtYYu'></bdo><ul id='UtYYu'></ul>