- Add proper Tests\ namespace to all test classes in tests/Feature and tests/Unit - Split RemainingModelsTest.php into separate files (PSR-4 compliance) - Create missing factories: MetaFactory, RemoteEmailFactory - Add HasFactory trait to RemoteEmail model - Add missing ReflectionClass imports to test files - Fix mass assignment issues in Meta and RemoteEmail models - Override database connection for RemoteEmail in testing environment - Fix DateTime comparison precision issues in tests
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Models;
|
|
|
|
use App\Models\Message;
|
|
use Carbon\Carbon;
|
|
use Tests\TestCase;
|
|
|
|
class MessageTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function it_can_create_a_message_with_factory()
|
|
{
|
|
$message = Message::factory()->create();
|
|
|
|
$this->assertInstanceOf(Message::class, $message);
|
|
$this->assertIsString($message->subject);
|
|
$this->assertIsString($message->from);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_has_correct_fillable_attributes()
|
|
{
|
|
$messageData = [
|
|
'subject' => 'Test Message',
|
|
'from' => 'Test Sender <sender@example.com>',
|
|
'to' => 'recipient@example.com',
|
|
'body' => 'Test body content',
|
|
'attachments' => null,
|
|
'is_seen' => false,
|
|
];
|
|
|
|
$message = Message::create($messageData);
|
|
|
|
foreach ($messageData as $key => $value) {
|
|
$this->assertEquals($value, $message->$key);
|
|
}
|
|
}
|
|
|
|
/** @test */
|
|
public function it_stores_to_field_as_string()
|
|
{
|
|
$to = 'test1@example.com';
|
|
$message = Message::factory()->create(['to' => $to]);
|
|
|
|
$this->assertIsString($message->to);
|
|
$this->assertEquals($to, $message->to);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_uses_created_at_as_timestamp()
|
|
{
|
|
$message = Message::factory()->create();
|
|
|
|
$this->assertInstanceOf(Carbon::class, $message->created_at);
|
|
$this->assertNotNull($message->created_at);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_can_query_unseen_messages()
|
|
{
|
|
$unseenMessage = Message::factory()->create(['is_seen' => false]);
|
|
$seenMessage = Message::factory()->create(['is_seen' => true]);
|
|
|
|
$unseenMessages = Message::where('is_seen', false)->get();
|
|
$seenMessages = Message::where('is_seen', true)->get();
|
|
|
|
$this->assertCount(1, $unseenMessages);
|
|
$this->assertCount(1, $seenMessages);
|
|
}
|
|
} |