The wantsJson()
method checks the Accept HTML header for the string application/json
and returns true if it is set.
The isJson()
method checks that the HTML header CONTENT_TYPE
contains the string /json
and returns true if it is found.
Both methods are found in vendor/laravel/framework/src/Illuminate/Http/Request.php
The ajax method set the content type and the accept headers to json and in my experience that tends to be the default behavior (although not to be assumed.)
Your PHPUnit Test hasn't set any headers and thus why wantsJson
and isJson
methods return false
The fact that isJson
returned true
here is likely because its called after the CONTENT_TYPE has been set
I hope this helps.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community