Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow modifying of config values in test #599

Closed
dellow opened this issue Jan 7, 2019 · 3 comments
Closed

[Feature Request] Allow modifying of config values in test #599

dellow opened this issue Jan 7, 2019 · 3 comments

Comments

@dellow
Copy link

dellow commented Jan 7, 2019

Would be great if we could modify a config value with config helper in tests (or in setUp()):

// Update config.
config()->set('config_bool', true);
// Run test.
$this->browse(function($browser) {
  $browser
    ->visit('/test-endpoint')
    ->assertPresent('.element-visible-by-config_bool');
});

This doesn't seem to work no matter where I place the config()->set() command.

@staudenmeir
Copy link
Contributor

Site and test run in separate processes, so this is a complex issue.

You could achieve it by temporarily altering the .env file.

@dellow
Copy link
Author

dellow commented Jan 7, 2019

Ok I understand. Will close the issue.

@dellow dellow closed this as completed Jan 7, 2019
@tomvo
Copy link

tomvo commented May 27, 2020

For who stumbles on this, i've solved it by adding a middleware when running in debug + test mode which looks for a duskconfig get param.
Something along these lines:

public function handle($request, Closure $next)
    {
        $shouldHandle = false; 
        
        //Only handle the DuskRuntimeConfig when debug=TRUE and environment=testing
        if(config('app.debug') && app()->environment() == 'testing'){
            //Do an extra check for hostname and environment
            if(in_array($request->getHttpHost(), ['localhost:8000', '127.0.0.1:8000'])){
                $shouldHandle = true;
            }            
        }

        if($shouldHandle){
            if($request->has('duskconfig')){
                $configValues = json_decode($request->get('duskconfig'), true);

                if(sizeof($configValues) > 0){
                    foreach($configValues as $key => $value){
                        config([$key => $value]);
                    }
                }
            }
        }

        return $next($request);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants