This fails because the attempt to log in responds with a 419 because there is no CSRF token provided with the request. I tried adding a $this->get('/login'); before the POST, but that didn't help. I don't see how this could ever work since it doesn't try to get hold of a CSRF token before the POST, so I don't understand why this test is written this way. FWIW the login blade template does have a @csrf directive in.
Is there some standard way to disable CSRF during tests, or some way I should get hold of the token before making the request?
@synchro Laravel tests should automatically handle CSRF tokens. Otherwise everyone’s test suite would be broken and no one would be able to issue a POST request without first having to retrieve a valid CSRF token.
It sounds like you’ve maybe changed something or disabled something if Laravel is not automatically handling CSRF tokens for you in tests.
To check whether it's my doing or not, I just set up a clean install of Laravel, installed breeze, configured it using an empty sqlite DB, and ran the default tests – it fails authentication with the same 419 error.
What setting might affect whether the test env uses CSRF or not?
I finally found the problem. I have a .env.testing config file to use during tests, however, my phpunit.xml file overrides some of the settings in there, but in particular it overrides the database connection type, substituting sqlite for my configured mysql. It turns out that some of my migrations are incompatible with sqlite (drops multiple columns in one modification), but because PHPUnit aggressively suppresses error output, this underlying problem was hidden, and it took a lot of debugging to expose this error.
What was especially annoying is that when you run an individual test within PHPStorm, it doesn't seem to use this db config override, so the individual test was passing, but the same test would fail when run via artisan test.
I repeated a clean Laravel install with Jetstream, and the default test suite did pass, so I don't know what was wrong with my previous attempt to do that.