Passed
Push — main ( bf7881...b4ce3e )
by Sebastian
14:45
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
    /**
19
     * Tests Util::getExecType
20
     */
21
    public function testGetTypePHP(): void
22
    {
23
        $this->assertEquals('php', Util::getExecType('\\Foo\\Bar'));
24
        $this->assertEquals('php', Util::getExecType('\\Foo\\Bar::baz'));
25
        $this->assertEquals('php', Util::getExecType('\\Fiz'));
26
    }
27
28
    /**
29
     * Tests Util::getExecType
30
     */
31
    public function testGetTypeCli(): void
32
    {
33
        $this->assertEquals('cli', Util::getExecType('./my-binary'));
34
        $this->assertEquals('cli', Util::getExecType('phpunit'));
35
        $this->assertEquals('cli', Util::getExecType('~/composer install'));
36
        $this->assertEquals('cli', Util::getExecType('echo foo'));
37
        $this->assertEquals('cli', Util::getExecType('/usr/local/bin/phpunit.phar'));
38
    }
39
40
    /**
41
     * Tests Util::isTypeValid
42
     */
43
    public function testIsTypeValid(): void
44
    {
45
        $this->assertTrue(Util::isTypeValid('php'));
46
        $this->assertTrue(Util::isTypeValid('cli'));
47
        $this->assertFalse(Util::isTypeValid('foo'));
48
    }
49
50
    /**
51
     * Tests Util::getEnv
52
     */
53
    public function testCanReadEnvVar(): void
54
    {
55
        $_ENV['foo'] = 'bar';
56
        $this->assertEquals('bar', Util::getEnv('foo'));
57
        unset($_ENV['foo']);
58
    }
59
60
    /**
61
     * Tests Util::getEnv
62
     */
63
    public function testUsesServerSuperglobalAsFallback(): void
64
    {
65
        $_SERVER['foo'] = 'bar';
66
        $this->assertEquals('bar', Util::getEnv('foo'));
67
        unset($_SERVER['foo']);
68
    }
69
70
    /**
71
     * Tests Util::getEnv
72
     */
73
    public function testReturnsDefaultIdEnvNotSet(): void
74
    {
75
        $this->assertEquals('baz', Util::getEnv('fiz', 'baz'));
76
    }
77
}
78