It fixes the remaining stale test and keeps the actual N+1 strategy:

* Main ticket index renders scalar agent_name.
* Ticket index still eager-loads user, owner, agent.
* Ticket show comments no longer eager-load fake owner / agent relations.
* Updated the conflicting regression tests.
This commit is contained in:
Mark Gregory
2026-06-26 12:07:09 +01:00
parent 788bb87b01
commit 86f0082a84
12 changed files with 94 additions and 18 deletions
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Feature;
use Tests\TestCase;
final class TicketIndexDirectUserNPlusOneFilesTest extends TestCase
{
public function test_ticket_index_eager_loads_direct_user_relation(): void
{
$source = file_get_contents(dirname(__DIR__, 2) . '/Livewire/TicketIndex.php');
self::assertIsString($source);
self::assertStringContainsString("->with(['user:id,name,email', 'owner:id,name,email', 'agent:id,name,email', 'status', 'priority', 'category', 'project', 'team'])", $source);
self::assertStringNotContainsString("->with(['owner', 'agent', 'status', 'priority', 'category', 'project', 'team'])", $source);
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Feature;
use Tests\TestCase;
final class TicketIndexUserNPlusOneFilesTest extends TestCase
{
public function test_ticket_index_uses_scalar_agent_name_and_eager_loads_ticket_users(): void
{
$component = file_get_contents(dirname(__DIR__, 2) . '/Livewire/TicketIndex.php');
$view = file_get_contents(dirname(__DIR__, 2) . '/Resources/views/livewire/ticket-index.blade.php');
self::assertIsString($component);
self::assertIsString($view);
self::assertStringContainsString("->select('helpdesk_tickets.*')", $component);
self::assertStringContainsString("'agent_name' => User::query()", $component);
self::assertStringContainsString("->whereColumn('users.id', 'helpdesk_tickets.agent_id')", $component);
self::assertStringContainsString("->with(['user:id,name,email', 'owner:id,name,email', 'agent:id,name,email', 'status', 'priority', 'category', 'project', 'team'])", $component);
self::assertStringContainsString('$ticket->agent_name ?? \'Unassigned\'', $view);
self::assertStringNotContainsString('$ticket->agent?->name ?? \'Unassigned\'', $view);
}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Feature;
use Tests\TestCase;
final class TicketShowCommentRelationsFilesTest extends TestCase
{
public function test_ticket_show_only_eager_loads_real_comment_relations(): void
{
$source = file_get_contents(dirname(__DIR__, 2) . '/Livewire/TicketShow.php');
self::assertIsString($source);
self::assertStringContainsString("->with(['user.company', 'attachments'])", $source);
self::assertStringNotContainsString("->with(['user.company', 'owner:id,name,email,company_id', 'agent:id,name,email', 'attachments'])", $source);
}
}
@@ -10,9 +10,9 @@ final class TicketUserNPlusOneFilesTest extends TestCase
{
public function test_ticket_collection_queries_eager_load_user_owner_and_agent(): void
{
$index = file_get_contents(module_path('Helpdesk', 'Livewire/TicketIndex.php'));
$kanban = file_get_contents(module_path('Helpdesk', 'Livewire/KanbanBoard.php'));
$dashboard = file_get_contents(module_path('Helpdesk', 'Livewire/HelpdeskDashboardWidget.php'));
$index = file_get_contents(dirname(__DIR__, 2) . '/Livewire/TicketIndex.php');
$kanban = file_get_contents(dirname(__DIR__, 2) . '/Livewire/KanbanBoard.php');
$dashboard = file_get_contents(dirname(__DIR__, 2) . '/Livewire/HelpdeskDashboardWidget.php');
self::assertIsString($index);
self::assertIsString($kanban);