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
This commit is contained in:
F4ilji
2026-07-10 17:11:27 +05:00
parent c59a08b3a0
commit 4e2105190b
9 changed files with 25 additions and 23 deletions
@@ -4,11 +4,11 @@ namespace App\Containers\VikonIntegration\Tests\Feature;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use App\Ship\Tests\TestCase; use App\Ship\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
class UpdatePartTest extends TestCase class UpdatePartTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
private function createUser(): User private function createUser(): User
{ {
+2 -2
View File
@@ -4,12 +4,12 @@ namespace Tests\Feature\Auth;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
class AuthenticationTest extends TestCase class AuthenticationTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_login_screen_can_be_rendered(): void public function test_login_screen_can_be_rendered(): void
{ {
+2 -2
View File
@@ -5,14 +5,14 @@ namespace Tests\Feature\Auth;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified; use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
use Tests\TestCase; use Tests\TestCase;
class EmailVerificationTest extends TestCase class EmailVerificationTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_email_verification_screen_can_be_rendered(): void public function test_email_verification_screen_can_be_rendered(): void
{ {
@@ -3,12 +3,12 @@
namespace Tests\Feature\Auth; namespace Tests\Feature\Auth;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
class PasswordConfirmationTest extends TestCase class PasswordConfirmationTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_confirm_password_screen_can_be_rendered(): void public function test_confirm_password_screen_can_be_rendered(): void
{ {
+2 -2
View File
@@ -4,13 +4,13 @@ namespace Tests\Feature\Auth;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Tests\TestCase; use Tests\TestCase;
class PasswordResetTest extends TestCase class PasswordResetTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_reset_password_link_screen_can_be_rendered(): void public function test_reset_password_link_screen_can_be_rendered(): void
{ {
+2 -2
View File
@@ -3,13 +3,13 @@
namespace Tests\Feature\Auth; namespace Tests\Feature\Auth;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Tests\TestCase; use Tests\TestCase;
class PasswordUpdateTest extends TestCase class PasswordUpdateTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_password_can_be_updated(): void public function test_password_can_be_updated(): void
{ {
+2 -2
View File
@@ -3,12 +3,12 @@
namespace Tests\Feature\Auth; namespace Tests\Feature\Auth;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
class RegistrationTest extends TestCase class RegistrationTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_registration_screen_can_be_rendered(): void public function test_registration_screen_can_be_rendered(): void
{ {
+2 -2
View File
@@ -3,12 +3,12 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Containers\User\Models\User; use App\Containers\User\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase; use Tests\TestCase;
class ProfileTest extends TestCase class ProfileTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
public function test_profile_page_is_displayed(): void public function test_profile_page_is_displayed(): void
{ {
+9 -7
View File
@@ -5,13 +5,13 @@ namespace Tests\Feature\Vicon;
use App\Containers\Dashboard\Models\IntegrationCredential; use App\Containers\Dashboard\Models\IntegrationCredential;
use App\Services\Vicon\ViconApiConfig; use App\Services\Vicon\ViconApiConfig;
use App\Ship\Enums\CacheKeys; use App\Ship\Enums\CacheKeys;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Tests\TestCase; use Tests\TestCase;
class ViconApiConfigTest extends TestCase class ViconApiConfigTest extends TestCase
{ {
use RefreshDatabase; use DatabaseTransactions;
protected function setUp(): void protected function setUp(): void
{ {
@@ -21,11 +21,10 @@ class ViconApiConfigTest extends TestCase
private function createCredential(array $payload, bool $active = true): void private function createCredential(array $payload, bool $active = true): void
{ {
IntegrationCredential::create([ IntegrationCredential::updateOrCreate(
'provider' => 'vikon_api', ['provider' => 'vikon_api'],
'payload' => $payload, ['payload' => $payload, 'is_active' => $active],
'is_active' => $active, );
]);
} }
public function test_token_returns_value_from_db(): void 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 public function test_token_throws_when_not_configured(): void
{ {
IntegrationCredential::where('provider', 'vikon_api')->delete();
Cache::flush();
$config = app(ViconApiConfig::class); $config = app(ViconApiConfig::class);
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);