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

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

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

        PHPUnit - 创建 Mock 对象以充当属性的存根

        PHPUnit - creating Mock objects to act as stubs for properties(PHPUnit - 创建 Mock 对象以充当属性的存根)
          • <bdo id='hU61r'></bdo><ul id='hU61r'></ul>
              <legend id='hU61r'><style id='hU61r'><dir id='hU61r'><q id='hU61r'></q></dir></style></legend>

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

                <tbody id='hU61r'></tbody>

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

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

                1. 本文介绍了PHPUnit - 创建 Mock 对象以充当属性的存根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 PHPunit 中配置一个 Mock 对象以返回不同属性的值(使用 __get 函数访问)

                  I'm trying to configure a Mock object in PHPunit to return values for different properties (that are accessed using the __get function)

                  例子:

                  class OriginalObject {
                   public function __get($name){
                  switch($name)
                   case "ParameterA":
                    return "ValueA";
                   case "ParameterB":
                    return "ValueB";
                   }
                  }
                  

                  我正在尝试使用:

                  $mockObject = $this->getMock("OrigionalObject");
                  
                  $mockObject    ->expects($this->once())
                      ->method('__get')
                      ->with($this->equalTo('ParameterA'))
                      ->will($this->returnValue("ValueA"));
                  
                  $mockObject    ->expects($this->once())
                      ->method('__get')
                      ->with($this->equalTo('ParameterB'))
                      ->will($this->returnValue("ValueB"));
                  

                  但这非常失败:-(

                  推荐答案

                  我还没有尝试模拟 __get,但也许这会起作用:

                  I haven't tried mocking __get yet, but maybe this will work:

                  // getMock() is deprecated
                  // $mockObject = $this->getMock("OrigionalObject");
                  $mockObject = $this->createMock("OrigionalObject");
                  
                  $mockObject->expects($this->at(0))
                      ->method('__get')
                      ->with($this->equalTo('ParameterA'))
                      ->will($this->returnValue('ValueA'));
                  
                  $mockObject->expects($this->at(1))
                      ->method('__get')
                      ->with($this->equalTo('ParameterB'))
                      ->will($this->returnValue('ValueB'));
                  

                  我已经在测试中使用了 $this->at() 并且它有效(但不是最佳解决方案).我是从这个胎面得到的:

                  I've already used $this->at() in a test and it works (but isn't an optimal solution). I got it from this tread:

                  如何我可以让 PHPUnit MockObjects 根据参数返回不同的值吗?

                  这篇关于PHPUnit - 创建 Mock 对象以充当属性的存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)

                  <small id='0HIgL'></small><noframes id='0HIgL'>

                  <tfoot id='0HIgL'></tfoot>

                    <legend id='0HIgL'><style id='0HIgL'><dir id='0HIgL'><q id='0HIgL'></q></dir></style></legend>
                        <tbody id='0HIgL'></tbody>

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