diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php index 1de9e7bc1..a8c007018 100644 --- a/tests/Support/InteractsWithSettings.php +++ b/tests/Support/InteractsWithSettings.php @@ -2,12 +2,16 @@ namespace Tests\Support; +use App\Models\Setting; + trait InteractsWithSettings { protected Settings $settings; - public function setUpSettings() + public function initializeSettings() { $this->settings = Settings::initialize(); + + $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index e3fd8a7aa..28051c7c7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -23,7 +23,7 @@ abstract class TestCase extends BaseTestCase $this->withoutMiddleware($this->globallyDisabledMiddleware); if (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) { - $this->setUpSettings(); + $this->initializeSettings(); } } } diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index 31b68c0cf..b5ee25cf2 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -3,10 +3,13 @@ namespace Tests\Unit; use App\Models\AssetMaintenance; use Carbon\Carbon; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetMaintenanceTest extends TestCase { + use InteractsWithSettings; + public function testZerosOutWarrantyIfBlank() { $c = new AssetMaintenance; diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php index 7050ea307..8771187b2 100644 --- a/tests/Unit/AssetModelTest.php +++ b/tests/Unit/AssetModelTest.php @@ -4,10 +4,13 @@ namespace Tests\Unit; use App\Models\Asset; use App\Models\Category; use App\Models\AssetModel; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetModelTest extends TestCase { + use InteractsWithSettings; + public function testAnAssetModelZerosOutBlankEols() { $am = new AssetModel; diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index e4dc8a803..432165dc0 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -5,10 +5,13 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; use Carbon\Carbon; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class AssetTest extends TestCase { + use InteractsWithSettings; + // public function testAutoIncrementMixed() // { // $expected = '123411'; diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index 387ed946e..c74597b1b 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -4,10 +4,13 @@ namespace Tests\Unit; use App\Models\Category; use App\Models\AssetModel; use App\Models\Asset; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class CategoryTest extends TestCase { + use InteractsWithSettings; + public function testFailsEmptyValidation() { // An Asset requires a name, a qty, and a category_id. diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php index df8f64771..8f71057bf 100644 --- a/tests/Unit/ComponentTest.php +++ b/tests/Unit/ComponentTest.php @@ -5,10 +5,13 @@ use App\Models\Category; use App\Models\Company; use App\Models\Component; use App\Models\Location; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class ComponentTest extends TestCase { + use InteractsWithSettings; + public function testAComponentBelongsToACompany() { $component = Component::factory() diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 4dd842227..ed033cf44 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -5,10 +5,13 @@ use App\Models\Depreciation; use App\Models\Category; use App\Models\License; use App\Models\AssetModel; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class DepreciationTest extends TestCase { + use InteractsWithSettings; + public function testADepreciationHasModels() { $depreciation = Depreciation::factory()->create(); diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 8005759a1..64cf8afb0 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -8,10 +8,13 @@ use App\Models\Category; use Carbon\Carbon; use App\Notifications\CheckoutAssetNotification; use Illuminate\Support\Facades\Notification; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class NotificationTest extends TestCase { + use InteractsWithSettings; + public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { $admin = User::factory()->superuser()->create(); diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php index 2bc81da61..ad4231010 100644 --- a/tests/Unit/SnipeModelTest.php +++ b/tests/Unit/SnipeModelTest.php @@ -2,10 +2,13 @@ namespace Tests\Unit; use App\Models\SnipeModel; +use Tests\Support\InteractsWithSettings; use Tests\TestCase; class SnipeModelTest extends TestCase { + use InteractsWithSettings; + public function testSetsPurchaseDatesAppropriately() { $c = new SnipeModel;