aboutsummaryrefslogtreecommitdiff
path: root/tests/DotenvTest.php
blob: 757ce706d290c7d9083868bfc277e26708806ff3 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);

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

use NeonXP\Dotenv\Compiler\CompilerInterface;
use NeonXP\Dotenv\Dotenv;
use NeonXP\Dotenv\Exception\RuntimeException;
use NeonXP\Dotenv\Loader\LoaderInterface;
use NeonXP\Dotenv\Parser\ParserInterface;
use PHPUnit\Framework\TestCase;

/**
 * Class TestDotenv
 */
class DotenvTest extends TestCase
{
    /**
     * @var LoaderInterface
     */
    private $mockLoader;

    /**
     * @var ParserInterface
     */
    private $mockParser;

    /**
     * @var CompilerInterface
     */
    private $mockCompiler;

    public function setUp()
    {
        $this->mockLoader = new MockLoader();
        $this->mockParser = new MockParser();
        $this->mockCompiler = new MockCompiler();
    }

    public function testLoad()
    {
        $dotenv = new Dotenv($this->mockLoader, $this->mockParser, $this->mockCompiler);

        $this->expectException(RuntimeException::class);
        $dotenv->get('TEST1');

        $dotenv->load();

        $this->assertNull( $dotenv->get('NOT_EXISTS'));
        $this->assertEquals('default value', $dotenv->get('NOT_EXISTS', 'default value'));
        $this->assertEquals('VALUE3', $dotenv->get('KEY3', 'default value'));
        $this->assertEquals('VALUE3', $dotenv['KEY3']);
        $idx = 1;
        foreach ($dotenv as $key => $value) {
            $this->assertEquals("KEY{$idx}", $key);
            $this->assertEquals("VALUE{$idx}", $value);
            $idx++;
        }
    }
}