-
Notifications
You must be signed in to change notification settings - Fork 25
Require bootstrap.php if exists, to load all necessary .env files #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require bootstrap.php if exists, to load all necessary .env files #190
Conversation
7f433fb
to
78a6fd7
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
78a6fd7
to
efcc394
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
i am a big fan of BC i just had a look at your code and thought about it. i am not sure if it is optimal. maybe it tries to think too much for "me". you are loading the if i want to load the i would want codeception to load the also i am not sure if overriding the environment is the perfect solution but for that i am not sure. just some thoughts. what do you think? do i missunderstand something or are my thoughts valid? |
Got it. Many comments in the issue thread prefer the Symfony module to handle environments like Symfony does, via If Codeception already loaded it, the btw, I wasn't aware that Codeception generates a |
i think the symfony module should only
|
i think you mix something up, we have |
Coincidentally, they share name and code: The module must interact with As for avoiding 'hardcoding' the environment, it is not hardcoded. You must specify the environment in the module configuration: - Symfony:
app_path: 'src'
environment: 'test' This value affects the tests. Update it if necessary; code added in this PR will work correctly. |
in gerneral i mean we have to look at codeceptions bootstrap.php in a more global perspective. we also have to assume the file exists without symfony. and even with symfony the files maybe completly different if i want to boot my test env differently. so i would disagree that the two files share the same code (even if they may). with hardcoded i mean, that you will always overwrite a already set environment. for example if a set
can you explain that please? why must the module interact with it? isn't the file loaded by codeception automatically if i defined another problem would be that your code will prevent to load codeceptions bootstap.php at all if config/bootstrap.php exists. why would you want that exactly? if i load bypass finals in codeceptions bootstrap.php and then want to boostrap symfony with config/bootstrap.php this would no longer work with your code. your code would require me to delete config/bootstrap.php and then manually add its code to codeceptions bootstrap.php so that it would work again. but i don't know codceptions internals enough, maybe we even don't need to load tests/bootstrap.php in the module at all (would make the most sense to me) as it was already loaded by codeception before. so my suggestion would be:
does this make sense for you? |
I've mentioned before: no, it's not in new installs. Not in the recipe either. If it's not loaded, Symfony module won't load; tests won't run. Tested it before the PR. Try it yourself. Changing the recipe won't help everyone who lacks the key.
"The user can modify the bootstrap.php file generated by Codeception/Symfony to remove the part where it loads environments and add their own custom code" is not something I'm going to fix in this PR.
Is not loaded.
You cannot disable the environment setting, it's required. Please test it yourself before further discussion; speculating won't help. |
efcc394
to
174e9d0
Compare
we talk past one another and maybe you missunderstood me. i invite you to do a voice chat with me to clearify things. i just argue for being able to have both: a custom bootstrap.php file without all symfony dotenv handling and the magic of the symfony module which would also load the dotenv code. this is not possible with your code. |
Done in the last commit. Anything else? |
@TavoNiievez the config parameter is perfect. it would be enough for me but it is not what i meant. i meant to also be able to load tests/boostrap.php (custom without dotenv) and let the symfony module do its magic to do all the rest (so the default config settings should simply "make it work" tm. to be completly flexible and allow all developers to customize their needs i would go more in a config-for-everyting direction. private function bootstrapEnvironment(): void
{
// with that i can manage if i want to override an existing env
if (empty($_ENV['APP_ENV']) || $this->config['set_app_env']) {
$_ENV['APP_ENV'] = $this->config['environment'];
}
// so i can load config/bootstrap.php or tests/bootstrap.php or nothing or for example tests/symfonyExtraBootstrap.php
if (!empty($this->config['bootstrap_file'])) {
$bootstrapFile = $this->kernel->getProjectDir() . $this->config['bootstrap_file'];
if (file_exists($bootstrapFile)) {
require_once $bootstrapFile;
}
}
if ($this->config['load_dotenv'] && !method_exists(Dotenv::class, 'bootEnv')) {
throw new LogicException(
"Symfony DotEnv is missing. Try running 'composer require symfony/dotenv'\n" .
"If you can't install DotEnv add your env files to the 'params' key in codeception.yml\n" .
"or update your symfony/framework-bundle recipe by running:\n" .
'composer recipes:install symfony/framework-bundle --force'
);
(new Dotenv())->bootEnv('.env');
}
} |
Ok, I understand what you want to do, but again I reiterate, that would be an (very custom) enhancement. This PR is dedicated to those who are having problems loading their env files just as they would expect them to be loaded in Symfony, nothing more, nothing less. The If that's not what you need just don't enable this feature. |
844559c
to
48c4263
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
@c33s thank you for your help in this matter. |
I'm replacing #4 with this.
In my last comment I expressed that I had problems with compatibility logic in lower versions of Symfony, but since the minimum compatible version is now 5.4 we can move on.
I require the
tests/bootstrap.php
file if it exists, otherwise I try to use dotEnv manually.If all that fails I throw an exception telling the user what to do.
In the tests I performed this works regardless of whether or not you have
.env
and.env.test
set incodeception.yml
.This will also allow to remove these values from the recipe since they are now loaded automatically.
Closes #99.