Symfony:加载 .env.test 文件

标签 symfony symfony4

我认为这个 PR 解决了我遇到的问题 - 但我有这个补丁但它仍然没有按我预期的那样工作 - 我错过了什么或误解了什么?

https://github.com/symfony/symfony/pull/28533

我创建了一个包含以下内容的 .env.test:

DATABASE_URL_TEST=mysql://apps:@localhost:3306/mydb_test

然后我在 config/packages/test 目录中放置了一个 doctrine.yaml。

Symfony v4.2.3

但是,当我从 CLI 运行此命令时:

APP_ENV=test bin/console doctrine:database:create --env=test

我收到一个错误:

Environment variable not found: "DATABASE_URL_TEST".

很明显 .env.test 文件没有被加载 - 我如何才能加载一个特定的环境配置文件 - 除了 .env???

最佳答案

如果您的应用程序在某个时候确实是 Symfony 3.x 应用程序,我猜想是在升级过程中,UPGRADE 过程中的这两行被遗漏了:

Then, upgrade the contents of your console script and your front controller:

确实,bin/console 最近似乎已经更改,以反射(reflect)在 DotEnv 组件上完成的改编:https://github.com/symfony/recipes/commit/3e471cbc7d359b3ab245f3b0748d698e8d29692c#diff-2af50efd729ff8e61dcbd936cf2b114b

请注意,您还需要 https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/config/bootstrap.php

关于Symfony:加载 .env.test 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54816276/

相关文章:

php - Symfony2 : ResourceNotFoundException when using extends in a twig template

symfony - 将默认的应用程序命名空间更改为其他名称

php - 在 symfony 中使用参数执行 sql 请求时出现语法错误?

php - 在 Symfony 中使用 config.php 和 doctrine.yaml 使用动态数据库名称

symfony - 用 fosuser 覆盖注册 Controller 无法 Autowiring 服务 "App\Controller\RegistrationController"

forms - 在 Symfony2 中将数据库中的数据显示到表单

php - 根据内核请求重定向

php - 安装 php symfony 安装程序

php - 交响乐2 : setting form attributes in Form Class

symfony - 在 SF3.4 及更高版本中运行 Symfony DIC 烟雾测试