Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown named parameter $method #6

Open
chris-ware opened this issue Jul 19, 2024 · 5 comments
Open

Unknown named parameter $method #6

chris-ware opened this issue Jul 19, 2024 · 5 comments
Assignees

Comments

@chris-ware
Copy link

When trying to run this on authenticated routes in my application, I get the following:

Tests\Unit\PageTest > auth routes with ('GET', 'profile/password')                                                                                                                                                                                                                                      Error   
  Unknown named parameter $method

I've tried debugging this and I can seem to figure out why. Non-authenticated routes work fine.

I was hoping to use this as a replacement for my own code which also works perfectly fine, where with is an array of route name:

test('every basic page loads', function (string $route) {
    actingAs(\App\Domain\Auth\Models\User::factory()->create()->assignRole('Administrator'))
        ->get(route($route, absolute: false))
        ->assertOk();
})->with([]);

This is exactly the tests I have currently, the first one as stated working perfectly, the other one not so:

routeTesting('guest routes')
    ->ignoreRoutesWithMissingBindings()
    ->include('login')
    ->assertOk();

routeTesting('auth routes')
    ->setUp(function () {
        actingAs(\App\Domain\Auth\Models\User::factory()->create()->assignRole('Administrator'));
    })
    ->ignoreRoutesWithMissingBindings()
    ->exclude('login*', 'api*', '_*', 'log-viewer*', 'clockwork*', 'admin*', 'filament*', 'livewire*')
    ->assertOk();
@newtovaux
Copy link

newtovaux commented Jul 25, 2024

I'm having the same issue with

FAILED  Tests\Feature\RoutesTest > all routes with ('GET', '/')      Error   
  Unknown named parameter $method

Again with authenticated routes, I use a setUp() function to do the login, and it still doesn't work.

routeTesting('all routes')
    ->setUp(function ()
    {
        // Create user & login
        $this->user = User::factory()->create('password' => Hash::make('password')]);
        $response = $this->post('/login', [
            'email' => $this->user->email,
            'password' => 'password',
        ]);
    })
    ->assertSuccessful();

@pb30
Copy link
Contributor

pb30 commented Aug 3, 2024

It seems that having any ->setUp call causes this error

@pb30
Copy link
Contributor

pb30 commented Aug 5, 2024

This seems to be a workaround:

describe('routes work', function () {
    beforeEach(function () {
        $this->actingAs(User::factory()->create());
    });

    routeTesting('routes work')
        ->assertSuccessful();
});

@txdFabio
Copy link

txdFabio commented Oct 7, 2024

I'm having the same problem, either using ->setUp or the beforeEach() solution...

@Jaspur
Copy link

Jaspur commented Oct 9, 2024

Same issue (also with the workaround). All Sanctum routes: $this->actingAs(User::factory()->create(), 'sanctum');

Image

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

No branches or pull requests

6 participants