Skip to content

[13.x] Add callRoute() to MakesHttpRequests trait#60647

Draft
shaedrich wants to merge 15 commits into
laravel:13.xfrom
shaedrich:test-call-route
Draft

[13.x] Add callRoute() to MakesHttpRequests trait#60647
shaedrich wants to merge 15 commits into
laravel:13.xfrom
shaedrich:test-call-route

Conversation

@shaedrich

@shaedrich shaedrich commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

Currently, when you have a route like this:

Route::get('users', [UserController::class, 'all'])->name('users.all');
Route::delete('users', [UserController::class, 'delete'])->name('users.delete');

And you write a HTTP test for your functionality behind this, you can easily mess this up like this:

public function testUsersAll()
{
    // ✓ valid, but should be either GET + users.all or DELETE + users.delete
	$this->get(route('users.delete'));
}

callRoute() links calling routes in tests with retrieving routes so that they can be validated:

public function testUsersAll()
{
    // ✓ valid, but should be either GET + users.all or DELETE + users.delete
	$this->callRoute('users.delete', method: 'GET'); // × Throws
}

Future scope (intentionally left out)

  • Dedicated methods (make the method validation more useful)
    • callGetRoute(), callPostRoute(), callPutRoute(), callPatchRoute(), callDeleteRoute(), callOptionsRoute()
    • callJsonRoute(), callJsonGetRoute(), callJsonPostRoute(), callJsonPutRoute(), callJsonPatchRoute(), callJsonDeleteRoute(), callJsonOptionsRoute()
  • Parameter validation

@shaedrich shaedrich marked this pull request as draft July 2, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant