Use LazilyRefreshDatabase instead of plain RefreshDatabase in tests

Aligns with the app's dominant convention (84 files vs 10). Avoids
running migrations for tests that never touch the database.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
pull/7194/head
Your Name 2 weeks ago
parent 140221fe90
commit 255bdaa2a0

@ -4,14 +4,14 @@ namespace Tests\Feature;
use App\Models\User; use App\Models\User;
use Database\Factories\ProfileFactory; use Database\Factories\ProfileFactory;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase; use Tests\TestCase;
class ComposeControllerTest extends TestCase class ComposeControllerTest extends TestCase
{ {
use RefreshDatabase; use LazilyRefreshDatabase;
#[Test] #[Test]
public function search_location_can_filter_by_country() public function search_location_can_filter_by_country()

@ -1,10 +1,10 @@
<?php <?php
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

@ -1,9 +1,9 @@
<?php <?php
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

@ -1,9 +1,9 @@
<?php <?php
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

@ -4,7 +4,7 @@ use App\Models\Page;
use App\Models\Status; use App\Models\Status;
use App\Models\User; use App\Models\User;
use App\Models\UserSetting; use App\Models\UserSetting;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -41,7 +41,7 @@ test('discover page respects public config', function () {
}); });
describe('routes that require database', function () { describe('routes that require database', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
test('register page loads', function () { test('register page loads', function () {
$this->get('/register') $this->get('/register')
@ -92,7 +92,7 @@ describe('routes that require database', function () {
*/ */
describe('guest profile page (regression: cached UserSetting model)', function () { describe('guest profile page (regression: cached UserSetting model)', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
it('renders a public profile for an unauthenticated user', function () { it('renders a public profile for an unauthenticated user', function () {
$user = User::factory()->create(); $user = User::factory()->create();
@ -130,7 +130,7 @@ describe('guest profile page (regression: cached UserSetting model)', function (
}); });
describe('static site pages (regression: cached Page model)', function () { describe('static site pages (regression: cached Page model)', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
it('loads terms of use twice', function () { it('loads terms of use twice', function () {
$this->get('/site/terms')->assertStatus(200); $this->get('/site/terms')->assertStatus(200);
@ -211,7 +211,7 @@ describe('static informational pages load for guests', function () {
}); });
describe('community guidelines page (regression: cached page render)', function () { describe('community guidelines page (regression: cached page render)', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
it('loads the fallback twice', function () { it('loads the fallback twice', function () {
// No Page row exists; the route caches the rendered view either way. // No Page row exists; the route caches the rendered view either way.
@ -238,7 +238,7 @@ describe('community guidelines page (regression: cached page render)', function
}); });
describe('public status page (regression: cached status/media services)', function () { describe('public status page (regression: cached status/media services)', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
it('renders a public post for a guest on repeated requests', function () { it('renders a public post for a guest on repeated requests', function () {
$user = User::factory()->create(); $user = User::factory()->create();
@ -262,7 +262,7 @@ describe('public status page (regression: cached status/media services)', functi
}); });
describe('profile activitypub object (regression: cached AP object)', function () { describe('profile activitypub object (regression: cached AP object)', function () {
uses(RefreshDatabase::class); uses(LazilyRefreshDatabase::class);
beforeEach(function () { beforeEach(function () {
// config_cache() falls back to config() when the DB-backed config // config_cache() falls back to config() when the DB-backed config

@ -4,7 +4,7 @@ namespace Tests\Feature;
use App\Models\RemoteAuthInstance; use App\Models\RemoteAuthInstance;
use App\Services\Account\RemoteAuthService; use App\Services\Account\RemoteAuthService;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
@ -12,7 +12,7 @@ use Tests\TestCase;
class RemoteAuthServiceTest extends TestCase class RemoteAuthServiceTest extends TestCase
{ {
use RefreshDatabase; use LazilyRefreshDatabase;
private function activeInstance(string $domain = 'mastodon.example'): RemoteAuthInstance private function activeInstance(string $domain = 'mastodon.example'): RemoteAuthInstance
{ {

@ -5,7 +5,7 @@ namespace Tests\Feature;
use App\Models\User; use App\Models\User;
use App\Models\UserOidcMapping; use App\Models\UserOidcMapping;
use App\Services\UserOidcService; use App\Services\UserOidcService;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use League\OAuth2\Client\Provider\GenericResourceOwner; use League\OAuth2\Client\Provider\GenericResourceOwner;
@ -17,8 +17,8 @@ use Tests\TestCase;
class RemoteOidcTest extends TestCase class RemoteOidcTest extends TestCase
{ {
use LazilyRefreshDatabase;
use MockeryPHPUnitIntegration; use MockeryPHPUnitIntegration;
use RefreshDatabase;
#[Test] #[Test]
public function view_oidc_start() public function view_oidc_start()

@ -3,7 +3,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Status; use App\Models\Status;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase; use Tests\TestCase;
@ -23,7 +23,7 @@ use Tests\TestCase;
class SeasonalAggregationTest extends TestCase class SeasonalAggregationTest extends TestCase
{ {
use RefreshDatabase; use LazilyRefreshDatabase;
/** /**
* Mirrors the aggregation used in SeasonalController::getData for * Mirrors the aggregation used in SeasonalController::getData for

@ -8,7 +8,7 @@ use App\Models\MediaTag;
use App\Models\Notification; use App\Models\Notification;
use App\Models\Status; use App\Models\Status;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase; use Tests\TestCase;
@ -27,7 +27,7 @@ use Tests\TestCase;
class StatusDeleteCleanupTest extends TestCase class StatusDeleteCleanupTest extends TestCase
{ {
use RefreshDatabase; use LazilyRefreshDatabase;
#[Test] #[Test]
public function deleting_a_status_removes_associated_dms_and_their_notifications() public function deleting_a_status_removes_associated_dms_and_their_notifications()

@ -6,7 +6,7 @@ use App\Jobs\CuratedOnboarding\CuratedOnboardingNotifyAdminNewApplicationPipelin
use App\Mail\CuratedRegisterNotifyAdmin; use App\Mail\CuratedRegisterNotifyAdmin;
use App\Models\CuratedRegister; use App\Models\CuratedRegister;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
@ -14,7 +14,7 @@ use Tests\TestCase;
class CuratedOnboardingNotifyAdminTest extends TestCase class CuratedOnboardingNotifyAdminTest extends TestCase
{ {
use RefreshDatabase; use LazilyRefreshDatabase;
protected function setUp(): void protected function setUp(): void
{ {

Loading…
Cancel
Save