first commit
This commit is contained in:
45
tests/Settings/SettingTest.php
Normal file
45
tests/Settings/SettingTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user