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

[testing] Formatter cache is not cleared after tests #3663

Closed
imorland opened this issue Nov 1, 2022 · 2 comments · Fixed by #3811
Closed

[testing] Formatter cache is not cleared after tests #3663

imorland opened this issue Nov 1, 2022 · 2 comments · Fixed by #3811
Assignees
Milestone

Comments

@imorland
Copy link
Member

imorland commented Nov 1, 2022

Current Behavior

When running tests which involve the Formatter, the formatter cache is not cleared at the end of the test run

Steps to Reproduce

  • Run a test which does not enable flarum/markdown
  • Write a test which enabled flarum/markdown
  • test the output
  • run both tests again, notice that the previous first test now fails

By adding

protected function tearDown(): void
    {
        parent::tearDown();

        resolve(Formatter::class)->flush();
    }

To the test class, behaviour is as would be expected.

Expected Behavior

The Formatter cache should be cleared as part of tearDown()

Screenshots

No response

Environment

  • Flarum version: x.y.z
  • Website URL: http://example.com
  • Webserver: [e.g. apache, nginx]
  • Hosting environment: [e.g. shared, vps]
  • PHP version: x.y.z
  • Browser: [e.g. chrome 67, safari 11]

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

No response

Additional Context

No response

@n-peugnet
Copy link
Contributor

Similarly to this, the application's cache is not cleared between each tests, this took me quite some time to realize while trying to write some tests for code that interact with the cache.

I solved it by clearing the cache myself in the tearDown() using this line:

$this->app()->getContainer()->make(\Illuminate\Contracts\Cache\Store::class)->flush();

But IMO this should be always done, as the tests should be as independent from each other as possible.

@SychO9
Copy link
Member

SychO9 commented May 2, 2023

PR welcome :)

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

Successfully merging a pull request may close this issue.

3 participants