【发布时间】:2015-08-10 00:54:45
【问题描述】:
如果被存根的方法最初不存在于被存根的类中,有没有办法让 PHPUnit 抛出异常?
这是一个粗略的例子:
class User {
function getId() { ... }
}
class LoginTest extends PHPUnit_Framework_TestCase {
function testLogin() {
...
$userMock = $this->getMockBuilder('User')
->setMethods(['getID']) // getId is misspelled; error should occur
->getMock();
...
}
}
class Login {
function login($user) {
...
$id = $user->getID(); // tests will pass even though this is misspelled
...
}
}
【问题讨论】:
标签: php mocking phpunit stubbing