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:
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('[email protected]', '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('[email protected]', '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?
If I understand your question right - you looking for "how to set config param", then you can use Config::set($key, $value)
Correct answer is above
Config::set($key, $value)
Example
//Not forget to add namespace using class.
use Config;
//Example to set config. (configFile.key)
Config::set('auth.enable_verification', false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With