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

  1. <small id='JM8w5'></small><noframes id='JM8w5'>

  2. <legend id='JM8w5'><style id='JM8w5'><dir id='JM8w5'><q id='JM8w5'></q></dir></style></legend>

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

      使用 PHPUnit 和 Zend 框架测试异常的问题

      时间:2023-05-30
      <i id='Nqva9'><tr id='Nqva9'><dt id='Nqva9'><q id='Nqva9'><span id='Nqva9'><b id='Nqva9'><form id='Nqva9'><ins id='Nqva9'></ins><ul id='Nqva9'></ul><sub id='Nqva9'></sub></form><legend id='Nqva9'></legend><bdo id='Nqva9'><pre id='Nqva9'><center id='Nqva9'></center></pre></bdo></b><th id='Nqva9'></th></span></q></dt></tr></i><div id='Nqva9'><tfoot id='Nqva9'></tfoot><dl id='Nqva9'><fieldset id='Nqva9'></fieldset></dl></div>
    1. <tfoot id='Nqva9'></tfoot>
        <bdo id='Nqva9'></bdo><ul id='Nqva9'></ul>

                <tbody id='Nqva9'></tbody>

              • <small id='Nqva9'></small><noframes id='Nqva9'>

                <legend id='Nqva9'><style id='Nqva9'><dir id='Nqva9'><q id='Nqva9'></q></dir></style></legend>
              • 本文介绍了使用 PHPUnit 和 Zend 框架测试异常的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当用户在没有正确的 post 参数的情况下访问/user/validate 时,我的 Zend 应用程序会抛出一个 zend 异常.(我收到标准的发生错误"消息,在我的布局中框起来了).这是故意的.

                When a user accesses /user/validate without the correct post parameters, my Zend application throws a zend exception. (I get the standard "An Error Occurred" message, framed within my layout). This is intentional.

                我现在正在尝试使用 PHPUnit 测试该行为.这是我的测试:

                I am now trying to test that behaviour with PHPUnit. Here's my test:

                /**
                 * @expectedException Zend_Exception
                 */
                public function testEmptyUserValidationParametersCauseException() {
                    $this->dispatch('/user/validate');
                }
                

                当我运行测试时,我收到一条消息,说它失败了,预期异常 Zend_Exception".有什么想法吗?

                When I run the test I get a message saying it failed, "Expected exception Zend_Exception". Any ideas?

                我在文件中有其他测试工作正常...

                I have other tests in the file which are working just fine...

                谢谢!

                推荐答案

                Zend_Controller_Plugin_ErrorHandler 插件为您处理异常,默认的 Error_Controller 强制执行 500 重定向,这可能意味着您正在测试的异常不再存在.尝试以下单元测试,看看它是否通过:

                The Zend_Controller_Plugin_ErrorHandler plugin handles exceptions for you and the default Error_Controller forces a 500 redirect which may mean the exception you are testing for no longer exists. Try the following unit test and see if it passes:

                public function testUnknownUserRedirectsToErrorPage()
                {
                    $this->dispatch('/user/validate');
                    $this->assertController('error');
                    $this->assertAction('error');
                    $this->assertResponseCode('500');
                }
                

                如果这有效,则表明当您呈现错误视图时,异常将不再存在,因为它包含在重定向之前的代码中.

                If this works then it shows that by the time you are rendering the error view the exception will no longer exist as it is contained in the code before the redirect.

                这篇关于使用 PHPUnit 和 Zend 框架测试异常的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Magento Capture 方法不起作用 下一篇:文件名 feed1.xls 在 php 中不可读

                相关文章

                <legend id='LK4kk'><style id='LK4kk'><dir id='LK4kk'><q id='LK4kk'></q></dir></style></legend>

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

              • <small id='LK4kk'></small><noframes id='LK4kk'>

              • <tfoot id='LK4kk'></tfoot>