Fix test collisions that broke the full suite

Resolve name clashes that only surfaced when running the whole suite
together rather than files in isolation:

- Drop the redundant uses(TestCase::class) from two Feature tests; the
  TestCase binding already comes from tests/Pest.php, and binding it
  twice throws TestCaseAlreadyInUse.
- Rename the per-file seedFilter() helpers to seedCustomFilter() and
  seedUserFilter() so the two files no longer redeclare the same global
  function.
- Configure a captcha driver in two CaptchaManagerTest cases so they
  assert per-surface behaviour instead of the unconfigured-driver path.
pull/7824/head
Ashley 1 week ago
parent 2ecaaa9869
commit dfa054f60a

@ -5,9 +5,8 @@ use App\Models\User;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Laravel\Passport\Passport;
use Tests\TestCase;
uses(TestCase::class, LazilyRefreshDatabase::class);
uses(LazilyRefreshDatabase::class);
/*
|--------------------------------------------------------------------------

@ -34,7 +34,7 @@ function resetExpiredQuotaLimits(): void
}
}
function seedFilter(int $pid, string $title, string $keyword, ?Carbon $expiresAt): CustomFilter
function seedCustomFilter(int $pid, string $title, string $keyword, ?Carbon $expiresAt): CustomFilter
{
$filter = CustomFilter::create([
'profile_id' => $pid,
@ -80,7 +80,7 @@ it('does not count expired filters against the quota', function () {
$pid = $user->profile_id;
for ($i = 0; $i < $max; $i++) {
seedFilter($pid, 'expired-'.$i, 'expired'.$i, now()->subDay());
seedCustomFilter($pid, 'expired-'.$i, 'expired'.$i, now()->subDay());
}
Passport::actingAs($user, ['read', 'write']);
@ -106,7 +106,7 @@ it('still enforces the quota for unexpired filters', function () {
$pid = $user->profile_id;
for ($i = 0; $i < $max; $i++) {
seedFilter($pid, 'live-'.$i, 'live'.$i, now()->addWeek());
seedCustomFilter($pid, 'live-'.$i, 'live'.$i, now()->addWeek());
}
Passport::actingAs($user, ['read', 'write']);
@ -122,7 +122,7 @@ it('allows the policy create check to pass when all filters are expired', functi
$pid = $user->profile_id;
for ($i = 0; $i < 150; $i++) {
seedFilter($pid, 'expired-'.$i, 'policy'.$i, now()->subDay());
seedCustomFilter($pid, 'expired-'.$i, 'policy'.$i, now()->subDay());
}
expect($user->can('create', CustomFilter::class))->toBeTrue();

@ -134,6 +134,9 @@ class CaptchaManagerTest extends TestCase
{
config([
'captcha.enabled' => true,
'captcha.driver' => 'hcaptcha',
'captcha.hcaptcha.secret' => 'a-real-secret',
'captcha.hcaptcha.sitekey' => 'a-real-sitekey',
'captcha.active.login' => true,
'captcha.active.register' => false,
'captcha.active.forgot_password' => true,
@ -155,7 +158,12 @@ class CaptchaManagerTest extends TestCase
#[Test]
public function active_on_returns_false_for_an_unknown_surface(): void
{
config(['captcha.enabled' => true]);
config([
'captcha.enabled' => true,
'captcha.driver' => 'hcaptcha',
'captcha.hcaptcha.secret' => 'a-real-secret',
'captcha.hcaptcha.sitekey' => 'a-real-sitekey',
]);
$this->assertFalse($this->manager()->activeOn('does_not_exist'));
}

@ -6,9 +6,8 @@ use App\Models\User;
use App\Services\FollowerService;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\View;
use Tests\TestCase;
uses(TestCase::class, LazilyRefreshDatabase::class);
uses(LazilyRefreshDatabase::class);
beforeEach(function () {
// Resolve views from the tree this test lives in, so the permalink page

@ -26,7 +26,7 @@ uses(LazilyRefreshDatabase::class);
const LEGACY_TYPE = 'App\Profile';
function seedFilter(int $userId, int $targetId, string $filterType, string $type): UserFilter
function seedUserFilter(int $userId, int $targetId, string $filterType, string $type): UserFilter
{
$filter = new UserFilter;
$filter->user_id = $userId;
@ -51,8 +51,8 @@ describe('legacy App\Profile rows', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
seedFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
$rel = RelationshipService::refresh($user->profile_id, $target->profile_id);
@ -66,7 +66,7 @@ describe('legacy App\Profile rows', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
Passport::actingAs($user, ['write']);
$this->postJson("/api/v1/accounts/{$target->profile_id}/unblock")
@ -85,7 +85,7 @@ describe('legacy App\Profile rows', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
Passport::actingAs($user, ['write']);
$this->postJson("/api/v1/accounts/{$target->profile_id}/unmute")
@ -106,8 +106,8 @@ describe('legacy App\Profile rows', function () {
$muted = User::factory()->create();
$muted->refresh();
seedFilter($user->profile_id, $blocked->profile_id, 'block', LEGACY_TYPE);
seedFilter($user->profile_id, $muted->profile_id, 'mute', LEGACY_TYPE);
seedUserFilter($user->profile_id, $blocked->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $muted->profile_id, 'mute', LEGACY_TYPE);
$profile = Profile::find($user->profile_id);
@ -123,7 +123,7 @@ describe('warm cache eviction on legacy row removal', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'block', LEGACY_TYPE);
expect(collect(UserFilterService::blocks($user->profile_id))->map(fn ($i) => (string) $i))
->toContain((string) $target->profile_id);
@ -143,7 +143,7 @@ describe('warm cache eviction on legacy row removal', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
seedUserFilter($user->profile_id, $target->profile_id, 'mute', LEGACY_TYPE);
expect(collect(UserFilterService::mutes($user->profile_id))->map(fn ($i) => (string) $i))
->toContain((string) $target->profile_id);
@ -165,7 +165,7 @@ describe('modern App\Models\Profile control', function () {
$target = User::factory()->create();
$target->refresh();
seedFilter($user->profile_id, $target->profile_id, 'block', Profile::class);
seedUserFilter($user->profile_id, $target->profile_id, 'block', Profile::class);
$rel = RelationshipService::refresh($user->profile_id, $target->profile_id);
expect($rel['blocking'])->toBeTrue();
@ -194,14 +194,14 @@ describe('legacy morph normalization migration', function () {
$distinct->refresh();
// lone legacy row with no modern twin
seedFilter($user->profile_id, $lone->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $lone->profile_id, 'block', LEGACY_TYPE);
// legacy row colliding with an existing modern row on the unique tuple
$legacyCollision = seedFilter($user->profile_id, $collide->profile_id, 'block', LEGACY_TYPE);
seedFilter($user->profile_id, $collide->profile_id, 'block', Profile::class);
$legacyCollision = seedUserFilter($user->profile_id, $collide->profile_id, 'block', LEGACY_TYPE);
seedUserFilter($user->profile_id, $collide->profile_id, 'block', Profile::class);
// distinct legacy row (mute) that must survive untouched in value
seedFilter($user->profile_id, $distinct->profile_id, 'mute', LEGACY_TYPE);
seedUserFilter($user->profile_id, $distinct->profile_id, 'mute', LEGACY_TYPE);
runMorphNormalization();

Loading…
Cancel
Save