我的其中一条路线中有以下代码:
return Response::download('cv.pdf');
知道如何测试这个吗?我试过使用 shouldReceive() 但这似乎不起作用('shouldReceive() 未定义函数......')。
我有一个Usersequelize模型,它有一个beforeCreate使用加密密码的钩子bcrypyt.Bcrypyt使用require语句由模型加载为依赖项.
现在,我正在为我的模型编写测试,我想编写一个测试,确保bcrypt在创建时散列密码.
目前,我已在User设置bcrypt对象的模型上添加了一个setter .在我的测试中,我可以创建一个间谍使用sinon并使用setter注入间谍并确保在创建时调用它.
这是正确的方法吗?我觉得好像我正在为我的测试创建一个二传手,并且它没有任何其他目的.
我的一条路线中有以下内容
$rules = array(
'name' => 'Required',
'subject' => 'Required',
'message' => 'Required',
'email' => 'Required|Email',
'recaptcha_response_field' => 'required|recaptcha'
);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()){
return Redirect::to('contact')->withInput()->withErrors($validator);
}else{
$data = array('name' => Input::get('name'),
'email' => Input::get('email'),
'text' => Input::get('message'),
'subject' => Input::get('subject'));
Queue::push('ContactQueue', $data);
return Redirect::to('contact')->with('success', 'Message sent successfully');
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为成功案例编写单元测试,我有以下内容:
public function testSuccess(){
Validator::shouldReceive('make')->once()->andReturn(Mockery::mock(['fails' => false]));
Queue::shouldReceive('push')->once();
$this->call('POST', '/contact');
$this->assertRedirectedTo('/contact');
}
Run Code Online (Sandbox Code Playgroud)
但是在尝试运行phpunit时我一直收到以下错误:
BadMethodCallException: Method Illuminate\Queue\QueueManager::connected() does not exist on this mock object
有任何想法吗?
laravel ×2
laravel-4 ×2
mockery ×2
unit-testing ×2
node.js ×1
phpunit ×1
sequelize.js ×1
sinon ×1
testing ×1