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/SettingTest.php
Normal file
67
tests/Unit/Models/SettingTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_can_create_a_setting_with_factory()
|
||||
{
|
||||
$setting = Setting::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(Setting::class, $setting);
|
||||
$this->assertIsString($setting->app_name);
|
||||
$this->assertIsString($setting->app_version);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_has_correct_fillable_attributes()
|
||||
{
|
||||
$settingData = [
|
||||
'app_name' => 'ZEmailnator',
|
||||
'app_version' => '1.0.0',
|
||||
'app_base_url' => 'https://example.com',
|
||||
'app_admin' => 'admin@example.com',
|
||||
'app_title' => 'Test Title',
|
||||
];
|
||||
|
||||
$setting = Setting::create($settingData);
|
||||
|
||||
foreach ($settingData as $key => $value) {
|
||||
$this->assertEquals($value, $setting->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_stores_configuration_values()
|
||||
{
|
||||
$setting = Setting::factory()->create([
|
||||
'app_name' => 'Test App',
|
||||
'configuration_settings' => json_encode([
|
||||
'max_emails_per_user' => 100,
|
||||
'enable_registrations' => true,
|
||||
'default_language' => 'en',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->assertEquals('Test App', $setting->app_name);
|
||||
$this->assertIsString($setting->configuration_settings);
|
||||
$config = json_decode($setting->configuration_settings, true);
|
||||
$this->assertEquals(100, $config['max_emails_per_user']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_query_public_settings()
|
||||
{
|
||||
$setting1 = Setting::factory()->create(['app_name' => 'Public App']);
|
||||
$setting2 = Setting::factory()->create(['app_name' => 'Private App']);
|
||||
|
||||
$allSettings = Setting::all();
|
||||
|
||||
$this->assertCount(2, $allSettings);
|
||||
$this->assertIsString($allSettings->first()->app_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user