【问题标题】:What is the difference between Codeception\Util\Stub::construct('SomeClass') and new SomeClass?Codeception\Util\Stub::construct('SomeClass') 和 new SomeClass 有什么区别?
【发布时间】:2016-08-26 05:59:17
【问题描述】:

有两种方法可以在 Codeception 中创建新的类编写单元测试。

use Codeception\Util\Stub as Stub;
$SomeClass = new SomeClass();
$SomeClass = Stub::construct('SomeClass');

有人能解释一下这两种方法有什么区别吗?

【问题讨论】:

    标签: php unit-testing codeception stub


    【解决方案1】:

    new SomeClass 创建该类的常规实例,
    Stub::construct('SomeClass') 创建该类的测试替身,并替换了一些方法或属性。

    http://codeception.com/docs/reference/Stub#construct 中所述

    属性和方法可以在第三个参数中设置。甚至可以设置受保护和私有属性。

    如果您不覆盖任何属性或方法,两者之间没有区别(也没有理由使用 Stub)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-27
      • 2021-10-01
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2018-08-02
      • 1970-01-01
      相关资源
      最近更新 更多