1

I am creating HTTP tests for an existing laravel application as described in the docs. The tests look something like this:

public function testSomething() 
{
    $this->get('/something')->assertOk();
}

The app has some endpoints that use the HTTP SEARCH method, declared like this:

Route::addRoute('SEARCH', '', 'SomeController@index');

However, the test class doesn't have a search('/something') method.

Is there any way to test a route with custom HTTP methods?

1 Answer 1

2

Laravel implement shortcut method for the most used http verb but not all. So if you look closer at the $this->get('...') it's implemented like that:
In \Illuminate\Foundation\Testing\Concerns\MakesHttpRequests

     public function get($uri, array $headers = [])
        {
            $server = $this->transformHeadersToServerVars($headers);
            $cookies = $this->prepareCookiesForRequest();
    
            return $this->call('GET', $uri, [], $cookies, [], $server);
        }

So for your use case, you can call

$this->call('SEARCH', '/something', [], $cookies, [], $server)->assertOk();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.