Laravel 5应用程序始终使用“测试"环境配置 [英] Laravel 5 app always using 'testing' environment configuration

查看:144
本文介绍了Laravel 5应用程序始终使用“测试"环境配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两种环境和两种配置的Laravel 5应用程序:测试(用于PHPUnit配置,内存数据库)和本地(我的开发配置).

I have a Laravel 5 app with two environments and two configurations: testing (for PHPUnit configuration, in-memory db) and local (my development configuration).

即使将环境配置为local,应用程序也只会将配置加载到resources/config/testing文件夹中.我可以从APP_ENV环境变量在同一应用程序中看到环境,它是local.

Even when the environment is configured to be local, the application only loads the configuration in the resources/config/testing folder. I can see the environment in the same app from the APP_ENV environment variable, and it is local.

  • 我应该不使用测试配置目录来配置我的测试吗?

  • Should I just not be using a testing configuration directory for configuring my tests?

在Laravel 5中配置测试环境的更好方法是什么?

What's a better way to configure my testing environment in Laravel 5?

推荐答案

Laravel 5不再正确地级联配置文件,因此您的测试配置文件将覆盖您本地配置文件中的所有内容.

Laravel 5 doesn't cascade config files correctly anymore so your testing config file is overriding anything you have in your local config file.

现在,您不应该为每种环境提供任何子文件夹,而应在根文件夹的.env文件内设置配置设置.

Now you aren't supposed to have any subfolders for each environment, but rather set configuration settings inside the .env file in the root folder.

此文件未检入存储库,以确保没有敏感内容被检入存储库.对于您的应用程序所处的每种环境,您都应该有一个单独的.env文件.

This file isn't checked in to the repo to ensure that nothing sensitive is checked into the repo. You should have a separate .env file for each environment your application is living.

测试

对于php单元(功能性),您可以在phpunit.xml文件中设置env变量,例如.

For php unit (functional) you can set env variables in the phpunit.xml file e.g..

<php>
    <env name="APP_ENV" value="testing"/>
    <env name="CACHE_DRIVER" value="array"/>
    <env name="SESSION_DRIVER" value="array"/>
</php>

对于Behat(接受)测试Laracasts Laravel Behat扩展,您可以创建一个.env.behat文件来更改环境变量.

For behat (acceptance) testing the Laracasts Laravel Behat extension allows you to create a .env.behat file to change the environment variables.

对于phpspec(单元)进行良好的测试,环境无关紧要,因为您单独测试各个方法并模拟其他所有方法.

For phpspec (unit) testing well the environment shouldn't matter as your testing individual methods in isolation and mock everything else.

对于硒(集成/系统/e2e)测试,无论您在哪里进行测试,环境变量都应来自服务器上的.env文件.

For selenium (integration / system / e2e) testing the environment variables should come from the .env file on the server wherever you are doing this testing.

这篇关于Laravel 5应用程序始终使用“测试"环境配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆