Let's say you have a test run where every test that renders a view fails with the same error:
InvalidArgumentException: View [some-view-name] not found.
This isn't hypothetical, someone booked a Get Unstuck call with me and wanted help with this exact problem.
First, I checked the location on disk for the Blade files. The views hadn't moved, and nothing in the tests changed since the last passing test run.
I cleared the view cache as well to be safe, but no change.
It turned out the cause was a cached config file instead. Why?
When you run php artisan config:cache, Laravel evaluates every config file once and writes the results to bootstrap/cache/config.php.
That includes your view paths, which get stored as absolute paths:
// bootstrap/cache/config.php
'view' => [
'paths' => [
'/app/resources/views',
],
'compiled' => '/app/storage/framework/views',
],
Those paths are right for wherever the command ran. But in this project, they had Docker containers, but would sometimes run tests from the host.
The project lived at /app inside the container and somewhere under their home directory on the host, but both sides shared the same bootstrap/cache directory.
This was the mismatch.
For this person, the fix was just to run php artisan config:clear.
In addition, I advised to 1) not cache config locally, it causes all sorts of issues during development, and 2) always run your tests in the container.
New Laravel apps ship with a composer test script that always runs config:clear first, and this is why, to just bypass this issue even when doing weird things on your dev machine.
Here to help,
Joel
P.S. Our testing course starts with environment setup, including a separate test database and safe overrides in phpunit.xml.