From 4e2105190b21e422fb0fb0489664e28ebf3dd502 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Fri, 10 Jul 2026 17:11:27 +0500 Subject: [PATCH] fix(tests): replace RefreshDatabase with DatabaseTransactions - Prevents local DB data loss when running 'php artisan test' - ViconApiConfigTest uses updateOrCreate to avoid unique constraint - Delete + Cache::flush for 'not configured' test case --- .../Tests/Feature/UpdatePartTest.php | 4 ++-- tests/Feature/Auth/AuthenticationTest.php | 4 ++-- tests/Feature/Auth/EmailVerificationTest.php | 4 ++-- tests/Feature/Auth/PasswordConfirmationTest.php | 4 ++-- tests/Feature/Auth/PasswordResetTest.php | 4 ++-- tests/Feature/Auth/PasswordUpdateTest.php | 4 ++-- tests/Feature/Auth/RegistrationTest.php | 4 ++-- tests/Feature/ProfileTest.php | 4 ++-- tests/Feature/Vicon/ViconApiConfigTest.php | 16 +++++++++------- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/Containers/VikonIntegration/Tests/Feature/UpdatePartTest.php b/app/Containers/VikonIntegration/Tests/Feature/UpdatePartTest.php index 9ed1913..2fee2f1 100644 --- a/app/Containers/VikonIntegration/Tests/Feature/UpdatePartTest.php +++ b/app/Containers/VikonIntegration/Tests/Feature/UpdatePartTest.php @@ -4,11 +4,11 @@ namespace App\Containers\VikonIntegration\Tests\Feature; use App\Containers\User\Models\User; use App\Ship\Tests\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; class UpdatePartTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; private function createUser(): User { diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index d36b1f7..99639d6 100755 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -4,12 +4,12 @@ namespace Tests\Feature\Auth; use App\Containers\User\Models\User; use App\Providers\RouteServiceProvider; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; class AuthenticationTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_login_screen_can_be_rendered(): void { diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index 447b11c..0541d5f 100755 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -5,14 +5,14 @@ namespace Tests\Feature\Auth; use App\Containers\User\Models\User; use App\Providers\RouteServiceProvider; use Illuminate\Auth\Events\Verified; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\URL; use Tests\TestCase; class EmailVerificationTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_email_verification_screen_can_be_rendered(): void { diff --git a/tests/Feature/Auth/PasswordConfirmationTest.php b/tests/Feature/Auth/PasswordConfirmationTest.php index 911f9d3..dc004c8 100755 --- a/tests/Feature/Auth/PasswordConfirmationTest.php +++ b/tests/Feature/Auth/PasswordConfirmationTest.php @@ -3,12 +3,12 @@ namespace Tests\Feature\Auth; use App\Containers\User\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; class PasswordConfirmationTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_confirm_password_screen_can_be_rendered(): void { diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php index 9c4c069..767f4d1 100755 --- a/tests/Feature/Auth/PasswordResetTest.php +++ b/tests/Feature/Auth/PasswordResetTest.php @@ -4,13 +4,13 @@ namespace Tests\Feature\Auth; use App\Containers\User\Models\User; use Illuminate\Auth\Notifications\ResetPassword; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Notification; use Tests\TestCase; class PasswordResetTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_reset_password_link_screen_can_be_rendered(): void { diff --git a/tests/Feature/Auth/PasswordUpdateTest.php b/tests/Feature/Auth/PasswordUpdateTest.php index caf88c3..bf331c4 100755 --- a/tests/Feature/Auth/PasswordUpdateTest.php +++ b/tests/Feature/Auth/PasswordUpdateTest.php @@ -3,13 +3,13 @@ namespace Tests\Feature\Auth; use App\Containers\User\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Hash; use Tests\TestCase; class PasswordUpdateTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_password_can_be_updated(): void { diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 30829b1..125f481 100755 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -3,12 +3,12 @@ namespace Tests\Feature\Auth; use App\Providers\RouteServiceProvider; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; class RegistrationTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_registration_screen_can_be_rendered(): void { diff --git a/tests/Feature/ProfileTest.php b/tests/Feature/ProfileTest.php index efc59c3..cb503b3 100755 --- a/tests/Feature/ProfileTest.php +++ b/tests/Feature/ProfileTest.php @@ -3,12 +3,12 @@ namespace Tests\Feature; use App\Containers\User\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; class ProfileTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; public function test_profile_page_is_displayed(): void { diff --git a/tests/Feature/Vicon/ViconApiConfigTest.php b/tests/Feature/Vicon/ViconApiConfigTest.php index 6fb4c45..4bd8da8 100644 --- a/tests/Feature/Vicon/ViconApiConfigTest.php +++ b/tests/Feature/Vicon/ViconApiConfigTest.php @@ -5,13 +5,13 @@ namespace Tests\Feature\Vicon; use App\Containers\Dashboard\Models\IntegrationCredential; use App\Services\Vicon\ViconApiConfig; use App\Ship\Enums\CacheKeys; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Cache; use Tests\TestCase; class ViconApiConfigTest extends TestCase { - use RefreshDatabase; + use DatabaseTransactions; protected function setUp(): void { @@ -21,11 +21,10 @@ class ViconApiConfigTest extends TestCase private function createCredential(array $payload, bool $active = true): void { - IntegrationCredential::create([ - 'provider' => 'vikon_api', - 'payload' => $payload, - 'is_active' => $active, - ]); + IntegrationCredential::updateOrCreate( + ['provider' => 'vikon_api'], + ['payload' => $payload, 'is_active' => $active], + ); } public function test_token_returns_value_from_db(): void @@ -57,6 +56,9 @@ class ViconApiConfigTest extends TestCase public function test_token_throws_when_not_configured(): void { + IntegrationCredential::where('provider', 'vikon_api')->delete(); + Cache::flush(); + $config = app(ViconApiConfig::class); $this->expectException(\RuntimeException::class);