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:
59
tests/Unit/Models/MetaTest.php
Normal file
59
tests/Unit/Models/MetaTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\Meta;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MetaTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_can_create_a_meta_with_factory()
|
||||
{
|
||||
$meta = Meta::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(Meta::class, $meta);
|
||||
$this->assertIsString($meta->key);
|
||||
$this->assertIsString($meta->value);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_correct_fillable_attributes()
|
||||
{
|
||||
$metaData = [
|
||||
'key' => 'total_emails_created',
|
||||
'value' => '1500',
|
||||
];
|
||||
|
||||
$meta = Meta::create($metaData);
|
||||
|
||||
foreach ($metaData as $key => $value) {
|
||||
$this->assertEquals($value, $meta->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_stores_key_value_pairs_correctly()
|
||||
{
|
||||
$meta = Meta::factory()->create([
|
||||
'key' => 'app_version',
|
||||
'value' => '1.2.3',
|
||||
]);
|
||||
|
||||
$this->assertEquals('app_version', $meta->key);
|
||||
$this->assertEquals('1.2.3', $meta->value);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_retrieve_value_by_key()
|
||||
{
|
||||
Meta::factory()->create(['key' => 'site_name', 'value' => 'ZEmailnator']);
|
||||
Meta::factory()->create(['key' => 'max_emails', 'value' => '100']);
|
||||
|
||||
$siteName = Meta::where('key', 'site_name')->first();
|
||||
$maxEmails = Meta::where('key', 'max_emails')->first();
|
||||
|
||||
$this->assertEquals('ZEmailnator', $siteName->value);
|
||||
$this->assertEquals('100', $maxEmails->value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user