【发布时间】:2016-08-10 03:52:05
【问题描述】:
这是我等待 phpunit 测试的函数:
<?php
class Dog
{
public function born()
{
$a = new Action();
$rs = $a->talk();
return $rs;
}
}
类 Action 是:
class Action
{
public function talk()
{
return "true";
}
}
测试函数是:
public function testStub()
{
$stub = $this->getMockBuilder('Action')
->getMock();
$stub->method('talk')
->willReturn('false');
var_dump($stub->talk()); // "false"
$dog = new Dog();
//[How can the born method invoke the stub method ?]
var_dump($dog->born()); // "true" [I think it should be "false",but it isn't]
}
现在,如何使用存根类来替换 Action 类?
感谢您的帮助。
【问题讨论】: