Welcome Guest, Not a member yet? Register   Sign In
phpunit testing routes only available after login
#1

(This post was last modified: 08-05-2023, 02:49 PM by dgvirtual. Edit Reason: update )

I need to create unit tests for controllers / routes that are only accessible for logged in users. I am using IonAuth.
PHP Code:
public function testValidateField()
{
    $route route_to('invoice_validate_field''name');
    $getArray = ['name' => 'Name Surname'];
    $result $this->call('get'$route$getArray);
    $this->assertTrue($result->isOK());
    $result->assertRedirectTo('login');

This works, but, as you can see, I can only check if the route gets redirected, because the route is only available for logged in users.

I am using IonAuth for authentication. The login check is performed by a filter.

How do I imitate logged in user in this case? How do I log in?

I see Shield has AuthenticationTesting trait for that. But how do I deal with IonAuth here? Maybe @benedmunds could suggest something?
==

Donatas G.
Reply


Messages In This Thread
phpunit testing routes only available after login - by dgvirtual - 08-05-2023, 02:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB