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

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

      1. PHPUnit 中的模拟 - 具有不同参数的同一方法的多个配置

        时间:2023-10-31

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

                  <legend id='SLAz9'><style id='SLAz9'><dir id='SLAz9'><q id='SLAz9'></q></dir></style></legend>
                    <tbody id='SLAz9'></tbody>

                  <tfoot id='SLAz9'></tfoot>

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

                  <i id='SLAz9'><tr id='SLAz9'><dt id='SLAz9'><q id='SLAz9'><span id='SLAz9'><b id='SLAz9'><form id='SLAz9'><ins id='SLAz9'></ins><ul id='SLAz9'></ul><sub id='SLAz9'></sub></form><legend id='SLAz9'></legend><bdo id='SLAz9'><pre id='SLAz9'><center id='SLAz9'></center></pre></bdo></b><th id='SLAz9'></th></span></q></dt></tr></i><div id='SLAz9'><tfoot id='SLAz9'></tfoot><dl id='SLAz9'><fieldset id='SLAz9'></fieldset></dl></div>
                • 本文介绍了PHPUnit 中的模拟 - 具有不同参数的同一方法的多个配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可以这样配置PHPUnit mock吗?

                  Is it possible to configure PHPUnit mock in this way?

                  $context = $this->getMockBuilder('Context')
                     ->getMock();
                  
                  $context->expects($this->any())
                     ->method('offsetGet')
                     ->with('Matcher')
                     ->will($this->returnValue(new Matcher()));
                  
                  $context->expects($this->any())
                     ->method('offsetGet')
                     ->with('Logger')
                     ->will($this->returnValue(new Logger()));
                  

                  我使用 PHPUnit 3.5.10,当我请求 Matcher 时它失败了,因为它需要Logger"参数.就像第二个期望是重写第一个,但是当我转储模拟时,一切看起来都很好.

                  I use PHPUnit 3.5.10 and it fails when I ask for Matcher because it expects "Logger" argument. It is like the second expectation is rewriting the first one, but when I dump the mock, everything looks ok.

                  推荐答案

                  从 PHPUnit 3.6 开始,有 $this->returnValueMap() 可用于根据给定参数返回不同的值方法存根.

                  As of PHPUnit 3.6, there is $this->returnValueMap() which may be used to return different values depending on the given parameters to the method stub.

                  这篇关于PHPUnit 中的模拟 - 具有不同参数的同一方法的多个配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHPUnit 模拟私有方法 下一篇:如何让 PHPUnit MockObjects 根据参数返回不同的值?

                  相关文章

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

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

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

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

                    1. <tfoot id='uheYW'></tfoot>