You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a test for a job that automatically updates a setting in some specific case. But when I refresh my settings class after the job, the values default back to the default values defined in my migrations.
It does work without the refresh() call in my test, but then I wouldn't ensure that I actually called the ->save() method on the setting.
Simplified example:
// Migration:$this->migrator->add('example.processing_enabled', false);
// Successful test, false positive because setting gets reset to false even without the dispatch.publicfunctionit_updates_the_setting_in_a_specific_case(): void
{
$settings = ExampleSettings::fake(['processing_enabled' => true]);
dispatch(newExampleJob(shouldUpdateSettings: true));
$settings->refresh();
$this->assertFalse($settings->processing_enabled);
}
// Failing testpublicfunctionit_does_not_update_the_setting_in_other_cases(): void
{
// example.processing_enabled = false$settings = ExampleSettings::fake(['processing_enabled' => true]);
dispatch(newExampleJob(shouldUpdateSettings: false));
$settings->refresh();
$this->assertTrue($settings->processing_enabled);
}
Any thoughts on this? Is there another way to actually enforce the call to ->save() in my tests while using fake settings? In my opinion the refresh method should work as expected even for fake settings but I'm not sure if I'm missing something.
Thanks in advance. This package is truly amazing!
The text was updated successfully, but these errors were encountered:
Fake settings were built to quickly set some settings in tests without having to update migrations. We've never built them to be saved actually. Why don't you work on the real database in this case?
I'm writing a test for a job that automatically updates a setting in some specific case. But when I refresh my settings class after the job, the values default back to the default values defined in my migrations.
It does work without the refresh() call in my test, but then I wouldn't ensure that I actually called the ->save() method on the setting.
Simplified example:
Any thoughts on this? Is there another way to actually enforce the call to ->save() in my tests while using fake settings? In my opinion the refresh method should work as expected even for fake settings but I'm not sure if I'm missing something.
Thanks in advance. This package is truly amazing!
The text was updated successfully, but these errors were encountered: