Codeception / Codeception/module-laravel

environment_file is not respected if laravel config cache exists (Laravel 7.x and 8.x)

Aperta
#37 1 commento 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
6
Fork
13
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi,

documentation states (https://codeception.com/docs/modules/Laravel) that `environment_file` specifies the environment file to load for the tests.

Laravel loads env file in https://github.com/laravel/framework/blob/1f700400890e7c43233afb43951821b9d2b70f3c/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php#L86
That function is, however, only called if there is no existing config cache, see https://github.com/laravel/framework/blob/3b6732ff4c2a095e1edac6a3dab84d9b29243325/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php#L22

So, e.g. running `php artisan config:cache` will create a config cache with your default .env file.

Running `vendor/bin/codecept run [...]` will then ignore the environment_file as the config is not loaded, as there already is a cache using the default .env file. No warning or error whatever is thrown. The test will run using the .env file possibly clearing and filling your database with test cases.

Is this by design or a bug?
I haven't found anything in the docs of the module regarding this cache issue.

My current workaround will be to run `php artisan config:clear` before running any test, maybe even including this command in the setup routines of an extended Laravel codeception module. What is the best practise to avoid such problems?

EDIT: I would strongly advise to at least throw an error if a config cache exists or the config cache is different than what is specified in the environment_file

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Reproduce the issue with Laravel's config:cache and Codeception's environment_file setting, then inspect the Laravel module documentation and the linked LoadEnvironmentVariables.php paths. Confirm how the module should behave when a config cache exists; done means the mismatch is safely handled through an implemented warning/error or clear documented behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
laravel, php
Ambito
backend, testing
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.