From 7c95e4517876bab8e800f15fd73257e2db51ba8d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 12 Apr 2023 17:28:47 -0700 Subject: [PATCH] Introduce trait to conditionally interact with settings --- tests/Feature/Api/Assets/AssetIndexTest.php | 3 +++ tests/Feature/Api/Users/UsersForSelectListTest.php | 3 +++ tests/Support/InteractsWithSettings.php | 8 ++++++++ tests/TestCase.php | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/Support/InteractsWithSettings.php diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 2bb54b8097..3618c6e01e 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -6,10 +6,13 @@ use App\Models\Asset; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetIndexTest extends TestCase { + use InteractsWithSettings; + public function testAssetIndexReturnsExpectedAssets() { Asset::factory()->count(3)->create(); diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 71e094b669..6ab5bf9a85 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -6,10 +6,13 @@ use App\Models\Company; use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class UsersForSelectListTest extends TestCase { + use InteractsWithSettings; + public function testUsersAreReturned() { $users = User::factory()->superuser()->count(3)->create(); diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php new file mode 100644 index 0000000000..0a7a9c53b6 --- /dev/null +++ b/tests/Support/InteractsWithSettings.php @@ -0,0 +1,8 @@ +withoutMiddleware($this->globallyDisabledMiddleware); - $this->settings = Settings::initialize(); + if (in_array(InteractsWithSettings::class, class_uses_recursive($this))) { + $this->settings = Settings::initialize(); + } } }