我正在尝试为 PHPUnit 创建一个测试,但是 - 在我们正在测试的类中,有一种情况是传递的对象被检查为NULL
.
我已经像这样创建了对象(实际上是一个接口):
class SomeTestClass extends PHPUnit_Framework_Testcase {
protected $storage;
public function setUp() {
$this->storage = $this->getMockBuilder('Some\Namespace\TestedInterface')->getMock();
}
public function testStorage() {
/* here is where I need to pass over $this->storage to testFunc() and assert it is null */
$testingClass = new TestingClass();
$testingClass->testFunc( $this->storage );
}
}
所以 - 我需要做的是创建一个模拟接口的对象,它的“返回”值是null
在testFunc()
函数中检查它的时候。
我怎么做?我们的TestingClass
类需要一个实现接口的对象。
谢谢。