【发布时间】:2021-02-11 01:34:11
【问题描述】:
我想使用.env.testing,我读到了here:
您也可以创建一个 .env.testing 文件。当运行 PHPUnit 测试或使用 --env=testing 选项执行 Artisan 命令时,此文件将覆盖 .env 文件。
我有一个应该创建我的测试数据库的工匠命令。该命令在他的句柄方法中使用php artisan testdb:fresh和calling another command触发:
public function handle()
{
if ($this->isProduction()) {
$this->errorMessageTestingDatabase();
return;
}
$this->call('migrate:fresh', ['--env' => 'testing', '--seed' => true]);
}
但是,--env=testing 标志似乎被忽略了。连接到 db 异常失败。
但是,如果我运行命令
php artisan testdb:fresh --env=testing
它有效。使用 Artisan 命令调用 Artisan 命令时无法传递 env 标志?
【问题讨论】:
-
--seed是否正确执行?如果是这样,可能是因为--env不在migrate:fresh的范围内。 -
@RobBiermann 当我没有通过
--env=testing时,它在数据库连接上失败。当我通过它时,种子会被执行。 -
@RobBiermann 不,谢谢你告诉我,我的是重复的
-
我猜你可以使用
exec('php artisan migrate:fresh --env=testing --seed=true')来“解决”它,因为此代码不会被最终用户注入任何东西