1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Tests: purge settings cache

Some tests need to change settings, but since MemoryCacheSettingsRepository caches settings in-memory, those changes aren't reflected. The new `purgeSettingsCache` removes it from the container, eliminating that cache.

For UserTest, we also need to regenerate the display name driver, since that's set statically on boot, before we'll get a change to clear the settings cache.
This commit is contained in:
Alexander Skvortsov
2021-01-07 14:10:53 -05:00
parent fd79a14cac
commit 6771b3e3b7
4 changed files with 60 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\extenders;
use Flarum\Extend;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\Tests\integration\UsesSettings;
use Flarum\User\DisplayName\DriverInterface;
use Flarum\User\User;
use Illuminate\Support\Arr;
@@ -19,6 +20,7 @@ use Illuminate\Support\Arr;
class UserTest extends TestCase
{
use RetrievesAuthorizedUsers;
use UsesSettings;
/**
* @inheritDoc
@@ -37,6 +39,17 @@ class UserTest extends TestCase
]);
}
/**
* Purge the settings cache and reset the new display name driver.
*/
protected function recalculateDisplayNameDriver()
{
$this->purgeSettingsCache();
$container = $this->app()->getContainer();
$container->forgetInstance('flarum.user.display_name.driver');
User::setDisplayNameDriver($container->make('flarum.user.display_name.driver'));
}
protected function registerTestPreference()
{
$this->extend(
@@ -51,6 +64,7 @@ class UserTest extends TestCase
public function username_display_name_driver_used_by_default()
{
$this->app();
$this->recalculateDisplayNameDriver();
$user = User::find(1);
@@ -68,6 +82,7 @@ class UserTest extends TestCase
);
$this->app();
$this->recalculateDisplayNameDriver();
$user = User::find(1);