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

Skip to content

Allow to override .env files per env #481

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

Merged
1 commit merged into from
Nov 9, 2018
Merged

Allow to override .env files per env #481

1 commit merged into from
Nov 9, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 8, 2018

Q A
License MIT

This PR is an alternative to #466 and replaces #479.
It needs symfony/symfony#29129 to work with 4.2.

What we have here:

Regarding flex integration:

  • this PR doesn't change anything for existing projects - they won't notice
  • when flex sees a .env.test file, it should skip updating phpunit.xml files
  • that's it - all the rest should remain identical, isn't it?
  • (people that still want to use .env.dist just need to create the file and flex will populate it as it does today)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

@nicolas-grekas
Copy link
Member Author

I improved the phpunit-bridge integration: it now uses .env files before anything else.
This means .env.test works now to configure the bridge also.
This fixes symfony/symfony#28726

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request passes validation.

umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($env, $debug);
$kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to cast $_SERVER['APP_DEBUG'] to boolean to not rely on implicit typecast.

fabpot added a commit to symfony/flex that referenced this pull request Nov 12, 2018
…icolas-grekas)

This PR was merged into the 1.1-dev branch.

Discussion
----------

Skip updating phpunit.xml files when .env.test exists

This is to support `.env` < `.env.local` < `.env.test` < `.env.test.local` dotenv files *withouth affecting existing workflows* based on `.env(.dist)` and `phpunit.xml(.dist)`.

Leveraged by symfony/recipes#481

Best reviewed [ignoring whitespaces](https://github.com/symfony/flex/pull/434/files?w=1).

Commits
-------

ae7128a Skip updating phpunit.xml files when .env.test exists
@bartvanraaij
Copy link

bartvanraaij commented Nov 13, 2018

It looks like the "env Configurator" is broken since this PR?

I try to set up a new API Platform project via:

composer create-project symfony/skeleton test-api
cd test-api
composer req api

At this point, after installing all the packages etc., the console reads Modify your DATABASE_URL config in .env.
However, the .env-file is completely empty (apart from the default comment regarding real env-vars).
Also, the CORS_ALLOW_ORIGIN var which is required by NelmioCorsBundle (installed by API Platform) is not added.

If I manually create a .env.dist file before doing composer req api it does work. But that's a workaround to trigger the "old way" I guess.

Another use case:

composer create-project symfony/website-skeleton test-site

This also generates an empty .env file.

@fabpot
Copy link
Member

fabpot commented Nov 14, 2018

/cc @nicolas-grekas

@nicolas-grekas
Copy link
Member Author

(fixed by bumping flex to v1.1.7 in skeletons)

@bendavies
Copy link
Contributor

To make others aware, there is a breaking change here if your coding standard adds declare(strict_types=1); to index.php as the cast of APP_DEBUG to a bool is no longer done, which will result in:

PHP Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\HttpKernel\Kernel::__construct() must be of the type boolean, string given`

So, exclude these file from your cs fixer config.

@ciaranmcnulty
Copy link

@bendavies or add an explicit (bool) cast to your index.php whilst adding the declare

@bendavies
Copy link
Contributor

bendavies commented Nov 22, 2018

@ciaranmcnulty well yes, but I'd rather keep inline with upstream so I can just copy and paste updates from recipes in future without having to diff my own changes. I'm treating these files as vendors essentially.

This was a good bug, as our integration tests don't hit index.php, so this error made it to a deployed environment before being spotted (testing env, thankfully).

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet