Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

oprudkyi
Copy link

  • load env file based on environment set via --env, i.e. --env=something will load settings from .env.something
  • support for Laravel 5.1 (tested with 5.3)

these changes are needed to fix issue when command is called directly from console, i.e. if something like

./artisan db:seed-test --env=testing

is called, then script uses values from .env (and not from .env.testing)

so update forces use of a correct db via reloading environment/configuration based on passed value from --env

- load env file based on environment set via --env, i.e.
 --env=something will load settings from .env.something
- support Laravel 5.1 (tested with 5.3)
@smazurov
Copy link
Contributor

I'm not certain this is the correct and expected behavior of laravel apps, if you have a testing env file, it should contain correct db/cache for testing from .env.testing, instead of quietly reading from .env.

If you have a env var you wish to overwrite, you can always pass it into console like:

$ MYSQL_HOST=testhost.dev php artisan db:seed-test --env=testing

@oprudkyi
Copy link
Author

oprudkyi commented Dec 23, 2016

Hi,
well, I do understand I'm trying to fix edge case , i.e.

  • I use the command to seed testing instance for acceptance testing (i.e. via phanton/codeception) and there no phpunit bootstrap to force correct shell file (at least easy one)
  • there is some additional scripting involved , so editing of scripts to keep them in sync with .etc.testing also is not always convenient

if you have a testing env file, it should contain correct db/cache for testing from .env.testing, instead of quietly reading from .env.

Unfortunately , with unpatched server.php/bootstrap.. and/or setting shell variables it reads .env only

If you have a env var you wish to overwrite, you can always pass it into console like:

yes, but in case of scripting and hardly predicable config it ends in headache

the other idea was to dynamically replace .env with .env.testing but it also can have not expected results (i.e. script breaks and original .env not returned back etc)

so I end with such solution

Well, probably there should be additional shell parameter to run my code, some like --force-correct-env-file to avoid running this part of code every time

@oprudkyi
Copy link
Author

oh, I'm sorry, please forget this, seems Laravel 5.3. handles this by self , i.e. --env=testing loads correct .env file now.
I will leave only updates for ^5.1

@oprudkyi
Copy link
Author

I've removed hack for reloading environment

@smazurov
Copy link
Contributor

as far as i understand it, this now only updates the required laravel version, and adds some commented out lines, is this actually required? It works fine for us on a 5.1 laravel.

@oprudkyi
Copy link
Author

Well, on 5.3. the
return $this->laravel['file'];
doesn't work (with sqlite) , it raises exception 'ReflectionException' with message 'Class file does not exist'

so changing 'file' to 'files' is required
return $this->laravel['files'];

also it seems 'files' are default name of facade starting from 5.0
https://laravel.com/docs/5.0/facades

@smazurov
Copy link
Contributor

got it - if you remove the commented out lines i will merge and release a new version, thanks for clarifying!

@oprudkyi
Copy link
Author

I've removed anything unrelated (the function/var names don't affect functionality). seems not so much to merge :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants