【发布时间】:2011-10-06 09:36:48
【问题描述】:
我想测试一个调用同名父方法的类方法。有没有办法做到这一点?
class Parent {
function foo() {
echo 'bar';
}
}
class Child {
function foo() {
$foo = parent::foo();
return $foo;
}
}
class ChildTest extend PHPUnit_TestCase {
function testFoo() {
$mock = $this->getMock('Child', array('foo'));
//how do i mock parent methods and simulate responses?
}
}
【问题讨论】:
-
@james,在这种情况下,unit 是什么?
-
这是不可能的,因为您需要在
Parent和Child之间插入一个模拟子类。 -
我想我可以通过将调用父方法包装在其他一些可模拟的方法中来修改子类。
标签: php testing mocking phpunit