3

I have the following in one of my routes

$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');
}

I am trying to write a unit test for the success scenario, I have the following:

public function testSuccess(){
    Validator::shouldReceive('make')->once()->andReturn(Mockery::mock(['fails' => false]));

    Queue::shouldReceive('push')->once();

    $this->call('POST', '/contact');

    $this->assertRedirectedTo('/contact');
}

But I keep receiving the following error when trying to run phpunit:

BadMethodCallException: Method Illuminate\Queue\QueueManager::connected() does not exist on this mock object

Any ideas?

4

1 回答 1

5

放置Queue::shouldReceive('connected')->once();Queue::shouldReceive('push')->once(); 解决了这个问题。

于 2014-01-14T20:50:02.833 回答