Laravel-Testing-Decoded
Laravel-Testing-Decoded copied to clipboard
Input::replace not working with $this->call
In chapter 10 under "Redirections" you post the following example:
public function testStore() {
Input::replace($input = ['title' => 'My Title']);
$this->mock
->shouldReceive('create')
->once()
->with($input);
$this->app->instance('Post', $this->mock);
$this->call('POST', 'posts');
$this->assertRedirectedToRoute('posts.index');
}
However, that will not pass the "input" (defined in line 1 in the method) to the controller. Instead, the input parameter should be added to the $this->call method, like so:
public function testStore() {
$input = ['title' => 'My Title'];
$this->mock
->shouldReceive('create')
->once()
->with($input);
$this->app->instance('Post', $this->mock);
$this->call('POST', 'posts', $input);
$this->assertRedirectedToRoute('posts.index');
}
And then in the controller (which is not described either in the book):
public function store()
{
$this->post->create(Input::all());
// some redirect here...
}
Am I getting something wrong here?