【发布时间】:2017-10-20 02:45:42
【问题描述】:
我有这门课
<?php
class Password
{
protected function checkPassword()
{
$this->callExit();
}
protected function callExit()
{
exit;
}
}
这是我的测试:
public function testAuthorizeExitsWhenPasswordNotSet()
{
$badCode = $this->getMockBuilder(Password::class)
->setMethods(array('callExit'))
->getMock();
$badCode->expects($this->once())
->method('callExit');
$badCode->checkPassword();
}
在早期的类中,callExit 方法属于 Password 类。
我的问题是,我可以测试不属于 Password 类的方法吗?
例如在checkPassword方法中:
protected function checkPassword()
{
$user = new User;
$this->callExit();
$user->fillOut();
}
我想为fillOut 方法做一个模拟,我该怎么做?
帮帮我!!
【问题讨论】:
-
创建 mocker 用户类并使用该 mock 对象调用 fillout()
-
我想检查
fillOut方法是否在checkPassword方法@zod内部被调用
标签: php unit-testing testing mocking phpunit