简体   繁体   English

phpunit-使用依赖注入测试构造函数

[英]phpunit - Testing constructor with dependency injection

I need to test following constructor which has dependency injection using phpunit. 我需要测试以下使用phpunit进行依赖注入的构造函数。 For that do I have to use mocking ? 为此,我必须使用模拟吗? If so please give an example. 如果是这样,请举一个例子。

/**
 * Set graph object
 *
 * @param Graph $graphObj graph object
 */
public function __construct(Graph $graphObj)
{
    $this->graphObject = $graphObj;
}

Assuming phpunit: 假设phpunit:

$mockGraph = $this->getMockBuilder('Graph')
                  ->setMethods(array('update'))
                  ->getMock();
$testObject = new Object($mockGraph);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM