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

fake settings do not persist after ->refresh() call #240

Closed
markwalet opened this issue Oct 12, 2023 · 2 comments
Closed

fake settings do not persist after ->refresh() call #240

markwalet opened this issue Oct 12, 2023 · 2 comments

Comments

@markwalet
Copy link
Contributor

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.
public function it_updates_the_setting_in_a_specific_case(): void
{
    $settings = ExampleSettings::fake(['processing_enabled' => true]);

    dispatch(new ExampleJob(shouldUpdateSettings: true));
    $settings->refresh();

    $this->assertFalse($settings->processing_enabled);
}

// Failing test
public function it_does_not_update_the_setting_in_other_cases(): void
{
    // example.processing_enabled = false
    $settings = ExampleSettings::fake(['processing_enabled' => true]);

    dispatch(new ExampleJob(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!

@rubenvanassche
Copy link
Member

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?

@rubenvanassche
Copy link
Member

Closing due to inactivity.

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

2 participants