【问题标题】:Laravel 5.2: Setup APP_ENV for testingLaravel 5.2:设置 APP_ENV 进行测试
【发布时间】:2016-01-17 03:45:49
【问题描述】:

为了测试,我需要使用另一个数据库,而不是 local 环境。

我在开发流程中使用 homestead 和 Laravel 5.2 + Behat3 + Mink。

当我从主机运行 behat 时,这没问题 - 变量设置为 APP_ENV=testing

但是在宅基地机器内设置testing 环境时遇到问题:APP_ENV 始终为local

  1. 对于测试环境(APP_ENV)我修改了标准welcome.blade.php下一条路:

    - <div class="title">Laravel 5</div>
    + <div class="title">Laravel 5 ({!! app()->environment() !!})</div>
    
  2. 我已经配置了behat.yml:

    default:
        extensions:
            Laracasts\Behat:
                env_path: .env.behat
            Behat\MinkExtension:
                default_session: laravel
                laravel: ~
    
  3. 我在.env.behat中的测试环境变量:

    APP_ENV=testing
    APP_DEBUG=true
    DB_CONNECTION=sqlite
    
  4. 我做了我的 home.feature:

    Feature: Check home page
      In order to verify home page
      As a user
      I need to see text Laravel and an environment name
    
      @home
      Scenario: Home Page
        Given I am on the homepage
        Then I should see "Laravel 5 (testing)"
    

所以当我运行 behat 时,我看到 Laravel 5 (local) 但看不到 Laravel 5 (testing) 文本:

    Feature: Check home page
      In order to verify home page
      As a user
      I need to see Laravel text

      @home
      Scenario: Home Page                       # features/home.feature:7
        Given I am on the homepage              # FeatureContext::iAmOnHomepage()
        Then I should see "Laravel 5 (testing)" # FeatureContext::assertPageContainsText()
          The text "Laravel 5 (testing)" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)

    --- Failed scenarios:

        features/home.feature:7

    1 scenario (1 failed)

我在配置中遗漏了什么,或者关于自定义设置 Laravel 配置我应该知道什么?

【问题讨论】:

    标签: php behat homestead mink laravel-5.2


    【解决方案1】:

    我不知道是不是这样,但请确保您的Homestead.yaml 中没有:

    variables:
        - key: APP_ENV
          value: local
    

    如果这样做,请将其删除,然后您可以尝试配置您的虚拟机,但很有可能您需要销毁它(您应该首先备份所有内容,例如数据库等)并在从文件中删除后重新创建。

    【讨论】:

    • 太棒了!您的解决方案有效。实际上,我的 Homestead.yaml 中有变量配置。所以我把它移走了,并为宅基地做好了准备。现在所有的测试都通过了。非常感谢。
    • 很高兴我能帮上忙。如果所有问题都可以这么容易解决:)
    • 哦,是的,你是对的 :-) 祝你快速轻松地解决你的任务。
    猜你喜欢
    • 1970-01-01
    • 2016-09-02
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    相关资源
    最近更新 更多