|
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
|
|
|
|