56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
|
<?php
|
||
|
/* FlatArray | https://gitlab.com/byjoby/flatarray | MIT License */
|
||
|
declare(strict_types=1);
|
||
|
namespace FlatArray\Config;
|
||
|
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use Symfony\Component\Yaml\Yaml;
|
||
|
|
||
|
class ConfigTest extends TestCase
|
||
|
{
|
||
|
public function testVariables()
|
||
|
{
|
||
|
//single level of variable
|
||
|
$c = new Config();
|
||
|
$c['a.b'] = 'a';
|
||
|
$c['c'] = '${a.b}';
|
||
|
$this->assertEquals('a', $c['c']);
|
||
|
//variable referencing another variable
|
||
|
$c['d'] = '${c}';
|
||
|
$this->assertEquals('a', $c['d']);
|
||
|
}
|
||
|
|
||
|
public function testReading()
|
||
|
{
|
||
|
$data = [
|
||
|
'a' => 'b',
|
||
|
'c' => [
|
||
|
'd' => 'e'
|
||
|
]
|
||
|
];
|
||
|
//json
|
||
|
$a = new Config();
|
||
|
$a->readFile(__DIR__.'/configtest.json');
|
||
|
$this->assertEquals($data, $a->get());
|
||
|
//yaml
|
||
|
$a = new Config();
|
||
|
$a->readFile(__DIR__.'/configtest.yaml');
|
||
|
$this->assertEquals($data, $a->get());
|
||
|
}
|
||
|
|
||
|
public function testSerializing()
|
||
|
{
|
||
|
$data = [
|
||
|
'a' => 'b',
|
||
|
'c' => [
|
||
|
'd' => 'e'
|
||
|
]
|
||
|
];
|
||
|
$c = new Config($data);
|
||
|
//json
|
||
|
$this->assertEquals($data, json_decode($c->json(), true));
|
||
|
//yaml
|
||
|
$this->assertEquals($data, Yaml::parse($c->yaml()));
|
||
|
}
|
||
|
}
|