changing a config value depending on test method

I have an application with a system to verify accounts (register -> get email with link to activate -> account verified). That verification flow is optional and can be switched off with a configuration value:

// config/auth.php
return [
  // ...
  'enable_verification' => true
];

I want to test the registration controller:

  • it should redirect to home page in both cases
  • when verification is ON, home page should show message 'email sent'
  • when verification is OFF, home page should show message 'account created'
  • etc.
  • My test methods:

    public function test_UserProperlyCreated_WithVerificationDisabled()
    {
        $this->app['config']->set('auth.verification.enabled', false);
    
        $this
            ->visit(route('frontend.auth.register.form'))
            ->type('Test', 'name')
            ->type('test@example.com', 'email')
            ->type('123123', 'password')
            ->type('123123', 'password_confirmation')
            ->press('Register');
    
        $this
            ->seePageIs('/')
            ->see(trans('auth.registration.complete'));
    }
    
    public function test_UserProperlyCreated_WithVerificationEnabled()
    {
        $this->app['config']->set('auth.verification.enabled', true);
    
        $this
            ->visit(route('frontend.auth.register.form'))
            ->type('Test', 'name')
            ->type('test@example.com', 'email')
            ->type('123123', 'password')
            ->type('123123', 'password_confirmation')
            ->press('Register');
    
        $this
            ->seePageIs('/')
            ->see(trans('auth.registration.needs_verification'));
    }
    

    When debugging, I noticed that the configuration value when inside the controller method is always set to the value in the config file, no matter what I set with my $this->app['config']->set...

    I have other tests on the user repository itself to check that it works both when validation is ON or OFF. And there the tests behave as expected.

    Any idea why it fails for controllers and how to fix that?


    如果我理解你的问题 - 你在寻找“如何设置配置参数”,那么你可以使用Config::set($key, $value)

    链接地址: http://www.djcxy.com/p/92256.html

    上一篇: 码头图像名称是如何分析的?

    下一篇: 根据测试方法更改配置值