<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/common/QrbEnvironment.php';

use PHPUnit\Framework\TestCase;

final class QrbEnvironmentTest extends TestCase
{
    private QrbEnvironment $qrbEnv;
    
    protected function setUp(): void
    {
        $this->qrbEnv = new QrbEnvironment();
    }
    
    public function testGetSupportedLanguages()
    {
        $this->assertEquals(array("de", "fr", "it", "en"), 
                            QrbEnvironment::getSupportedLanguages());
    }
    
    public function testReadDefaultAndToString() : void
    {
        $this->assertEquals(10, $this->qrbEnv->getMaxRunsToKeep());
        $this->assertEquals(QrbEnvironment::DEFAULT_PROFILE, $this->qrbEnv->getCurrentProfile());
        echo $this->qrbEnv . "\n"; 
    }    
    
    public function testSetMaxRunsToKeep() : void
    {
        // save
        $save = $this->qrbEnv->getMaxRunsToKeep();
        $this->assertEquals(10, $save);
        
        try
        {
            $this->qrbEnv->setMaxRunsToKeep(11);
            $this->assertEquals(11, $this->qrbEnv->getMaxRunsToKeep());
        }
        finally
        {
            // restore
            $this->qrbEnv->setMaxRunsToKeep($save);
            $this->assertEquals(10, $this->qrbEnv->getMaxRunsToKeep());
        }
    }
    
    public function testSetCurrentProfile() : void
    {
        // save
        $save = $this->qrbEnv->getCurrentProfile();
        $this->assertEquals(QrbEnvironment::DEFAULT_PROFILE, $save);
        
        try
        {
            $this->qrbEnv->setCurrentProfile("Test");
            $this->assertEquals("Test", $this->qrbEnv->getCurrentProfile());
        }
        finally
        {
            // restore
            $this->qrbEnv->setCurrentProfile($save);
            $this->assertEquals(QrbEnvironment::DEFAULT_PROFILE, $save);
        }
    }
}

?>
