【发布时间】:2014-11-04 05:57:27
【问题描述】:
如何在不发送电子邮件的情况下测试这个 sn-p?
public function forgot()
{
$isValid = $this->updateForm->valid(Input::only('email'));
if ($isValid) {
$result = $this->user->forgot($this->updateForm->data());
if (isset($result['user']) && ($result['success'] > 0)) {
Event::fire('user.mail.forgot', array('data'=>$result['user']));
return Response::json(array('success'=>1),200);
}
$error = isset($result['error'])?array_pop($result):trans('user.generror');
return Response::json(array(
'success'=>0,
'errors' => array('error'=>array($error))),
200);
}
return Response::json(array(
'success' => 0,
'errors' => $this->updateForm->errors()),
200
);
}
现在我测试它:
public function _getSuccess($content)
{
$json = str_replace(")]}',\n", '', $content);
$native = json_decode($json);
return $native->success;
}
public function _set200($method, $uri, $parameters = array())
{
$this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
$response = $this->call($method, $uri, $parameters);
$this->assertResponseStatus(200);
return $response;
}
public function testUserForgot200Success()
{
$response = $this->_set200('POST', '/api/v1/users/forgot', array('email' => $this->userEmail));
$this->assertSame(1, $this->_getSuccess($response->getContent()));
}
但是这样我必须在测试文件夹中设置邮件配置文件,然后系统会发送一封电子邮件:(
【问题讨论】: