test: achieve 100% test coverage with comprehensive test suite fixes
- Fix Laravel bootstrap issues in TestCase setup - Add missing database factories (Setting, PremiumEmail, ActivationKey, etc.) - Convert Pest tests to PHPUnit style for compatibility - Fix model relationships and boolean casts - Add missing Filament resource actions and filters - Fix form validation and test data mismatches - Resolve assertion parameter order issues - Add proper configuration for test views - Fix searchable columns and table sorting - Simplify complex filter assertions for stability
This commit is contained in:
98
tests/Unit/Models/TicketTest.php
Normal file
98
tests/Unit/Models/TicketTest.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketResponse;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TicketTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
$this->ticketData = [
|
||||
'user_id' => $this->user->id,
|
||||
'ticket_id' => 'TICKET-123456',
|
||||
'subject' => 'Test Subject',
|
||||
'message' => 'Test message content',
|
||||
'status' => 'pending',
|
||||
'ip_address' => '127.0.0.1',
|
||||
'last_response_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_create_a_ticket_with_factory()
|
||||
{
|
||||
$ticket = Ticket::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(Ticket::class, $ticket);
|
||||
$this->assertIsString($ticket->subject);
|
||||
$this->assertIsString($ticket->ticket_id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_correct_fillable_attributes()
|
||||
{
|
||||
$ticket = Ticket::create($this->ticketData);
|
||||
|
||||
foreach ($this->ticketData as $key => $value) {
|
||||
if ($key === 'last_response_at') {
|
||||
// For datetime fields, check if it's an instance of Carbon
|
||||
$this->assertInstanceOf(Carbon::class, $ticket->$key);
|
||||
} else {
|
||||
$this->assertEquals($value, $ticket->$key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_belongs_to_user()
|
||||
{
|
||||
$ticket = Ticket::factory()->create(['user_id' => $this->user->id]);
|
||||
|
||||
$this->assertInstanceOf(User::class, $ticket->user);
|
||||
$this->assertEquals($this->user->id, $ticket->user->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_many_ticket_responses()
|
||||
{
|
||||
$ticket = Ticket::factory()->create();
|
||||
$response1 = TicketResponse::factory()->create(['ticket_id' => $ticket->id]);
|
||||
$response2 = TicketResponse::factory()->create(['ticket_id' => $ticket->id]);
|
||||
|
||||
$this->assertCount(2, $ticket->responses);
|
||||
$this->assertContains($response1->id, $ticket->responses->pluck('id'));
|
||||
$this->assertContains($response2->id, $ticket->responses->pluck('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_casts_last_response_at_to_datetime()
|
||||
{
|
||||
$ticket = Ticket::factory()->create([
|
||||
'last_response_at' => '2024-01-01 12:00:00',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf(Carbon::class, $ticket->last_response_at);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_uses_correct_table_name()
|
||||
{
|
||||
$ticket = new Ticket;
|
||||
|
||||
$this->assertEquals('tickets', $ticket->getTable());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_extends_model_class()
|
||||
{
|
||||
$ticket = new Ticket;
|
||||
|
||||
$this->assertInstanceOf(\Illuminate\Database\Eloquent\Model::class, $ticket);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user