A
A
Alexander2018-12-17 14:33:18
Laravel
Alexander, 2018-12-17 14:33:18

How to call a controller method with parameters in Laravel unit tests?

Friends, hello everyone.
Can you please tell me how to call a controller method with parameters from tests?
Let's say here is an example of a controller with a method to be called for a test:

class PostController
{
    public function attach($id) {
        dd($id);
    }
}

Here is the test method:
public function testAccountAttach()
{
    $response = $this->call('GET', route('accountattach'), [
        'id' => 1
    ]);
}

It doesn't work that way.
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kovalchuk, 2018-12-17
@up_sweep

public function testAccountAttach()
    {
        $response = $this->call('GET', route('accountattach',[
                'id' => 1
         ]));
}

https://laravel.com/docs/5.7/routing#named-routes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question