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:
67
tests/Unit/Models/UsageLogTest.php
Normal file
67
tests/Unit/Models/UsageLogTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\UsageLog;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UsageLogTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_create_a_usage_log_with_factory()
|
||||
{
|
||||
$usageLog = UsageLog::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(UsageLog::class, $usageLog);
|
||||
$this->assertIsInt($usageLog->emails_created_count);
|
||||
$this->assertIsInt($usageLog->emails_received_count);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_correct_fillable_attributes()
|
||||
{
|
||||
$usageLogData = [
|
||||
'user_id' => $this->user->id,
|
||||
'ip_address' => '192.168.1.1',
|
||||
'emails_created_count' => 5,
|
||||
'emails_received_count' => 10,
|
||||
'emails_created_history' => json_encode(['2023-01-01 12:00:00' => 3]),
|
||||
'emails_received_history' => json_encode(['2023-01-01 12:30:00' => 7]),
|
||||
];
|
||||
|
||||
$usageLog = UsageLog::create($usageLogData);
|
||||
|
||||
foreach ($usageLogData as $key => $value) {
|
||||
$this->assertEquals($value, $usageLog->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_belongs_to_a_user()
|
||||
{
|
||||
$usageLog = UsageLog::factory()->create(['user_id' => $this->user->id]);
|
||||
|
||||
$this->assertInstanceOf(User::class, $usageLog->user);
|
||||
$this->assertEquals($this->user->id, $usageLog->user->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_tracks_different_email_counts()
|
||||
{
|
||||
$usageLog = UsageLog::factory()->create([
|
||||
'emails_created_count' => 15,
|
||||
'emails_received_count' => 25,
|
||||
]);
|
||||
|
||||
$this->assertEquals(15, $usageLog->emails_created_count);
|
||||
$this->assertEquals(25, $usageLog->emails_received_count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user