-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Adding test bootstrap.php file so .env vars are read #366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
/* | ||
* Environment variables can also be specified in phpunit.xml.dist. | ||
* Those variables will override any defined in .env. | ||
*/ | ||
|
||
if (!isset($_SERVER['APP_ENV']) || 'prod' !== $_SERVER['APP_ENV']) { | ||
if (!class_exists(Dotenv::class)) { | ||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); | ||
} | ||
(new Dotenv())->load(__DIR__.'/../.env'); | ||
} | ||
|
||
$debug = $_SERVER['APP_DEBUG'] ?? true; | ||
|
||
if ($debug) { | ||
umask(0000); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
// The check is to ensure we don't use .env in production | ||
if (!isset($_SERVER['APP_ENV'])) { | ||
if (!isset($_SERVER['APP_ENV']) || 'prod' !== $_SERVER['APP_ENV']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just had an issue trying to warm-up my cache on the CI.
I can see that my case is kind of weird and I am going to change the way I ran the command but we could do something to improve DX in that case perhaps ? |
||
if (!class_exists(Dotenv::class)) { | ||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
/* | ||
* Environment variables can also be specified in phpunit.xml.dist. | ||
* Those variables will override any defined in .env. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! |
||
*/ | ||
if (!isset($_SERVER['APP_ENV'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouln't this be the same as for version 4.7?
|
||
if (!class_exists(Dotenv::class)) { | ||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); | ||
} | ||
(new Dotenv())->load(__DIR__.'/../.env'); | ||
} | ||
|
||
$debug = $_SERVER['APP_DEBUG'] ?? true; | ||
|
||
if ($debug) { | ||
umask(0000); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use
getenv('APP_ENV')
instead of$_SERVER['APP_ENV']
. Are there any reasons behind? Symfony recommends to usegetenv()
in docs but has$_SERVER[]
in code which is not consistent as for me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #156 about that. It should probably be updated in the docs then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getenv
is an issue because of not being thread safe (probably less an issue in the PHPUnit bootstrap as this is used only in the CLI)