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

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

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

        <tfoot id='DuL6c'></tfoot>

        PHPUnit:如何使用多个参数模拟多个方法调用?

        PHPUnit: how do I mock multiple method calls with multiple arguments?(PHPUnit:如何使用多个参数模拟多个方法调用?)
        <legend id='ETj0A'><style id='ETj0A'><dir id='ETj0A'><q id='ETj0A'></q></dir></style></legend>
          <tfoot id='ETj0A'></tfoot>
              <tbody id='ETj0A'></tbody>

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

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

                  本文介绍了PHPUnit:如何使用多个参数模拟多个方法调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为使用 PHPUnit 的方法编写单元测试.我正在测试的方法在同一个对象上调用相同的方法 3 次,但使用不同的参数集.我的问题类似于提出的问题 这里和这里

                  I am writing a unit test for a method using PHPUnit. The method I am testing makes a call to the same method on the same object 3 times but with different sets of arguments. My question is similar to the questions asked here and here

                  其他帖子中提出的问题与只接受一个参数的模拟方法有关.

                  The questions asked in the other posts have to do with mocking methods that only take one argument.

                  但是,我的方法需要多个参数,我需要这样的东西:

                  However, my method takes multiple arguments and I need something like this:

                  $mock->expects($this->exactly(3))
                  ->method('MyMockedMethod')
                      ->with(
                          $this->logicalOr(
                              $this->equalTo($arg1, $arg2, arg3....argNb),
                              $this->equalTo($arg1b, $arg2b, arg3b....argNb),
                              $this->equalTo($arg1c, $arg2c, arg3c....argNc)
                          )
                      );
                  

                  此代码不起作用,因为 equalTo() 仅验证一个参数.给它多个参数会引发异常:

                  This code doesn't work because equalTo() validates only one argument. Giving it more than one argument throws an exception:

                  PHPUnit_Framework_Constraint_IsEqual::__construct() 的参数 #2 必须是数字

                  Argument #2 of PHPUnit_Framework_Constraint_IsEqual::__construct() must be a numeric

                  有没有办法为具有多个参数的方法进行 logicalOr 模拟?

                  Is there a way to do a logicalOr mocking for a method with more than one argument?

                  提前致谢.

                  推荐答案

                  在我的例子中,答案很简单:

                  In my case the answer turned out to be quite simple:

                  $this->expects($this->at(0))
                      ->method('write')
                      ->with(/* first set of params */);
                  
                  $this->expects($this->at(1))
                      ->method('write')
                      ->with(/* second set of params */);
                  

                  关键是使用$this->at(n),其中n是方法的第N次调用.我尝试过的任何 logicalOr() 变体都无法执行任何操作.

                  The key is to use $this->at(n), with n being the Nth call of the method. I couldn't do anything with any of the logicalOr() variants I tried.

                  这篇关于PHPUnit:如何使用多个参数模拟多个方法调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <legend id='oM03m'><style id='oM03m'><dir id='oM03m'><q id='oM03m'></q></dir></style></legend>
                1. <i id='oM03m'><tr id='oM03m'><dt id='oM03m'><q id='oM03m'><span id='oM03m'><b id='oM03m'><form id='oM03m'><ins id='oM03m'></ins><ul id='oM03m'></ul><sub id='oM03m'></sub></form><legend id='oM03m'></legend><bdo id='oM03m'><pre id='oM03m'><center id='oM03m'></center></pre></bdo></b><th id='oM03m'></th></span></q></dt></tr></i><div id='oM03m'><tfoot id='oM03m'></tfoot><dl id='oM03m'><fieldset id='oM03m'></fieldset></dl></div>

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

                      <tfoot id='oM03m'></tfoot>
                            <bdo id='oM03m'></bdo><ul id='oM03m'></ul>
                              <tbody id='oM03m'></tbody>