PHPUnit 5.7.4子类中的存根基类方法不起作用。正在调用原始方法,而不是模拟。
当我试图嘲笑留着小胡子的孩子们的方法时PHPUnit 5.7.4子类中的存根基类方法不起作用。正在调用原始方法,而不是模拟。,php,unit-testing,symfony,phpunit,Php,Unit Testing,Symfony,Phpunit,当我试图嘲笑留着小胡子的孩子们的方法时 class baseClass { public function __construct() { } public function methodToBeMocked() { // do somthing } } class childClass extends baseClass { public function __construct() { p
class baseClass
{
public function __construct()
{
}
public function methodToBeMocked()
{
// do somthing
}
}
class childClass extends baseClass
{
public function __construct()
{
parent::__construct($doctrine, $securityContext);
}
public function methodUsingMethodToBeMocked()
{
// do somthing
$this->methodToBeMocked();
}
}
调用实际的基类方法,而不是调用模拟方法和返回值。需要调用模拟方法。请忽略childClass构造函数参数($doctrine,$securityContext)是
$this->getMockBuilder('\childClass')
类的完整命名空间?请忽略childClass构造函数参数($doctrine,$securityContext)是$this->getMockBuilder('\childClass'))
类的完整命名空间?
$this->mockChildClass = $this->getMockBuilder('\childClass')
->setMockClassName('Mock_Child_Class')
->setConstructorArgs(
[
// arguments
]
)
->setMethods(['methodToBeMocked'])
->getMock();
$this->mockChildClass
->expects($this->once())
->method('methodToBeMocked')
->will($this->returnValue(null));