Jmrtech's avatar

Test not reaching controller method

I am writing a test for an update method on the controller. When I run phpunit the test never reaches the controller, it just redirects it. When I add ->dump() this is what I get:

<!DOCTYPE html>\n
<html>\n
    <head>\n
        <meta charset="UTF-8" />\n
        <meta http-equiv="refresh" content="1;url=http://ptr.dev" />\n
\n
        <title>Redirecting to http://ptr.dev</title>\n
    </head>\n
    <body>\n
        Redirecting to <a href="http://ptr.dev">http://ptr.dev</a>.\n
    </body>\n
</html>

Middleware is enabled as some of it is required to access app. If I trigger some of the middleware it will change the Redirect to part of the code above. Only problem is none of my middleware directs back to the address listed. Here is code in test:

public function test_client_is_updated()
    {
        Session::start();

        $plan = factory(App\Plan::class)->create();

        $hospital = factory(App\Hospital::class)->create([
            'hospitalPhone' => '3104445555',
            'mobilePhone' => '+15005550006',
            'plan_id' => $plan->id,
            'stripe_active' => 1
        ]);
        $user = factory(App\User::class)->create([
            'hospital_id' => $hospital->id,
        ]);

        $client = factory(App\Client::class)->create([
            'hospital_id' => $hospital->id
        ]);

        $url = 'hospital/' . $hospital->id . '/client/' . $client->id;

        $new_client_info = [
            '_token' => csrf_token(),
            'phone1' => '13105556699'
        ];
        
        $this->actingAs($user)
            ->patch($url, $new_client_info)
            ->dump()
            ->seeInDatabase('clients', ['id' => $client->id, 'phone1' => $new_client_info['phone1']]);
    }
0 likes
1 reply
Bloomanity's avatar
  1. Try put()
  2. Try to dd inside the Request object if you have a custom one
  3. dd inside the update method and see what you get for the $request object
  4. double check the route and it's parameters; use the route() helper and make sure it's the correct route.

Please or to participate in this conversation.