Passed
Push — feature/config-shorthands ( 92b3e0...78871d )
by Sebastian
04:50
created

UtilTest::testCanReadEnvVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 1
b 0
f 0
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;
13
14
use PHPUnit\Framework\TestCase;
15
16
class UtilTest extends TestCase
17
{
18
    public function testGetTypePHP(): void
19
    {
20
        $this->assertEquals('php', Util::getExecType('\\Foo\\Bar'));
21
        $this->assertEquals('php', Util::getExecType('\\Foo\\Bar::baz'));
22
        $this->assertEquals('php', Util::getExecType('\\Fiz'));
23
    }
24
25
    public function testGetTypeCli(): void
26
    {
27
        $this->assertEquals('cli', Util::getExecType('./my-binary'));
28
        $this->assertEquals('cli', Util::getExecType('phpunit'));
29
        $this->assertEquals('cli', Util::getExecType('~/composer install'));
30
        $this->assertEquals('cli', Util::getExecType('echo foo'));
31
        $this->assertEquals('cli', Util::getExecType('/usr/local/bin/phpunit.phar'));
32
    }
33
34
    public function testIsTypeValid(): void
35
    {
36
        $this->assertTrue(Util::isTypeValid('php'));
37
        $this->assertTrue(Util::isTypeValid('cli'));
38
        $this->assertFalse(Util::isTypeValid('foo'));
39
    }
40
41
    public function testCanReadEnvVar(): void
42
    {
43
        $_ENV['foo'] = 'bar';
44
        $this->assertEquals('bar', Util::getEnv('foo'));
45
        unset($_ENV['foo']);
46
    }
47
48
    public function testUsesServerSuperglobalAsFallback(): void
49
    {
50
        $_SERVER['foo'] = 'bar';
51
        $this->assertEquals('bar', Util::getEnv('foo'));
52
        unset($_SERVER['foo']);
53
    }
54
55
    public function testReturnsDefaultIdEnvNotSet(): void
56
    {
57
        $this->assertEquals('baz', Util::getEnv('fiz', 'baz'));
58
    }
59
}
60