HardDrive's avatar

Struggling to find error in test

Hi I am getting an error 500 on a test I am running and am struggling to find what I have dome wrong. Below is my test and controller method and route :)

 /** @test */
    public function authenticated_users_can_update_existing_customer()
    {
        $this->withExceptionHandling();

        $customer = factory('App\Customer')->create();

        $data = [
        'company' => 'Acme Ltd',
        'first_name' => 'Ross',
        ];

        $this->actingAs($this->user)
        ->patchJson(route('customer.update', $customer->id),$data)
            ->assertStatus(202);

        $customer = $customer->fresh();

         $this->assertEquals('Acme Ltd', $customer->company);
    }

And my Controller Method and route

public function update(Customer $customer,Request $request)
    {
         //$this->validator(request()->all())->validate();

        $customer->update($data);

        return request()->wantsJson()
            ? response()->json($customer, 202)
            : null;
    }
// Resource Routes
    Route::resource('customer', 'CustomerController')->middleware('auth');

Thanks for any help in advance :)

0 likes
5 replies
MikeMacDowell's avatar
Level 25

@RossUK where's the $data variable coming from in your Controller Method?

I'd guess that's what causing the issue

$customer->update($data);
1 like
HardDrive's avatar

Hi, thanks for this I have been looking at it too long. I'm still/always learning. Is there any way to spit out the error during the test? I get the assertion errors but not why the error 500 is thrown. I'm just curious the correct way of debugging

Thanks

xkrupa12's avatar

Take a look at storage/logs/laravel.log - all 500s are usually logged there

1 like

Please or to participate in this conversation.