When I run my unit tests unsing Laravel I have an error that I can’t resolve…
No application encryption key has been specified.
I’ve tried this twice commands:
php artisan key:generate php artisan config:cache
Nothing changes there, I always remain blocked whereas my key exists in the .env…
I also tried to delete the .env and regenerate one from the .env.example
Advertisement
Answer
Laravel’s embeded PHPUnit uses .env.testing
file to load dotenv variables and also has an option to override dotenv variables by specifying on phpunit.xml
.
Try create the file .env.testing
and input test-dedicated env variables and make sure you have APP_KEY
entry on it.
For more details, see this link; https://laravel.com/docs/8.x/testing#environment