<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 的测试用例之外创建一个模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)

                <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>