A free open source IT asset/license management system
Introduce trait to conditionally interact with settings
Marcus Moore7c95e4517876
diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.phpindex 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.phpindex 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.phpnew file mode 100644index 0000000000..0a7a9c53b6--- /dev/null+++ b/tests/Support/InteractsWithSettings.php@@ -0,0 +1,8 @@+<?php++namespace Tests\Support;++trait InteractsWithSettings+{++}diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 6ab34ba485..c8dd661787 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -5,6 +5,7 @@ namespace Tests;use App\Http\Middleware\SecurityHeaders;use Illuminate\Foundation\Testing\LazilyRefreshDatabase;use Illuminate\Foundation\Testing\TestCase as BaseTestCase;+use Tests\Support\InteractsWithSettings;use Tests\Support\Settings;abstract class TestCase extends BaseTestCase@@ -24,6 +25,8 @@ abstract class TestCase extends BaseTestCase$this->withoutMiddleware($this->globallyDisabledMiddleware);- $this->settings = Settings::initialize();+ if (in_array(InteractsWithSettings::class, class_uses_recursive($this))) {+ $this->settings = Settings::initialize();+ }}}