4
我想模拟一个接口的validate
方法,并让所有其他接口方法存根返回null(我并不在乎他们会发生什么),但似乎没有办法很容易地做到这一点。如何模拟接口的一种方法?
这是我有:
$validator = $this
->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')
->setMethods(array('validate'))
->getMock();
$validator
->expects($this->once())
->method('validate')
->willReturn(array());
$validator->validate();
运行这给了我一个致命错误:
Class Mock_ValidatorInterface_56c4c003 contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods
所以 - 我需要以某种方式告诉PHPUnit的存根,接口要求的其他方法。什么是正确的方法来做到这一点?