inertia-laravel-testing icon indicating copy to clipboard operation
inertia-laravel-testing copied to clipboard

BadMethodCallException: Method Illuminate\Http\Response::assertInertia does not exist.

Open goldcoders opened this issue 4 years ago • 5 comments

dont know if this is the right thread to post this, but im getting this on a fresh install laravel

BadMethodCallException: Method Illuminate\Http\Response::assertInertia does not exist.

i tried both vscode phpunit and better php unit.

and they both squawk the same error.

but if im using the native cli command

.\vendor\bin\phpunit --filter test_home_is_using_inertia_handle_request_shared_data tests/Feature/HomePageTest.php

i dont get error...

dont know if the vscode plugin has some error or you have instanciated the class out of scope for the plugin to pickup.

I can live with command line but , the convenience of using a tool like better phpunit to invoke same keystroke saves more time :)

Can you look into this issue im sure this is very isolated case and mostly laravel people that are doing test will pick this error up.

goldcoders avatar Jan 30 '21 02:01 goldcoders

Hi,

The error is correct, but doesn't make any sense, because this package doesn't at all interact with Illuminate\Http\Response. Rather, it interacts with the Illuminate\Foundation\Testing\TestResponse object as a Macro.

Do you perhaps have an example of the violating test, and possibly the last 5-6 calls of the exception's stack trace?

claudiodekker avatar Feb 02 '21 17:02 claudiodekker

im using php 8.0 , maybe thats why, on php 7.4 this issue is not an issue... so something might be messing up the the Macro...

I dont know how to get the stack trace on visual studio code, only a popup notification appear with that error message... the stack trace is not log on the output or error logs ...

hope you can try on a php 8.0 set up... i believe this has issue on 8.0

i tried it on php 7.4 on my archlinux setup , no issue ...

so maybe thats why... Macros are messed up here at 8.0

goldcoders avatar Feb 03 '21 00:02 goldcoders

im using php 8.0 , maybe thats why, on php 7.4 this issue is not an issue...

That's still very strange, as we automatically run all of our tests against both the lowest & highest supported Laravel versions on every PHP version between PHP 7.2 and 8.0 (inclusive) every night, and everything seems to be working just fine.

I dont know how to get the stack trace on visual studio code, only a popup notification appear with that error message... the stack trace is not log on the output or error logs ...

Alright, that's unfortunate, as that means I can't really do a lot to debug it on my end then. I haven't used the package in a lot of PHP 8 projects yet, but I have used it in some, and can't reproduce what you're describing.

I'll leave this open for now in hopes that someone else will also run into this and can provide more context, but until then I'm afraid there isn't much I can do.

claudiodekker avatar Feb 09 '21 15:02 claudiodekker

@goldcoders

I had the same issue.

This is how i fixed it:

rm -rf vendor
composer update
php artisan optimize:clear

and unfortunately i had to change has to where in all my tests files.

// before
$response->assertInertia(function(Assert $page) {
    $page->has('title', trans('Reset Password'));
});

// after
$response->assertInertia(function(Assert $page) {
    $page->where('title', trans('Reset Password'));
});

liorocks avatar Feb 18 '21 12:02 liorocks

@Landish Glad that this solved it for you! 👍

Just to give some extra context/clarity: The way you were using has in your 'before' example was actually always incorrect, so it makes sense that you'd have to change it to where. The has method is really only capable of the following:

// Assert that the `comments` prop exists.
->has('comments')

// Assert that the `comments` prop exists, and is an array/object with 5 entries.
->has('comments', 5)

// Assert that the first `comments.0.id` prop matches is an integer with value 1 by using a `has`-scope
->has('comments.0', function (Assert $page) {
   $page->where('id', 1)
})

 // Direct/more verbose way to do the previous / scoped call.
->where('comments.0.id', 1)

claudiodekker avatar Feb 18 '21 13:02 claudiodekker