<?php
declare(strict_types=1);

namespace FreshCloud\Mail\Config\Tests;

use PHPUnit\Framework\TestCase;
use FreshCloud\Mail\Config\ArrayConfig;
use FreshCloud\Mail\Config\EnvConfig;

final class ConfigTest extends TestCase
{
    public function testArrayConfigGetSet(): void
    {
        $config = new ArrayConfig(['foo' => 'bar']);
        $this->assertSame('bar', $config->get('foo'));
        $config->set('bar', 'baz');
        $this->assertSame('baz', $config->get('bar'));
    }

    public function testArrayConfigHas(): void
    {
        $config = new ArrayConfig(['foo' => 'bar']);
        $this->assertTrue($config->has('foo'));
        $this->assertFalse($config->has('baz'));
    }

    public function testArrayConfigAll(): void
    {
        $config = new ArrayConfig(['foo' => 'bar', 'baz' => 'qux']);
        $this->assertSame(['foo' => 'bar', 'baz' => 'qux'], $config->all());
    }

    public function testEnvConfig(): void
    {
        putenv('TEST_ENV_VALUE=123');
        $config = new EnvConfig('TEST_');
        $this->assertSame('123', $config->get('ENV_VALUE'));
        $config->set('NEW_KEY', '456');
        $this->assertSame('456', $config->get('NEW_KEY'));
        $this->assertTrue($config->has('ENV_VALUE'));
        putenv('TEST_ENV_VALUE');
    }
}