Laravel-Testing-Decoded icon indicating copy to clipboard operation
Laravel-Testing-Decoded copied to clipboard

Input::replace not working with $this->call

Open simplenotezy opened this issue 10 years ago • 0 comments

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?

simplenotezy avatar Dec 17 '14 22:12 simplenotezy