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

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

  1. <tfoot id='nKWxI'></tfoot>
      <bdo id='nKWxI'></bdo><ul id='nKWxI'></ul>

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

      是否可以在 PhpUnit 的测试用例之外创建一个模拟?

      Is it possible to create a mock outside a test case in PhpUnit?(是否可以在 PhpUnit 的测试用例之外创建一个模拟?)

        • <small id='8v7uv'></small><noframes id='8v7uv'>

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

            • <bdo id='8v7uv'></bdo><ul id='8v7uv'></ul>
            • <legend id='8v7uv'><style id='8v7uv'><dir id='8v7uv'><q id='8v7uv'></q></dir></style></legend>
            • <tfoot id='8v7uv'></tfoot>

                  <tbody id='8v7uv'></tbody>

                本文介绍了是否可以在 PhpUnit 的测试用例之外创建一个模拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这可能看起来很愚蠢,但我希望不会,但我想创建一个服务,为使用我的项目的人返回模拟对象,以便他们可以模拟我项目中的所有类并测试他们的代码.

                It may seem silly, hope not, but I want to create a service that will return mock objects for people that uses my project so they can mock all the classes from my project and test their code.

                我的想法是提供这种服务,以便可以在其他项目的测试用例中调用它并为每个测试获取适当的模拟.

                My idea was to offer this kind of service so it can be called inside other project's test cases and obtain the appropriate mock for each test.

                这可能吗?或者还有其他方法可以做到这一点.顺便说一句,由于项目的限制,我不能使用任何模拟库.

                Is that possible? Or there are other ways to do that. Btw, I can't use any mocking library because of project's limitations.

                推荐答案

                是的,有可能.getMock 方法在底层使用 PHPUnit_Framework_MockObject_Generator 类.所以可以直接使用:

                Yes, it is possible. Under the hood the getMock method uses the PHPUnit_Framework_MockObject_Generator class. So you can use it directly:

                PHPUnit_Framework_MockObject_Generator::getMock($originalClassName, $methods)
                

                但是你会失去所有期望的快捷方式,比如 $this->once().您必须自己实例化期望:

                But you will lose all the expectation shortcuts like $this->once(). You will have to instantiate the expectations on your own:

                $mock->expects(PHPUnit_Framework_TestCase::once())

                查看PHPUnit源代码看看模拟是如何构建的

                Look at the PHPUnit source code to see how the mocks are build

                这篇关于是否可以在 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 的问题)

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

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