fix: resolve PSR-4 autoloading and test failures

- 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
This commit is contained in:
idevakk
2025-11-13 09:49:21 -08:00
parent 68ef391c5d
commit 3706072ce5
38 changed files with 863 additions and 680 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace Tests\Unit\Models;
use App\Models\RemoteEmail;
use Carbon\Carbon;
use Tests\TestCase;
class RemoteEmailTest extends TestCase
{
/** @test */
public function it_can_create_a_remote_email_with_factory()
{
$remoteEmail = RemoteEmail::factory()->create();
$this->assertInstanceOf(RemoteEmail::class, $remoteEmail);
$this->assertIsArray($remoteEmail->to);
$this->assertIsString($remoteEmail->from_email);
}
/** @test */
public function it_has_correct_fillable_attributes()
{
$timestamp = now();
$remoteEmailData = [
'message_id' => 'remote_123',
'subject' => 'Remote Email Subject',
'from_name' => 'Remote Sender',
'from_email' => 'remote@example.com',
'to' => ['recipient@example.com'],
'body_html' => '<p>HTML content</p>',
'body_text' => 'Text content',
'is_seen' => false,
'timestamp' => $timestamp,
];
$remoteEmail = RemoteEmail::create($remoteEmailData);
foreach ($remoteEmailData as $key => $value) {
if ($key === 'timestamp') {
$this->assertInstanceOf(Carbon::class, $remoteEmail->$key);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->$key->format('Y-m-d H:i:s'));
} else {
$this->assertEquals($value, $remoteEmail->$key);
}
}
}
/** @test */
public function it_casts_to_field_to_array()
{
$to = ['test1@example.com', 'test2@example.com'];
$remoteEmail = RemoteEmail::factory()->create(['to' => $to]);
$this->assertIsArray($remoteEmail->to);
$this->assertEquals($to, $remoteEmail->to);
}
/** @test */
public function it_casts_timestamp_to_datetime()
{
$timestamp = now();
$remoteEmail = RemoteEmail::factory()->create(['timestamp' => $timestamp]);
$this->assertInstanceOf(Carbon::class, $remoteEmail->timestamp);
$this->assertEquals($timestamp->format('Y-m-d H:i:s'), $remoteEmail->timestamp->format('Y-m-d H:i:s'));
}
}