EnvTest::testEnvValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Action\Cli\Command\Placeholder;
13
14
use CaptainHook\App\Console\IO\Mockery as IOMockery;
15
use CaptainHook\App\Config\Mockery as ConfigMockery;
16
use CaptainHook\App\Mockery as AppMockery;
17
use PHPUnit\Framework\TestCase;
18
19
class EnvTest extends TestCase
20
{
21
    use IOMockery;
22
    use AppMockery;
23
    use ConfigMockery;
24
25
    public function testEnvValue(): void
26
    {
27
        $_ENV['foo'] = 'bar';
28
29
        $io     = $this->createIOMock();
30
        $repo   = $this->createRepositoryMock();
31
        $config = $this->createConfigMock();
32
33
        $placeholder = new Env($io, $config, $repo);
34
        $result      = $placeholder->replacement(['value-of' => 'foo']);
35
36
        $this->assertEquals('bar', $result);
37
38
        unset($_ENV['foo']);
39
    }
40
41
    public function testNoValueOf(): void
42
    {
43
        $io     = $this->createIOMock();
44
        $repo   = $this->createRepositoryMock();
45
        $config = $this->createConfigMock();
46
47
        $placeholder = new Env($io, $config, $repo);
48
        $result      = $placeholder->replacement([]);
49
50
        $this->assertEquals('', $result);
51
    }
52
53
    public function testDefault(): void
54
    {
55
        $io     = $this->createIOMock();
56
        $repo   = $this->createRepositoryMock();
57
        $config = $this->createConfigMock();
58
59
        $placeholder = new Env($io, $config, $repo);
60
        $result      = $placeholder->replacement(['value-of' => 'MY_SUPER_ENV_VAR', 'default' => 'my-default']);
61
62
        $this->assertEquals('my-default', $result);
63
    }
64
}
65