aboutsummaryrefslogtreecommitdiff
path: root/tests/ParserTest.php
blob: c67056b0d0c5fbd1c45910a2c31a6e94ec52f10f (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
<?php
declare(strict_types=1);

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

use NeonXP\Dotenv\Parser\Parser;
use PHPUnit\Framework\TestCase;

/**
 * Class ParserTest
 */
class ParserTest extends TestCase
{
    public function testParseLines()
    {
        $tests = [
            "key1='value1' # comment" => ['key1', 'value1'],
            "key2 = 'value2'" => ['key2', 'value2'],
            "key3 = \"value3\" # comment" => ['key3', 'value3'],
            "key4 =\"value4\"" => ['key4', 'value4'],
            "key5 ='value5 # not comment'" => ['key5', 'value5 # not comment'],
            "key6 = \"value6 # not comment\"" => ['key6', 'value6 # not comment'],
            "boolean=true" => ['boolean', true],
            "numeric = 123" => ['numeric', 123]
        ];

        $parser = new Parser();

        foreach ($tests as $test => $expected) {
            $result = $parser->parseLine($test);
            $this->assertEquals($expected[0], $result['key']);
            $this->assertEquals($expected[1], $result['value']);
        }
    }
}