aboutsummaryrefslogtreecommitdiff
path: root/tests/CompilerTest.php
blob: 9a820ecb552902cbc3505f6bf1d659c42209c569 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);

/**
 * @author: Alexander Kiryukhin <alexander@kiryukhin.su>
 * @license: MIT
 */

use NeonXP\Dotenv\Types\KeyValue;
use PHPUnit\Framework\TestCase;

/**
 * Class CompilerTest
 */
class CompilerTest extends TestCase
{
    public function testParseLines()
    {
        $collection = [
            'KEY1' => 'VALUE1',
            'KEY2' => '${KEY1} ${KEY3}',
            'KEY3' => 'VALUE3',
            'KEY4' => 'Test ${KEY2} => ${KEY3}'
        ];
        $tests = [
            'KEY1' => 'VALUE1',
            'KEY2' => 'VALUE1 VALUE3',
            'KEY3' => 'VALUE3',
            'KEY4' => 'Test VALUE1 VALUE3 => VALUE3',
        ];
        $compiler = new \NeonXP\Dotenv\Compiler\Compiler();
        $collectionOfKeyValues = [];
        foreach ($collection as $key => $value) {
            $collectionOfKeyValues[] = new KeyValue($key, $value);
        }
        $compiler->setRawCollection($collectionOfKeyValues);

        foreach ($tests as $key => $expected) {
            $result = $compiler->compileKeyValue(new KeyValue($key, $collection[$key]));
            $this->assertEquals($key, $result->getKey());
            $this->assertEquals($expected, $result->getValue());
        }
    }
}