Files
netslim-core/tests/Settings/SettingTest.php
2026-03-20 22:13:41 +01:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Settings;
use Netig\Netslim\Settings\Domain\Entity\Setting;
use PHPUnit\Framework\TestCase;
final class SettingTest extends TestCase
{
public function testSerializesAndRestoresTypedValues(): void
{
$setting = new Setting('site.enabled', true);
self::assertSame('bool', $setting->getType());
self::assertSame('1', $setting->toStorageValue());
$restored = Setting::fromStorage([
'setting_key' => 'site.enabled',
'setting_value' => '1',
'value_type' => 'bool',
]);
self::assertTrue($restored->getValue());
}
public function testRejectsEmptyKey(): void
{
$this->expectException(\InvalidArgumentException::class);
new Setting('', 'value');
}
public function testRejectsUnsupportedStoredType(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Type de paramètre stocké non supporté');
Setting::fromStorage([
'setting_key' => 'site.mode',
'setting_value' => 'legacy',
'value_type' => 'legacy-type',
]);
}
}