From 6d594faae7510719d01793593fddf12cfef77c74 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 1 May 2023 16:04:43 -0700 Subject: [PATCH 1/3] Clear the settings cache on app destruction --- tests/Support/InteractsWithSettings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php index 1de9e7bc13..aae1aab9d9 100644 --- a/tests/Support/InteractsWithSettings.php +++ b/tests/Support/InteractsWithSettings.php @@ -2,6 +2,8 @@ namespace Tests\Support; +use App\Models\Setting; + trait InteractsWithSettings { protected Settings $settings; @@ -9,5 +11,7 @@ trait InteractsWithSettings public function setUpSettings() { $this->settings = Settings::initialize(); + + $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); } } From da08f6ef8cd3398d3fe09c3b642427812ebd0626 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 1 May 2023 16:05:26 -0700 Subject: [PATCH 2/3] Add InteractsWithSettings trait to required tests --- tests/Unit/AssetMaintenanceTest.php | 3 +++ tests/Unit/AssetModelTest.php | 3 +++ tests/Unit/AssetTest.php | 3 +++ tests/Unit/CategoryTest.php | 3 +++ tests/Unit/ComponentTest.php | 3 +++ tests/Unit/DepreciationTest.php | 3 +++ tests/Unit/NotificationTest.php | 3 +++ tests/Unit/SnipeModelTest.php | 3 +++ 8 files changed, 24 insertions(+) diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index 31b68c0cf5..b5ee25cf2b 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 7050ea307d..8771187b2a 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 e4dc8a803f..432165dc07 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 387ed946e0..c74597b1b4 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 df8f64771f..8f71057bfc 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 4dd8422276..ed033cf442 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 8005759a1e..64cf8afb0a 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 2bc81da61b..ad4231010f 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; From f7d2b62d875c9c8f348b896a5e114243f5f5ceb2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 1 May 2023 16:06:28 -0700 Subject: [PATCH 3/3] Improve method name --- tests/Support/InteractsWithSettings.php | 2 +- tests/TestCase.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Support/InteractsWithSettings.php b/tests/Support/InteractsWithSettings.php index aae1aab9d9..a8c0070188 100644 --- a/tests/Support/InteractsWithSettings.php +++ b/tests/Support/InteractsWithSettings.php @@ -8,7 +8,7 @@ trait InteractsWithSettings { protected Settings $settings; - public function setUpSettings() + public function initializeSettings() { $this->settings = Settings::initialize(); diff --git a/tests/TestCase.php b/tests/TestCase.php index e3fd8a7aa4..28051c7c7f 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(); } } }