diff --git a/composer.json b/composer.json index 3eff12d82..033fa82d8 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "wikimedia/less.php": "^3.0" }, "require-dev": { - "flarum/testing": "^0.1.0-beta.16" + "flarum/testing": "dev-main#81e25f034e2b6dceaea753ad7579b5c61d641993" }, "autoload": { "psr-4": { diff --git a/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php b/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php index 2b769f27e..d0a1180eb 100644 --- a/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php +++ b/tests/integration/api/csrf_protection/RequireCsrfTokenTest.php @@ -26,11 +26,10 @@ class RequireCsrfTokenTest extends TestCase $this->prepareDatabase([ 'api_keys' => [ ['user_id' => 1, 'key' => 'superadmin'], - ], - 'settings' => [ - ['key' => 'csrf_test', 'value' => 1], - ], + ] ]); + + $this->setting('csrf_test', 1); } /** diff --git a/tests/integration/api/users/CreateTest.php b/tests/integration/api/users/CreateTest.php index af8d6c727..ba9b7239b 100644 --- a/tests/integration/api/users/CreateTest.php +++ b/tests/integration/api/users/CreateTest.php @@ -25,11 +25,7 @@ class CreateTest extends TestCase { parent::setUp(); - $this->prepareDatabase([ - 'settings' => [ - ['key' => 'mail_driver', 'value' => 'log'], - ], - ]); + $this->setting('mail_driver', 'log'); } /** diff --git a/tests/integration/extenders/FilesystemTest.php b/tests/integration/extenders/FilesystemTest.php index 78482a26c..3edcaf4bf 100644 --- a/tests/integration/extenders/FilesystemTest.php +++ b/tests/integration/extenders/FilesystemTest.php @@ -83,7 +83,7 @@ class FilesystemTest extends TestCase */ public function disk_uses_local_adapter_if_configured_adapter_from_config_file_unavailable() { - $this->overrideConfigWithDiskDriver(); + $this->config('disk_driver.flarum-assets', 'null'); $assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets'); @@ -115,25 +115,12 @@ class FilesystemTest extends TestCase (new Extend\Filesystem)->driver('null', NullFilesystemDriver::class) ); - $this->overrideConfigWithDiskDriver(); + $this->config('disk_driver.flarum-assets', 'null'); $assetsDisk = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets'); $this->assertEquals(get_class($assetsDisk->getDriver()->getAdapter()), NullAdapter::class); } - - protected function overrideConfigWithDiskDriver() - { - $tmp = $this->tmpDir(); - $configArr = include "$tmp/config.php"; - $configArr = array_merge($configArr, ['disk_driver' => [ - 'flarum-assets' => 'null' - ]]); - - $config = new Config($configArr); - - $this->app()->getContainer()->instance('flarum.config', $config); - } } class NullFilesystemDriver implements DriverInterface diff --git a/tests/integration/extenders/ModelUrlTest.php b/tests/integration/extenders/ModelUrlTest.php index 87ac36f82..05e5d1a75 100644 --- a/tests/integration/extenders/ModelUrlTest.php +++ b/tests/integration/extenders/ModelUrlTest.php @@ -15,13 +15,11 @@ use Flarum\Http\SlugDriverInterface; use Flarum\Http\SlugManager; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; -use Flarum\Testing\integration\UsesSettings; use Flarum\User\User; class ModelUrlTest extends TestCase { use RetrievesAuthorizedUsers; - use UsesSettings; /** * @inheritDoc @@ -31,12 +29,12 @@ class ModelUrlTest extends TestCase parent::setUp(); $userClass = User::class; + + $this->setting("slug_driver_$userClass", 'testDriver'); + $this->prepareDatabase([ 'users' => [ $this->normalUser(), - ], - 'settings' => [ - ['key' => "slug_driver_$userClass", 'value' => 'testDriver'], ] ]); } @@ -46,8 +44,6 @@ class ModelUrlTest extends TestCase */ public function uses_default_driver_by_default() { - $this->purgeSettingsCache(); - $slugManager = $this->app()->getContainer()->make(SlugManager::class); $testUser = User::find(1); @@ -63,8 +59,6 @@ class ModelUrlTest extends TestCase { $this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class)); - $this->purgeSettingsCache(); - $slugManager = $this->app()->getContainer()->make(SlugManager::class); $testUser = User::find(1); diff --git a/tests/integration/extenders/SettingsTest.php b/tests/integration/extenders/SettingsTest.php index c1953afb9..437707f9f 100644 --- a/tests/integration/extenders/SettingsTest.php +++ b/tests/integration/extenders/SettingsTest.php @@ -12,12 +12,10 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; -use Flarum\Testing\integration\UsesSettings; class SettingsTest extends TestCase { use RetrievesAuthorizedUsers; - use UsesSettings; /** * @inheritDoc @@ -29,12 +27,11 @@ class SettingsTest extends TestCase $this->prepareDatabase([ 'users' => [ $this->normalUser() - ], - 'settings' => [ - ['key' => 'custom-prefix.custom_setting', 'value' => 'customValue'], - ['key' => 'custom-prefix.custom_setting2', 'value' => 'customValue'] ] ]); + + $this->setting('custom-prefix.custom_setting', 'customValue'); + $this->setting('custom-prefix.custom_setting2', 'customValue'); } /** @@ -42,8 +39,6 @@ class SettingsTest extends TestCase */ public function custom_setting_isnt_serialized_by_default() { - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -65,8 +60,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.customSetting', 'custom-prefix.custom_setting') ); - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -91,8 +84,6 @@ class SettingsTest extends TestCase }) ); - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -115,8 +106,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.customSetting2', 'custom-prefix.custom_setting2', CustomInvokableClass::class) ); - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -139,8 +128,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.noCustomSetting', 'custom-prefix.no_custom_setting', null, 'customDefault') ); - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -165,8 +152,6 @@ class SettingsTest extends TestCase }, 'customDefault') ); - $this->purgeSettingsCache(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, diff --git a/tests/integration/extenders/UserTest.php b/tests/integration/extenders/UserTest.php index 2f3226d47..ef37ec53b 100644 --- a/tests/integration/extenders/UserTest.php +++ b/tests/integration/extenders/UserTest.php @@ -12,7 +12,6 @@ namespace Flarum\Tests\integration\extenders; use Flarum\Extend; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; -use Flarum\Testing\integration\UsesSettings; use Flarum\User\DisplayName\DriverInterface; use Flarum\User\User; use Illuminate\Support\Arr; @@ -20,7 +19,6 @@ use Illuminate\Support\Arr; class UserTest extends TestCase { use RetrievesAuthorizedUsers; - use UsesSettings; /** * @inheritDoc @@ -32,22 +30,10 @@ class UserTest extends TestCase $this->prepareDatabase([ 'users' => [ $this->normalUser(), - ], - 'settings' => [ - ['key' => 'display_name_driver', 'value' => 'custom'], ] ]); - } - /** - * 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')); + $this->setting('display_name_driver', 'custom'); } protected function registerTestPreference() @@ -64,7 +50,6 @@ class UserTest extends TestCase public function username_display_name_driver_used_by_default() { $this->app(); - $this->recalculateDisplayNameDriver(); $user = User::find(1); @@ -82,7 +67,6 @@ class UserTest extends TestCase ); $this->app(); - $this->recalculateDisplayNameDriver(); $user = User::find(1);